Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Add more unit tests
support550fecf1f072
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Extensions/TierPriceExtensionsTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Extensions/TierPriceExtensionsTests.csdeleted file mode 100644index 77466d640..000000000--- a/src/Tests/Grand.Business.Catalog.Tests/Extensions/TierPriceExtensionsTests.cs+++ /dev/null@@ -1,63 +0,0 @@-using Grand.Domain.Catalog;-using Microsoft.VisualStudio.TestTools.UnitTesting;--namespace Grand.Business.Catalog.Tests.Extensions-{-- [TestClass()]- public class TierPriceExtensionsTests- {- [TestMethod()]- public void Can_remove_duplicatedQuantities()- {-- var tierPrices = new List<TierPrice>();- tierPrices.Add(new TierPrice {- //will be removed- Id = "1",- Price = 150,- Quantity = 1- });- tierPrices.Add(new TierPrice {- //will stay- Id = "2",- Price = 100,- Quantity = 1- });- tierPrices.Add(new TierPrice {- //will stay- Id = "3",- Price = 200,- Quantity = 3- });- tierPrices.Add(new TierPrice {- //will stay- Id = "4",- Price = 250,- Quantity = 4- });- tierPrices.Add(new TierPrice {- //will be removed- Id = "5",- Price = 300,- Quantity = 4- });- tierPrices.Add(new TierPrice {- //will stay- Id = "6",- Price = 350,- Quantity = 5- });-- var tierPriceCollection = tierPrices.RemoveDuplicatedQuantities();-- Assert.IsNull(tierPriceCollection.FirstOrDefault(v => v.Id == "1"));- Assert.IsNotNull(tierPriceCollection.FirstOrDefault(v => v.Id == "2")); //doubled 15 - saved- Assert.IsNotNull(tierPriceCollection.FirstOrDefault(v => v.Id == "3")); //! doubled 15 - removed- Assert.IsNotNull(tierPriceCollection.FirstOrDefault(v => v.Id == "4")); //doubled 23 - saved- Assert.IsNull(tierPriceCollection.FirstOrDefault(v => v.Id == "5"));- Assert.IsNotNull(tierPriceCollection.FirstOrDefault(v => v.Id == "6")); //! doubled 23 - removed-- }- }-}diff --git a/src/Tests/Grand.Business.Checkout.Tests/Extensions/CheckoutAttributeExtensionsTests.cs b/src/Tests/Grand.Business.Checkout.Tests/Extensions/CheckoutAttributeExtensionsTests.csdeleted file mode 100644index ab4ae20bf..000000000--- a/src/Tests/Grand.Business.Checkout.Tests/Extensions/CheckoutAttributeExtensionsTests.cs+++ /dev/null@@ -1,44 +0,0 @@-using Grand.Domain.Catalog;-using Grand.Domain.Orders;-using Microsoft.VisualStudio.TestTools.UnitTesting;--namespace Grand.Business.Checkout.Tests.Extensions-{- [TestClass]- public class CheckoutAttributeExtensionsTests- {- [TestMethod()]- public void CanRemoveShippableAttributes()- {- List<CheckoutAttribute> attributes = new List<CheckoutAttribute>();- attributes.Add(new CheckoutAttribute { Id = "1", Name = "Attribute001", ShippableProductRequired = false });- attributes.Add(new CheckoutAttribute { Id = "2", Name = "Attribute002", ShippableProductRequired = true });- attributes.Add(new CheckoutAttribute { Id = "3", Name = "Attribute003", ShippableProductRequired = false });- attributes.Add(new CheckoutAttribute { Id = "4", Name = "Attribute004", ShippableProductRequired = true });-- //removes these with "ShippableProductRequired = true"- IList<CheckoutAttribute> afterRemoval = attributes.RemoveShippableAttributes();- Assert.AreEqual(2, afterRemoval.Count());- Assert.AreEqual("Attribute001", afterRemoval[0].Name);- Assert.AreEqual("3", afterRemoval[1].Id);- }-- [TestMethod]- public void ShouldHaveValues_ReturnExpectedResults()- {- List<CheckoutAttribute> attributes = new List<CheckoutAttribute>();- var atr1 = new CheckoutAttribute { Id = "1", Name = "Attribute001", AttributeControlTypeId = AttributeControlType.Checkboxes };- var atr2 = new CheckoutAttribute { Id = "2", Name = "Attribute002", AttributeControlTypeId = AttributeControlType.TextBox };- var atr3 = new CheckoutAttribute { Id = "3", Name = "Attribute003", AttributeControlTypeId = AttributeControlType.Datepicker };- var atr4 = new CheckoutAttribute { Id = "4", Name = "Attribute004", AttributeControlTypeId = AttributeControlType.FileUpload };- var atr5 = new CheckoutAttribute { Id = "5", Name = "Attribute005", AttributeControlTypeId = AttributeControlType.DropdownList };- CheckoutAttribute atr6 = null;- Assert.IsTrue(atr1.ShouldHaveValues());- Assert.IsTrue(atr5.ShouldHaveValues());- Assert.IsFalse(atr2.ShouldHaveValues());- Assert.IsFalse(atr3.ShouldHaveValues());- Assert.IsFalse(atr4.ShouldHaveValues());- Assert.IsFalse(atr6.ShouldHaveValues());- }- }-}diff --git a/src/Tests/Grand.Domain.Tests/App_Data/index.txt b/src/Tests/Grand.Domain.Tests/App_Data/index.txtnew file mode 100644index 000000000..5f282702b--- /dev/null+++ b/src/Tests/Grand.Domain.Tests/App_Data/index.txt@@ -0,0 +1 @@+\ No newline at end of filediff --git a/src/Tests/Grand.Domain.Tests/Catalog/TierPriceExtensionsTests.cs b/src/Tests/Grand.Domain.Tests/Catalog/TierPriceExtensionsTests.csnew file mode 100644index 000000000..a64910c1c--- /dev/null+++ b/src/Tests/Grand.Domain.Tests/Catalog/TierPriceExtensionsTests.cs@@ -0,0 +1,131 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Grand.Domain.Catalog;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;++namespace Grand.Domain.Catalog.Tests+{+ [TestClass()]+ public class TierPriceExtensionsTests+ {+ private IList<TierPrice> _tierPrices;++ public TierPriceExtensionsTests()+ {+ _tierPrices = new List<TierPrice>();+ _tierPrices.Add(new TierPrice() {+ CurrencyCode = "USD",+ CustomerGroupId = null,+ Price = 10,+ Quantity = 1,+ StoreId = "1",+ });+ _tierPrices.Add(new TierPrice() {+ CurrencyCode = "USD",+ CustomerGroupId = "1",+ Price = 12,+ Quantity = 1,+ StoreId = "1",+ });+ _tierPrices.Add(new TierPrice() {+ CurrencyCode = "USD",+ CustomerGroupId = "2",+ Price = 10,+ Quantity = 1,+ StoreId = "2",+ EndDateTimeUtc = DateTime.UtcNow.AddDays(1),+ });+ _tierPrices.Add(new TierPrice() {+ CurrencyCode = "EUR",+ CustomerGroupId = "3",+ Price = 10,+ Quantity = 1,+ StoreId = "3",+ StartDateTimeUtc = DateTime.UtcNow,+ });++ }++ [TestMethod()]+ public void FilterByDateTest()+ {+ Assert.AreEqual(3, _tierPrices.FilterByDate(new DateTime(2010, 01, 01)).Count());++ }++ [TestMethod()]+ public void FilterByStoreTest()+ {+ Assert.AreEqual(2, _tierPrices.FilterByStore("1").Count());+ }++ [TestMethod()]+ public void FilterForCustomerTest()+ {+ var customer = new Customers.Customer();+ customer.Groups.Add("1");+ customer.Groups.Add("2");+ Assert.AreEqual(3, _tierPrices.FilterForCustomer(customer).Count());+ }++ [TestMethod()]+ public void FilterByCurrencyTest()+ {+ Assert.AreEqual(3, _tierPrices.FilterByCurrency("USD").Count());+ }++ [TestMethod()]+ public void RemoveDuplicatedQuantitiesTest()+ {+ var tierPrices = new List<TierPrice>();+ tierPrices.Add(new TierPrice {+ //will be removed+ Id = "1",+ Price = 150,+ Quantity = 1+ });+ tierPrices.Add(new TierPrice {+ //will stay+ Id = "2",+ Price = 100,+ Quantity = 1+ });+ tierPrices.Add(new TierPrice {+ //will stay+ Id = "3",+ Price = 200,+ Quantity = 3+ });+ tierPrices.Add(new TierPrice {+ //will stay+ Id = "4",+ Price = 250,+ Quantity = 4+ });+ tierPrices.Add(new TierPrice {+ //will be removed+ Id = "5",+ Price = 300,+ Quantity = 4+ });+ tierPrices.Add(new TierPrice {+ //will stay+ Id = "6",+ Price = 350,+ Quantity = 5+ });++ var tierPriceCollection = tierPrices.RemoveDuplicatedQuantities();++ Assert.IsNull(tierPriceCollection.FirstOrDefault(v => v.Id == "1"));+ Assert.IsNotNull(tierPriceCollection.FirstOrDefault(v => v.Id == "2")); //doubled 15 - saved+ Assert.IsNotNull(tierPriceCollection.FirstOrDefault(v => v.Id == "3")); //! doubled 15 - removed+ Assert.IsNotNull(tierPriceCollection.FirstOrDefault(v => v.Id == "4")); //doubled 23 - saved+ Assert.IsNull(tierPriceCollection.FirstOrDefault(v => v.Id == "5"));+ Assert.IsNotNull(tierPriceCollection.FirstOrDefault(v => v.Id == "6")); //! doubled 23 - removed }+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Common.Tests/Extensions/AddressAttributeExtensionsTests.cs b/src/Tests/Grand.Domain.Tests/Common/AddressAttributeExtensionsTests.cssimilarity index 96%rename from src/Tests/Grand.Business.Common.Tests/Extensions/AddressAttributeExtensionsTests.csrename to src/Tests/Grand.Domain.Tests/Common/AddressAttributeExtensionsTests.csindex 14144760b..e6d8dbf60 100644--- a/src/Tests/Grand.Business.Common.Tests/Extensions/AddressAttributeExtensionsTests.cs+++ b/src/Tests/Grand.Domain.Tests/Common/AddressAttributeExtensionsTests.cs@@ -1,8 +1,7 @@using Grand.Domain.Catalog;-using Grand.Domain.Common;using Microsoft.VisualStudio.TestTools.UnitTesting;-namespace Grand.Business.Common.Tests.Extensions+namespace Grand.Domain.Common.Tests{[TestClass()]public class AddressAttributeExtensionsTests@@ -41,4 +40,4 @@ namespace Grand.Business.Common.Tests.ExtensionsAssert.IsTrue(addressAttribute4.ShouldHaveValues());}}-}+}\ No newline at end of filediff --git a/src/Tests/Grand.Domain.Tests/Common/AddressExtensionsTests.cs b/src/Tests/Grand.Domain.Tests/Common/AddressExtensionsTests.csnew file mode 100644index 000000000..58b1ca033--- /dev/null+++ b/src/Tests/Grand.Domain.Tests/Common/AddressExtensionsTests.cs@@ -0,0 +1,41 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Grand.Domain.Common;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;++namespace Grand.Domain.Common.Tests+{+ [TestClass()]+ public class AddressExtensionsTests+ {+ [TestMethod()]+ public void FindAddressTest_NotNull()+ {+ var addresses = new List<Address>() {+ new Address(){ Address1 = "address1", Address2 = "address11", FirstName = "name1", LastName = "namelast1" },+ new Address(){ Address1 = "address2", Address2 = "address12", FirstName = "name2", LastName = "namelast2" },+ new Address(){ Address1 = "address3", Address2 = "address13", FirstName = "name3", LastName = "namelast3" },+ new Address(){ Address1 = "address4", Address2 = "address14", FirstName = "name4", LastName = "namelast4" },+ };+ var address = addresses.FindAddress("name1", "namelast1", string.Empty, string.Empty, string.Empty,+ string.Empty, "address1", "address11", string.Empty, string.Empty, string.Empty, string.Empty);+ Assert.IsNotNull(address);+ }+ [TestMethod()]+ public void FindAddressTest_IsNull()+ {+ var addresses = new List<Address>() {+ new Address(){ Address1 = "address1", Address2 = "address11", FirstName = "name1", LastName = "namelast1" },+ new Address(){ Address1 = "address2", Address2 = "address12", FirstName = "name2", LastName = "namelast2" },+ new Address(){ Address1 = "address3", Address2 = "address13", FirstName = "name3", LastName = "namelast3" },+ new Address(){ Address1 = "address4", Address2 = "address14", FirstName = "name4", LastName = "namelast4" },+ };+ var address = addresses.FindAddress("name1", "namelast1", string.Empty, string.Empty, string.Empty,+ string.Empty, "address1", "address2", "city", string.Empty, string.Empty, string.Empty);+ Assert.IsNull(address);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Domain.Tests/Common/UserFieldExtensionsTests.cs b/src/Tests/Grand.Domain.Tests/Common/UserFieldExtensionsTests.csnew file mode 100644index 000000000..7a84bdf69--- /dev/null+++ b/src/Tests/Grand.Domain.Tests/Common/UserFieldExtensionsTests.cs@@ -0,0 +1,45 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Domain.Common.Tests+{+ [TestClass()]+ public class UserFieldExtensionsTests+ {+ private Customers.Customer entity;++ public UserFieldExtensionsTests()+ {+ entity = new Customers.Customer();+ entity.UserFields.Add(new UserField() { Key = "FirstName", Value = "Sara", StoreId = "" });+ entity.UserFields.Add(new UserField() { Key = "LastName", Value = "Name", StoreId = "" });+ entity.UserFields.Add(new UserField() { Key = "Registered", Value = "1", StoreId = "1" });+ }++ [TestMethod()]+ public void GetUserFieldFromEntityTest_FirstName_NotNull()+ {+ var userField = entity.GetUserFieldFromEntity<string>("FirstName");+ Assert.IsNotNull(userField);+ Assert.AreEqual(userField, "Sara");+ }+ [TestMethod()]+ public void GetUserFieldFromEntityTest_City_IsNull()+ {+ var userField = entity.GetUserFieldFromEntity<string>("City");+ Assert.IsNull(userField);+ }+ [TestMethod()]+ public void GetUserFieldFromEntityTest_Registered_Store_NotNull()+ {+ var userField = entity.GetUserFieldFromEntity<string>("Registered", "1");+ Assert.IsNotNull(userField);+ Assert.AreEqual(userField, "1");+ }+ [TestMethod()]+ public void GetUserFieldFromEntityTest_Registered_Store_Null()+ {+ var userField = entity.GetUserFieldFromEntity<string>("Registered", "2");+ Assert.IsNull(userField);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Domain.Tests/Customers/CustomerAttributeExtensionsTests.cs b/src/Tests/Grand.Domain.Tests/Customers/CustomerAttributeExtensionsTests.csnew file mode 100644index 000000000..e69208bf3--- /dev/null+++ b/src/Tests/Grand.Domain.Tests/Customers/CustomerAttributeExtensionsTests.cs@@ -0,0 +1,43 @@+using Grand.Domain.Catalog;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Domain.Customers.Tests+{+ [TestClass()]+ public class CustomerAttributeExtensionsTests+ {+ [TestMethod()]+ public void ShouldHaveValues_NullCustomerAttribute_ReturnFalse()+ {+ CustomerAttribute customerAttribute = null;+ Assert.IsFalse(customerAttribute.ShouldHaveValues());+ }++ [TestMethod()]+ public void ShouldHaveValues__ReturnFalse()+ {+ var customerAttribute1 = new CustomerAttribute() { AttributeControlTypeId = AttributeControlType.TextBox };+ var customerAttribute2 = new CustomerAttribute() { AttributeControlTypeId = AttributeControlType.MultilineTextbox };+ var customerAttribute3 = new CustomerAttribute() { AttributeControlTypeId = AttributeControlType.Datepicker };+ var customerAttribute4 = new CustomerAttribute() { AttributeControlTypeId = AttributeControlType.FileUpload };+ Assert.IsFalse(customerAttribute1.ShouldHaveValues());+ Assert.IsFalse(customerAttribute2.ShouldHaveValues());+ Assert.IsFalse(customerAttribute3.ShouldHaveValues());+ Assert.IsFalse(customerAttribute4.ShouldHaveValues());+ }+++ [TestMethod()]+ public void ShouldHaveValues__ReturnTrue()+ {+ var addressAttribute1 = new CustomerAttribute() { AttributeControlTypeId = AttributeControlType.DropdownList };+ var addressAttribute2 = new CustomerAttribute() { AttributeControlTypeId = AttributeControlType.ImageSquares };+ var addressAttribute3 = new CustomerAttribute() { AttributeControlTypeId = AttributeControlType.RadioList };+ var addressAttribute4 = new CustomerAttribute() { AttributeControlTypeId = AttributeControlType.ReadonlyCheckboxes };+ Assert.IsTrue(addressAttribute1.ShouldHaveValues());+ Assert.IsTrue(addressAttribute2.ShouldHaveValues());+ Assert.IsTrue(addressAttribute3.ShouldHaveValues());+ Assert.IsTrue(addressAttribute4.ShouldHaveValues());+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Domain.Tests/Data/DataSettingsManagerTests.cs b/src/Tests/Grand.Domain.Tests/Data/DataSettingsManagerTests.csnew file mode 100644index 000000000..f05ae057f--- /dev/null+++ b/src/Tests/Grand.Domain.Tests/Data/DataSettingsManagerTests.cs@@ -0,0 +1,42 @@+using Grand.SharedKernel.Extensions;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Domain.Data.Tests+{+ [TestClass()]+ public class DataSettingsManagerTests+ {+ public DataSettingsManagerTests()+ {+ CommonPath.BaseDirectory = NUnit.Framework.TestContext.CurrentContext.TestDirectory;+ }++ [TestInitialize]+ public void Setup()+ {+ DataSettingsManager.LoadDataSettings(null);++ if (File.Exists(CommonPath.SettingsPath))+ File.Delete(CommonPath.SettingsPath);+ }++ [TestMethod()]+ public async Task SaveSettings_LoadSettings_Test()+ {+ await DataSettingsManager.SaveSettings(new DataSettings() { ConnectionString = "connectionstring", DbProvider = DbProvider.MongoDB });+ var settings = DataSettingsManager.LoadSettings();+ Assert.IsNotNull(settings);+ Assert.IsTrue(DataSettingsManager.DatabaseIsInstalled());+ Assert.AreEqual("connectionstring", settings.ConnectionString);+ }+++ [TestMethod()]+ public async Task DatabaseIsInstalledTest_True()+ {+ await DataSettingsManager.SaveSettings(new DataSettings() { ConnectionString = "connectionstring", DbProvider = DbProvider.MongoDB });+ Assert.IsTrue(DataSettingsManager.DatabaseIsInstalled());+ }++ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Domain.Tests/Grand.Domain.Tests.csproj b/src/Tests/Grand.Domain.Tests/Grand.Domain.Tests.csprojindex 816de8f09..e35f2be7a 100644--- a/src/Tests/Grand.Domain.Tests/Grand.Domain.Tests.csproj+++ b/src/Tests/Grand.Domain.Tests/Grand.Domain.Tests.csproj@@ -21,4 +21,10 @@<ProjectReference Include="..\..\Core\Grand.SharedKernel\Grand.SharedKernel.csproj" /></ItemGroup>+ <ItemGroup>+ <None Update="App_Data\index.txt">+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>+ </None>+ </ItemGroup>+</Project>diff --git a/src/Tests/Grand.Domain.Tests/Messages/ContactAttributeExtensionsTests.cs b/src/Tests/Grand.Domain.Tests/Messages/ContactAttributeExtensionsTests.csnew file mode 100644index 000000000..3925f0dac--- /dev/null+++ b/src/Tests/Grand.Domain.Tests/Messages/ContactAttributeExtensionsTests.cs@@ -0,0 +1,69 @@+using Grand.Domain.Catalog;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Domain.Messages.Tests+{+ [TestClass()]+ public class ContactAttributeExtensionsTests+ {+ [TestMethod()]+ public void ShouldHaveValues_NullContactAttribute_ReturnFalse()+ {+ ContactAttribute contactAttribute = null;+ Assert.IsFalse(contactAttribute.ShouldHaveValues());+ }++ [TestMethod()]+ public void ShouldHaveValues__ReturnFalse()+ {+ var contactAttribute1 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.TextBox };+ var contactAttribute2 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.MultilineTextbox };+ var contactAttribute3 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.Datepicker };+ var contactAttribute4 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.FileUpload };+ Assert.IsFalse(contactAttribute1.ShouldHaveValues());+ Assert.IsFalse(contactAttribute2.ShouldHaveValues());+ Assert.IsFalse(contactAttribute3.ShouldHaveValues());+ Assert.IsFalse(contactAttribute4.ShouldHaveValues());+ }+++ [TestMethod()]+ public void ShouldHaveValues__ReturnTrue()+ {+ var contactAttribute1 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.DropdownList };+ var contactAttribute2 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.ImageSquares };+ var contactAttribute3 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.RadioList };+ var contactAttribute4 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.ReadonlyCheckboxes };+ Assert.IsTrue(contactAttribute1.ShouldHaveValues());+ Assert.IsTrue(contactAttribute2.ShouldHaveValues());+ Assert.IsTrue(contactAttribute3.ShouldHaveValues());+ Assert.IsTrue(contactAttribute4.ShouldHaveValues());+ }++ [TestMethod()]+ public void CanBeUsedAsConditionTest__ReturnFalse()+ {+ var contactAttribute1 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.TextBox };+ var contactAttribute2 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.MultilineTextbox };+ var contactAttribute3 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.Datepicker };+ var contactAttribute4 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.FileUpload };+ Assert.IsFalse(contactAttribute1.CanBeUsedAsCondition());+ Assert.IsFalse(contactAttribute2.CanBeUsedAsCondition());+ Assert.IsFalse(contactAttribute3.CanBeUsedAsCondition());+ Assert.IsFalse(contactAttribute4.CanBeUsedAsCondition());+ }++ [TestMethod()]+ public void CanBeUsedAsConditionTest__ReturnTruee()+ {+ var contactAttribute1 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.DropdownList };+ var contactAttribute2 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.Checkboxes };+ var contactAttribute3 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.RadioList };+ var contactAttribute4 = new ContactAttribute() { AttributeControlTypeId = (int)AttributeControlType.ColorSquares };+ Assert.IsTrue(contactAttribute1.CanBeUsedAsCondition());+ Assert.IsTrue(contactAttribute2.CanBeUsedAsCondition());+ Assert.IsTrue(contactAttribute3.CanBeUsedAsCondition());+ Assert.IsTrue(contactAttribute4.CanBeUsedAsCondition());+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Domain.Tests/Orders/CheckoutAttributeExtensionsTests.cs b/src/Tests/Grand.Domain.Tests/Orders/CheckoutAttributeExtensionsTests.csnew file mode 100644index 000000000..6f78e257f--- /dev/null+++ b/src/Tests/Grand.Domain.Tests/Orders/CheckoutAttributeExtensionsTests.cs@@ -0,0 +1,70 @@+using Grand.Domain.Catalog;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Domain.Orders.Tests+{+ [TestClass()]+ public class CheckoutAttributeExtensionsTests+ {+ [TestMethod()]+ public void ShouldHaveValues_NullCheckoutAttribute_ReturnFalse()+ {+ CheckoutAttribute checkoutAttribute = null;+ Assert.IsFalse(checkoutAttribute.ShouldHaveValues());+ }++ [TestMethod()]+ public void ShouldHaveValues__ReturnFalse()+ {+ var checkoutAttribute1 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.TextBox };+ var checkoutAttribute2 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.MultilineTextbox };+ var checkoutAttribute3 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.Datepicker };+ var checkoutAttribute4 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.FileUpload };+ Assert.IsFalse(checkoutAttribute1.ShouldHaveValues());+ Assert.IsFalse(checkoutAttribute2.ShouldHaveValues());+ Assert.IsFalse(checkoutAttribute3.ShouldHaveValues());+ Assert.IsFalse(checkoutAttribute4.ShouldHaveValues());+ }+++ [TestMethod()]+ public void ShouldHaveValues__ReturnTrue()+ {+ var checkoutAttribute1 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.DropdownList };+ var checkoutAttribute2 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.ImageSquares };+ var checkoutAttribute3 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.RadioList };+ var checkoutAttribute4 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.ReadonlyCheckboxes };+ Assert.IsTrue(checkoutAttribute1.ShouldHaveValues());+ Assert.IsTrue(checkoutAttribute2.ShouldHaveValues());+ Assert.IsTrue(checkoutAttribute3.ShouldHaveValues());+ Assert.IsTrue(checkoutAttribute4.ShouldHaveValues());+ }++ [TestMethod()]+ public void CanBeUsedAsConditionTest__ReturnFalse()+ {+ var checkoutAttribute1 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.TextBox };+ var checkoutAttribute2 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.MultilineTextbox };+ var checkoutAttribute3 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.Datepicker };+ var checkoutAttribute4 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.FileUpload };+ Assert.IsFalse(checkoutAttribute1.CanBeUsedAsCondition());+ Assert.IsFalse(checkoutAttribute2.CanBeUsedAsCondition());+ Assert.IsFalse(checkoutAttribute3.CanBeUsedAsCondition());+ Assert.IsFalse(checkoutAttribute4.CanBeUsedAsCondition());+ }++ [TestMethod()]+ public void CanBeUsedAsConditionTest__ReturnTruee()+ {+ var checkoutAttribute1 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.DropdownList };+ var checkoutAttribute2 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.Checkboxes };+ var checkoutAttribute3 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.RadioList };+ var checkoutAttribute4 = new CheckoutAttribute() { AttributeControlTypeId = AttributeControlType.ColorSquares };+ Assert.IsTrue(checkoutAttribute1.CanBeUsedAsCondition());+ Assert.IsTrue(checkoutAttribute2.CanBeUsedAsCondition());+ Assert.IsTrue(checkoutAttribute3.CanBeUsedAsCondition());+ Assert.IsTrue(checkoutAttribute4.CanBeUsedAsCondition());+ }++ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Domain.Tests/Orders/GiftVoucherExtensionsTests.cs b/src/Tests/Grand.Domain.Tests/Orders/GiftVoucherExtensionsTests.csnew file mode 100644index 000000000..1713d18f9--- /dev/null+++ b/src/Tests/Grand.Domain.Tests/Orders/GiftVoucherExtensionsTests.cs@@ -0,0 +1,87 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Grand.Domain.Orders;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;+using Grand.Domain.Common;++namespace Grand.Domain.Orders.Tests+{+ [TestClass()]+ public class GiftVoucherExtensionsTests+ {+ private GiftVoucher giftVoucher;++ public GiftVoucherExtensionsTests()+ {+ giftVoucher = new GiftVoucher() {+ Amount = 10,+ Code = "123456",+ CurrencyCode = "USD",+ IsGiftVoucherActivated = true+ };+ }++ [TestMethod()]+ public void AddGiftVoucherAttributeTest()+ {+ IList<CustomAttribute> customAttributes = new List<CustomAttribute>();+ GiftVoucherExtensions.AddGiftVoucherAttribute(customAttributes, "Johny", "[email protected]", "My name", "[email protected]", "my sample message");++ GiftVoucherExtensions.GetGiftVoucherAttribute(customAttributes, out var giftVoucherRecipientName, out var giftVoucherRecipientEmail,+ out var giftVoucherSenderName, out var giftVoucherSenderEmail, out var giftVoucherMessage);++ Assert.IsTrue(giftVoucherRecipientName == "Johny");+ Assert.IsTrue(giftVoucherRecipientEmail == "[email protected]");+ Assert.IsTrue(giftVoucherSenderName == "My name");+ Assert.IsTrue(giftVoucherSenderEmail == "[email protected]");+ Assert.IsTrue(giftVoucherMessage == "my sample message");++ }++ [TestMethod()]+ public void GetGiftVoucherAttributeTest()+ {+ IList<CustomAttribute> customAttributes = new List<CustomAttribute>();+ customAttributes.Add(new CustomAttribute() { Key = "RecipientName", Value = "Johny" });+ customAttributes.Add(new CustomAttribute() { Key = "RecipientEmail", Value = "[email protected]" });+ customAttributes.Add(new CustomAttribute() { Key = "SenderName", Value = "My name" });+ customAttributes.Add(new CustomAttribute() { Key = "SenderEmail", Value = "[email protected]" });+ customAttributes.Add(new CustomAttribute() { Key = "Message", Value = "my sample message" });+ customAttributes.Add(new CustomAttribute() { Key = "Test", Value = "my test" });++ GiftVoucherExtensions.GetGiftVoucherAttribute(customAttributes, out var giftVoucherRecipientName, out var giftVoucherRecipientEmail,+ out var giftVoucherSenderName, out var giftVoucherSenderEmail, out var giftVoucherMessage);++ Assert.IsTrue(giftVoucherRecipientName == "Johny");+ Assert.IsTrue(giftVoucherRecipientEmail == "[email protected]");+ Assert.IsTrue(giftVoucherSenderName == "My name");+ Assert.IsTrue(giftVoucherSenderEmail == "[email protected]");+ Assert.IsTrue(giftVoucherMessage == "my sample message");+ }++ [TestMethod()]+ public void GetGiftVoucherRemainingAmountTest()+ {+ giftVoucher.GiftVoucherUsageHistory.Add(new GiftVoucherUsageHistory() { UsedValue = 3 });+ giftVoucher.GiftVoucherUsageHistory.Add(new GiftVoucherUsageHistory() { UsedValue = 4 });+ Assert.IsTrue(giftVoucher.GetGiftVoucherRemainingAmount() == 3);+ }++ [TestMethod()]+ public void IsGiftVoucherValidTest_ValidTo_True()+ {+ giftVoucher.ValidTo = DateTime.UtcNow.AddDays(1);+ Assert.IsTrue(giftVoucher.IsGiftVoucherValid(new Directory.Currency() { CurrencyCode = "USD" }, new Stores.Store()));+ }++ [TestMethod()]+ public void IsGiftVoucherValidTest_False()+ {+ giftVoucher.ValidTo = DateTime.UtcNow.AddDays(-1);+ Assert.IsFalse(giftVoucher.IsGiftVoucherValid(new Directory.Currency() { CurrencyCode = "USD" }, new Stores.Store()));+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Domain.Tests/Stores/StoreExtensionsTests.cs b/src/Tests/Grand.Domain.Tests/Stores/StoreExtensionsTests.csnew file mode 100644index 000000000..7bcade642--- /dev/null+++ b/src/Tests/Grand.Domain.Tests/Stores/StoreExtensionsTests.cs@@ -0,0 +1,43 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Domain.Stores.Tests+{+ [TestClass()]+ public class StoreExtensionsTests+ {+ private Store store;++ [TestInitialize]+ public void Setup()+ {+ store = new();+ store.Domains.Add(new DomainHost() { HostName = "google.com", Url = "https:\\google.com" });+ store.Domains.Add(new DomainHost() { HostName = "yahoo.com", Url = "https:\\yahoo.com" });+ }++ [TestMethod()]+ public void ContainsHostValueTest_True()+ {+ Assert.IsTrue(store.ContainsHostValue("Google.com"));+ }++ [TestMethod()]+ public void ContainsHostValueTest_False()+ {+ Assert.IsFalse(store.ContainsHostValue("google"));+ }++ [TestMethod()]+ public void HostValueTest_NotNull()+ {+ Assert.IsNotNull(store.HostValue("yAhoO.com"));+ }++ [TestMethod()]+ public void HostValueTest_Null()+ {+ Assert.IsNull(store.HostValue("yahoo"));+ }++ }+}\ No newline at end of file