Skip to content

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.

Add tests

supportcadf2bede585
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Brands/BrandLayoutServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Brands/BrandLayoutServiceTests.cs
new file mode 100644
index 000000000..ff9d06e0d
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Brands/BrandLayoutServiceTests.cs
@@ -0,0 +1,111 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Data;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Catalog.Services.Brands.Tests
+{
+ [TestClass()]
+ public class BrandLayoutServiceTests
+ {
+ private IRepository<BrandLayout> _repository;
+ private MemoryCacheBase _cacheBase;
+ private Mock<IMediator> _mediatorMock;
+ private BrandLayoutService _brandLayoutService;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<BrandLayout>();
+ _mediatorMock = new Mock<IMediator>();
+
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+ _brandLayoutService = new BrandLayoutService(_repository, _cacheBase, _mediatorMock.Object);
+ }
+
+
+ [TestMethod()]
+ public async Task GetAllBrandLayoutsTest()
+ {
+ //Arrange
+ await _brandLayoutService.InsertBrandLayout(new BrandLayout());
+ await _brandLayoutService.InsertBrandLayout(new BrandLayout());
+ await _brandLayoutService.InsertBrandLayout(new BrandLayout());
+
+ //Act
+ var layouts = await _brandLayoutService.GetAllBrandLayouts();
+
+ //Assert
+ Assert.AreEqual(3, layouts.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetBrandLayoutByIdTest()
+ {
+ //Arrange
+ var brandLayout = new BrandLayout() {
+ Name = "test"
+ };
+ await _brandLayoutService.InsertBrandLayout(brandLayout);
+
+ //Act
+ var layout = await _brandLayoutService.GetBrandLayoutById(brandLayout.Id);
+
+ //Assert
+ Assert.IsNotNull(layout);
+ Assert.AreEqual("test", layout.Name);
+ }
+
+ [TestMethod()]
+ public async Task InsertBrandLayoutTest()
+ {
+ //Act
+ await _brandLayoutService.InsertBrandLayout(new BrandLayout());
+ //Assert
+ Assert.IsTrue(_repository.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task UpdateBrandLayoutTest()
+ {
+ //Arrange
+ var categoryLayout = new BrandLayout() {
+ Name = "test"
+ };
+ await _brandLayoutService.InsertBrandLayout(categoryLayout);
+ categoryLayout.Name = "test2";
+
+ //Act
+ await _brandLayoutService.UpdateBrandLayout(categoryLayout);
+
+ //Assert
+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x => x.Name == "test2"));
+ }
+
+ [TestMethod()]
+ public async Task DeleteBrandLayoutTest()
+ {
+
+ //Arrange
+ var brandLayout1 = new BrandLayout() {
+ Name = "test1"
+ };
+ await _brandLayoutService.InsertBrandLayout(brandLayout1);
+ var brandLayout2 = new BrandLayout() {
+ Name = "test2"
+ };
+ await _brandLayoutService.InsertBrandLayout(brandLayout2);
+
+ //Act
+ await _brandLayoutService.DeleteBrandLayout(brandLayout1);
+
+ //Assert
+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test1"));
+ Assert.AreEqual(1, _repository.Table.Count());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Brands/BrandServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Brands/BrandServiceTests.cs
new file mode 100644
index 000000000..d3987d275
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Brands/BrandServiceTests.cs
@@ -0,0 +1,141 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Customers;
+using Grand.Domain.Data;
+using Grand.Infrastructure;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using Grand.SharedKernel.Extensions;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Catalog.Services.Brands.Tests
+{
+ [TestClass()]
+ public class BrandServiceTests
+ {
+ private IRepository<Brand> _repository;
+ private Mock<IWorkContext> _workContextMock;
+ private Mock<IMediator> _mediatorMock;
+ private BrandService _brandService;
+ private MemoryCacheBase _cacheBase;
+
+ [TestInitialize()]
+ public void InitializeTests()
+ {
+ CommonPath.BaseDirectory = "";
+
+ _repository = new MongoDBRepositoryTest<Brand>();
+ _workContextMock = new Mock<IWorkContext>();
+ _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "" });
+ _workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());
+ _mediatorMock = new Mock<IMediator>();
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+ _brandService = new BrandService(_cacheBase, _repository, _workContextMock.Object, _mediatorMock.Object);
+ }
+
+
+ [TestMethod()]
+ public async Task GetAllBrandsTest()
+ {
+ //Arrange
+ await _brandService.InsertBrand(new Brand() { Published = true });
+ await _brandService.InsertBrand(new Brand() { Published = true });
+ await _brandService.InsertBrand(new Brand() { Published = true });
+
+ //Act
+ var brand = await _brandService.GetAllBrands();
+
+ //Assert
+ Assert.AreEqual(3, brand.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetBrandByIdTest()
+ {
+ //Arrange
+ var brand = new Brand() {
+ Name = "test"
+ };
+ await _brandService.InsertBrand(brand);
+
+ //Act
+ var layout = await _brandService.GetBrandById(brand.Id);
+
+ //Assert
+ Assert.IsNotNull(layout);
+ Assert.AreEqual("test", layout.Name);
+ }
+
+ [TestMethod()]
+ public async Task InsertBrandTest()
+ {
+ //Act
+ await _brandService.InsertBrand(new Brand());
+ //Assert
+ Assert.IsTrue(_repository.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task UpdateBrandTest()
+ {
+ //Arrange
+ var brand = new Brand() {
+ Name = "test"
+ };
+ await _brandService.InsertBrand(brand);
+ brand.Name = "test2";
+
+ //Act
+ await _brandService.UpdateBrand(brand);
+
+ //Assert
+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x => x.Name == "test2"));
+ }
+
+ [TestMethod()]
+ public async Task DeleteBrandTest()
+ {
+ //Arrange
+ var brand1 = new Brand() {
+ Name = "test1"
+ };
+ await _brandService.InsertBrand(brand1);
+ var brand2 = new Brand() {
+ Name = "test2"
+ };
+ await _brandService.InsertBrand(brand2);
+
+ //Act
+ await _brandService.DeleteBrand(brand1);
+
+ //Assert
+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test1"));
+ Assert.AreEqual(1, _repository.Table.Count());
+ }
+
+ [TestMethod()]
+ public async Task GetAllBrandsByDiscountTest()
+ {
+ //Arrange
+ var brand1 = new Brand() {
+ Name = "test1"
+ };
+ await _brandService.InsertBrand(brand1);
+ var brand2 = new Brand() {
+ Name = "test2"
+ };
+ brand2.AppliedDiscounts.Add("disc1");
+
+ await _brandService.InsertBrand(brand2);
+
+ //Act
+ var result = await _brandService.GetAllBrandsByDiscount("disc1");
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual(1, result.Count());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryLayoutServiceDbTest.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceDbTest.cs
similarity index 87%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryLayoutServiceDbTest.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceDbTest.cs
index 340ecb201..871322ec7 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryLayoutServiceDbTest.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceDbTest.cs
@@ -8,12 +8,12 @@ using MediatR;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
-namespace Grand.Business.Catalog.Tests.Service.Category
+namespace Grand.Business.Catalog.Tests.Services.Categories
{
[TestClass()]
public class CategoryLayoutServiceDbTest
{
- private IRepository<CategoryLayout> _repostiory;
+ private IRepository<CategoryLayout> _repository;
private MemoryCacheBase _cacheBase;
private Mock<IMediator> _mediatorMock;
private CategoryLayoutService _categoryLayoutService;
@@ -21,11 +21,11 @@ namespace Grand.Business.Catalog.Tests.Service.Category
[TestInitialize()]
public void Init()
{
- _repostiory = new MongoDBRepositoryTest<CategoryLayout>();
+ _repository = new MongoDBRepositoryTest<CategoryLayout>();
_mediatorMock = new Mock<IMediator>();
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
- _categoryLayoutService = new CategoryLayoutService(_repostiory, _cacheBase, _mediatorMock.Object);
+ _categoryLayoutService = new CategoryLayoutService(_repository, _cacheBase, _mediatorMock.Object);
}
[TestMethod()]
@@ -52,10 +52,10 @@ namespace Grand.Business.Catalog.Tests.Service.Category
await _categoryLayoutService.InsertCategoryLayout(new CategoryLayout());
await _categoryLayoutService.InsertCategoryLayout(new CategoryLayout());
- //Assert
+ //Act
var layouts = await _categoryLayoutService.GetAllCategoryLayouts();
- //Act
+ //Assert
Assert.AreEqual(3, layouts.Count);
}
@@ -72,12 +72,12 @@ namespace Grand.Business.Catalog.Tests.Service.Category
};
await _categoryLayoutService.InsertCategoryLayout(categoryLayout2);
- //Assert
+ //Act
await _categoryLayoutService.DeleteCategoryLayout(categoryLayout1);
- //Act
- Assert.IsNull(_repostiory.Table.FirstOrDefault(x => x.Name == "test1"));
- Assert.AreEqual(1, _repostiory.Table.Count());
+ //Assert
+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test1"));
+ Assert.AreEqual(1, _repository.Table.Count());
}
@@ -85,10 +85,10 @@ namespace Grand.Business.Catalog.Tests.Service.Category
[TestMethod()]
public async Task InsertCategoryLayout_True()
{
- //Assert
- await _categoryLayoutService.InsertCategoryLayout(new CategoryLayout());
//Act
- Assert.IsTrue(_repostiory.Table.Any());
+ await _categoryLayoutService.InsertCategoryLayout(new CategoryLayout());
+ //Assert
+ Assert.IsTrue(_repository.Table.Any());
}
[TestMethod()]
@@ -101,11 +101,11 @@ namespace Grand.Business.Catalog.Tests.Service.Category
await _categoryLayoutService.InsertCategoryLayout(categoryLayout);
categoryLayout.Name = "test2";
- //Assert
+ //Act
await _categoryLayoutService.UpdateCategoryLayout(categoryLayout);
- //Act
- Assert.IsNotNull(_repostiory.Table.FirstOrDefault(x => x.Name == "test2"));
+ //Assert
+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x => x.Name == "test2"));
}
[TestMethod()]
@@ -118,11 +118,11 @@ namespace Grand.Business.Catalog.Tests.Service.Category
await _categoryLayoutService.InsertCategoryLayout(categoryLayout);
categoryLayout.Name = "test2";
- //Assert
+ //Act
await _categoryLayoutService.UpdateCategoryLayout(categoryLayout);
- //Act
- Assert.IsNull(_repostiory.Table.FirstOrDefault(x => x.Name == "test3"));
+ //Assert
+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test3"));
}
}
}
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryLayoutServiceTest.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceTest.cs
similarity index 82%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryLayoutServiceTest.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceTest.cs
index 2996fdf6e..f601a8865 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryLayoutServiceTest.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryLayoutServiceTest.cs
@@ -7,7 +7,7 @@ using MediatR;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
-namespace Grand.Business.Catalog.Tests.Service.Category
+namespace Grand.Business.Catalog.Tests.Services.Categories
{
[TestClass()]
public class CategoryLayoutServiceTest
@@ -30,13 +30,13 @@ namespace Grand.Business.Catalog.Tests.Service.Category
public async Task GetCategoryLayoutById_InvokeMethods()
{
await _categoryLayoutService.GetCategoryLayoutById("1");
- _cacheMock.Verify(c => c.GetAsync<CategoryLayout>(It.IsAny<string>(), It.IsAny<Func<Task<CategoryLayout>>>()), Times.Once);
+ _cacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<CategoryLayout>>>()), Times.Once);
}
[TestMethod()]
public async Task GetAllCategoryLayouts_InvokeMethods()
{
await _categoryLayoutService.GetAllCategoryLayouts();
- _cacheMock.Verify(c => c.GetAsync<List<CategoryLayout>>(It.IsAny<string>(), It.IsAny<Func<Task<List<CategoryLayout>>>>()), Times.Once);
+ _cacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<CategoryLayout>>>>()), Times.Once);
}
[TestMethod()]
public async Task DeleteCategoryLayout_ValidArguments_InvokeMethods()
@@ -44,7 +44,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
await _categoryLayoutService.DeleteCategoryLayout(new CategoryLayout());
_repostioryMock.Verify(c => c.DeleteAsync(It.IsAny<CategoryLayout>()), Times.Once);
_cacheMock.Verify(c => c.RemoveByPrefix(It.IsAny<string>(), true), Times.Exactly(1));
- _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityDeleted<CategoryLayout>>(), default(CancellationToken)), Times.Once);
+ _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityDeleted<CategoryLayout>>(), default), Times.Once);
}
@@ -54,7 +54,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
await _categoryLayoutService.InsertCategoryLayout(new CategoryLayout());
_repostioryMock.Verify(c => c.InsertAsync(It.IsAny<CategoryLayout>()), Times.Once);
_cacheMock.Verify(c => c.RemoveByPrefix(It.IsAny<string>(), true), Times.Exactly(1));
- _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityInserted<CategoryLayout>>(), default(CancellationToken)), Times.Once);
+ _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityInserted<CategoryLayout>>(), default), Times.Once);
}
[TestMethod()]
@@ -63,7 +63,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
await _categoryLayoutService.UpdateCategoryLayout(new CategoryLayout());
_repostioryMock.Verify(c => c.UpdateAsync(It.IsAny<CategoryLayout>()), Times.Once);
_cacheMock.Verify(c => c.RemoveByPrefix(It.IsAny<string>(), true), Times.Exactly(1));
- _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityUpdated<CategoryLayout>>(), default(CancellationToken)), Times.Once);
+ _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityUpdated<CategoryLayout>>(), default), Times.Once);
}
}
}
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceDbTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceDbTests.cs
similarity index 82%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceDbTests.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceDbTests.cs
index 83d854cb0..b0af17d64 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceDbTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceDbTests.cs
@@ -16,12 +16,12 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
-namespace Grand.Business.Catalog.Tests.Service.Category
+namespace Grand.Business.Catalog.Tests.Services.Categories
{
[TestClass()]
public class CategoryServiceDbTests
{
- private IRepository<Domain.Catalog.Category> _categoryRepository;
+ private IRepository<Category> _categoryRepository;
private Mock<IWorkContext> _workContextMock;
private Mock<IMediator> _mediatorMock;
private IAclService _aclServiceMock;
@@ -34,31 +34,31 @@ namespace Grand.Business.Catalog.Tests.Service.Category
{
CommonPath.BaseDirectory = "";
- _categoryRepository = new MongoDBRepositoryTest<Grand.Domain.Catalog.Category>();
+ _categoryRepository = new MongoDBRepositoryTest<Category>();
_workContextMock = new Mock<IWorkContext>();
_workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "" });
- _workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Domain.Customers.Customer());
+ _workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());
_mediatorMock = new Mock<IMediator>();
_aclServiceMock = new AclService();
_settings = new CatalogSettings();
_cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
_categoryService = new CategoryService(_cacheBase, _categoryRepository, _workContextMock.Object, _mediatorMock.Object, _aclServiceMock);
}
-
+
[TestMethod()]
public async Task InsertCategory()
{
//Act
- await _categoryService.InsertCategory(new Domain.Catalog.Category());
+ await _categoryService.InsertCategory(new Category());
//Assert
Assert.IsTrue(_categoryRepository.Table.Any());
- }
+ }
[TestMethod()]
public async Task UpdateCategory()
{
//Arrange
- var category = new Domain.Catalog.Category() { Name = "test" };
+ var category = new Category() { Name = "test" };
await _categoryService.InsertCategory(category);
category.Name = "test2";
//Act
@@ -74,10 +74,10 @@ namespace Grand.Business.Catalog.Tests.Service.Category
var allCategory = GetMockCategoryList();
allCategory.ToList().ForEach(x => _categoryService.InsertCategory(x).GetAwaiter().GetResult());
//Act
- await _categoryService.DeleteCategory(allCategory.FirstOrDefault(x=>x.Id == "1"));
+ await _categoryService.DeleteCategory(allCategory.FirstOrDefault(x => x.Id == "1"));
//Assert
Assert.IsTrue(_categoryRepository.Table.Count() == 4);
- Assert.IsNull(_categoryRepository.Table.FirstOrDefault(x=>x.Id == "1"));
+ Assert.IsNull(_categoryRepository.Table.FirstOrDefault(x => x.Id == "1"));
}
[TestMethod()]
@@ -85,7 +85,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
{
var allCategory = GetMockCategoryList();
allCategory.ToList().ForEach(x => _categoryService.InsertCategory(x).GetAwaiter().GetResult());
- var category = new Grand.Domain.Catalog.Category() { Id = "6", ParentCategoryId = "3", Published = true };
+ var category = new Category() { Id = "6", ParentCategoryId = "3", Published = true };
await _categoryService.InsertCategory(category);
var result = await _categoryService.GetCategoryBreadCrumb(category, false);
Assert.IsTrue(result.Count == 2);
@@ -98,7 +98,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
{
var allCategory = GetMockCategoryList();
allCategory.ToList().ForEach(x => _categoryService.InsertCategory(x).GetAwaiter().GetResult());
- var category = new Grand.Domain.Catalog.Category() { ParentCategoryId = "3" };
+ var category = new Category() { ParentCategoryId = "3" };
var result = _categoryService.GetCategoryBreadCrumb(category, allCategory);
Assert.IsTrue(result.Count == 0);
}
@@ -173,7 +173,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
{
var allCategory = GetMockCategoryList();
allCategory.ToList().ForEach(x => _categoryService.InsertCategory(x).GetAwaiter().GetResult());
- var category = new Grand.Domain.Catalog.Category() { Id = "6", ParentCategoryId = "3", Published = true };
+ var category = new Category() { Id = "6", ParentCategoryId = "3", Published = true };
await _categoryService.InsertCategory(category);
var result = _categoryService.GetCategoryBreadCrumb(category, allCategory);
Assert.IsTrue(result.Count == 2);
@@ -186,7 +186,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
{
var allCategory = GetMockCategoryList();
allCategory.ToList().ForEach(x => _categoryService.InsertCategory(x).GetAwaiter().GetResult());
- var category = new Grand.Domain.Catalog.Category() { Id = "6", ParentCategoryId = "1", Published = true };
+ var category = new Category() { Id = "6", ParentCategoryId = "1", Published = true };
var result = _categoryService.GetCategoryBreadCrumb(category, allCategory);
Assert.IsTrue(result.Count == 3);
Assert.IsTrue(result.Any(c => c.Id.Equals("6")));
@@ -199,7 +199,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
var exprectedString = "cat5 >> cat1 >> cat6";
var allCategory = GetMockCategoryList();
allCategory.ToList().ForEach(x => _categoryService.InsertCategory(x).GetAwaiter().GetResult());
- var category = new Grand.Domain.Catalog.Category() { Id = "6", Name = "cat6", ParentCategoryId = "1", Published = true };
+ var category = new Category() { Id = "6", Name = "cat6", ParentCategoryId = "1", Published = true };
var result = await _categoryService.GetFormattedBreadCrumb(category);
Assert.IsTrue(exprectedString.Equals(result));
}
@@ -209,7 +209,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
var exprectedString = "cat5 >> cat1 >> cat6";
var allCategory = GetMockCategoryList();
allCategory.ToList().ForEach(x => _categoryService.InsertCategory(x).GetAwaiter().GetResult());
- var category = new Grand.Domain.Catalog.Category() { Id = "6", Name = "cat6", ParentCategoryId = "1", Published = true };
+ var category = new Category() { Id = "6", Name = "cat6", ParentCategoryId = "1", Published = true };
var result = _categoryService.GetFormattedBreadCrumb(category, allCategory);
Assert.IsTrue(exprectedString.Equals(result));
}
@@ -223,16 +223,16 @@ namespace Grand.Business.Catalog.Tests.Service.Category
Assert.IsTrue(string.IsNullOrEmpty(result));
}
-
- private IList<Grand.Domain.Catalog.Category> GetMockCategoryList()
+
+ private IList<Category> GetMockCategoryList()
{
- return new List<Grand.Domain.Catalog.Category>()
+ return new List<Category>()
{
- new Grand.Domain.Catalog.Category(){ Id="1" ,Name="cat1",Published=true,ParentCategoryId="5",FeaturedProductsOnHomePage=true},
- new Grand.Domain.Catalog.Category(){ Id="2" ,Name="cat2",Published=true,IncludeInMenu = true},
- new Grand.Domain.Catalog.Category(){ Id="3" ,Name="cat3",Published=true,ShowOnHomePage=true,ShowOnSearchBox=true},
- new Grand.Domain.Catalog.Category(){ Id="4" ,Name="cat4",Published=true,ShowOnHomePage=true,ShowOnSearchBox=true},
- new Grand.Domain.Catalog.Category(){ Id="5" ,Name="cat5",Published=true,FeaturedProductsOnHomePage=true},
+ new Category(){ Id="1" ,Name="cat1",Published=true,ParentCategoryId="5",FeaturedProductsOnHomePage=true},
+ new Category(){ Id="2" ,Name="cat2",Published=true,IncludeInMenu = true},
+ new Category(){ Id="3" ,Name="cat3",Published=true,ShowOnHomePage=true,ShowOnSearchBox=true},
+ new Category(){ Id="4" ,Name="cat4",Published=true,ShowOnHomePage=true,ShowOnSearchBox=true},
+ new Category(){ Id="5" ,Name="cat5",Published=true,FeaturedProductsOnHomePage=true},
};
}
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceTests.cs
similarity index 66%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceTests.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceTests.cs
index ef5eea163..2892cb117 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Service/Category/CategoryServiceTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/CategoryServiceTests.cs
@@ -13,13 +13,13 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
-namespace Grand.Business.Catalog.Tests.Service.Category
+namespace Grand.Business.Catalog.Tests.Services.Categories
{
[TestClass()]
public class CategoryServiceTests
{
private Mock<ICacheBase> _casheManagerMock;
- private Mock<IRepository<Grand.Domain.Catalog.Category>> _categoryRepositoryMock;
+ private Mock<IRepository<Category>> _categoryRepositoryMock;
private Mock<MongoRepository<Product>> _productRepositoryMock;
private Mock<IWorkContext> _workContextMock;
private Mock<IMediator> _mediatorMock;
@@ -34,7 +34,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
CommonPath.BaseDirectory = "";
_casheManagerMock = new Mock<ICacheBase>();
- _categoryRepositoryMock = new Mock<IRepository<Grand.Domain.Catalog.Category>>();
+ _categoryRepositoryMock = new Mock<IRepository<Category>>();
_productRepositoryMock = new Mock<MongoRepository<Product>>();
_workContextMock = new Mock<IWorkContext>();
_mediatorMock = new Mock<IMediator>();
@@ -54,9 +54,9 @@ namespace Grand.Business.Catalog.Tests.Service.Category
[TestMethod()]
public async Task InsertCategory_ValidArgument_InvokeRepositoryAndCache()
{
- await _categoryService.InsertCategory(new Grand.Domain.Catalog.Category());
- _categoryRepositoryMock.Verify(c => c.InsertAsync(It.IsAny<Domain.Catalog.Category>()), Times.Once);
- _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityInserted<Grand.Domain.Catalog.Category>>(), default(CancellationToken)), Times.Once);
+ await _categoryService.InsertCategory(new Category());
+ _categoryRepositoryMock.Verify(c => c.InsertAsync(It.IsAny<Category>()), Times.Once);
+ _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityInserted<Category>>(), default), Times.Once);
_casheManagerMock.Verify(c => c.RemoveByPrefix(It.IsAny<string>(), true), Times.Exactly(2));
}
@@ -70,9 +70,9 @@ namespace Grand.Business.Catalog.Tests.Service.Category
[TestMethod()]
public async Task UpdateCategory_ValidArgument_InvokeRepositoryAndCache()
{
- await _categoryService.UpdateCategory(new Grand.Domain.Catalog.Category());
- _categoryRepositoryMock.Verify(c => c.UpdateAsync(It.IsAny<Grand.Domain.Catalog.Category>()), Times.Once);
- _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityUpdated<Grand.Domain.Catalog.Category>>(), default(CancellationToken)), Times.Once);
+ await _categoryService.UpdateCategory(new Category());
+ _categoryRepositoryMock.Verify(c => c.UpdateAsync(It.IsAny<Category>()), Times.Once);
+ _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityUpdated<Category>>(), default), Times.Once);
_casheManagerMock.Verify(c => c.RemoveByPrefix(It.IsAny<string>(), true), Times.Exactly(2));
}
@@ -80,9 +80,9 @@ namespace Grand.Business.Catalog.Tests.Service.Category
public void GetCategoryBreadCrumb_ShouldReturnEmptyList()
{
var allCategory = GetMockCategoryList();
- var category = new Grand.Domain.Catalog.Category() { ParentCategoryId = "3" };
- _aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(), It.IsAny<Customer>())).Returns(() => true);
- _aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(), It.IsAny<string>())).Returns(() => true);
+ var category = new Category() { ParentCategoryId = "3" };
+ _aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<Customer>())).Returns(() => true);
+ _aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<string>())).Returns(() => true);
var result = _categoryService.GetCategoryBreadCrumb(category, allCategory);
Assert.IsTrue(result.Count == 0);
}
@@ -91,10 +91,10 @@ namespace Grand.Business.Catalog.Tests.Service.Category
public void GetCategoryBreadCrumb_ShouldReturnTwoElement()
{
var allCategory = GetMockCategoryList();
- var category = new Grand.Domain.Catalog.Category() { Id = "6", ParentCategoryId = "3", Published = true };
+ var category = new Category() { Id = "6", ParentCategoryId = "3", Published = true };
_workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "" });
- _aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(), It.IsAny<Customer>())).Returns(() => true);
- _aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(), It.IsAny<string>())).Returns(() => true);
+ _aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<Customer>())).Returns(() => true);
+ _aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<string>())).Returns(() => true);
var result = _categoryService.GetCategoryBreadCrumb(category, allCategory);
Assert.IsTrue(result.Count == 2);
Assert.IsTrue(result.Any(c => c.Id.Equals("6")));
@@ -105,10 +105,10 @@ namespace Grand.Business.Catalog.Tests.Service.Category
public void GetCategoryBreadCrumb_ShouldReturnThreeElement()
{
var allCategory = GetMockCategoryList();
- var category = new Grand.Domain.Catalog.Category() { Id = "6", ParentCategoryId = "1", Published = true };
+ var category = new Category() { Id = "6", ParentCategoryId = "1", Published = true };
_workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "" });
- _aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(), It.IsAny<Customer>())).Returns(() => true);
- _aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(), It.IsAny<string>())).Returns(() => true);
+ _aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<Customer>())).Returns(() => true);
+ _aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<string>())).Returns(() => true);
var result = _categoryService.GetCategoryBreadCrumb(category, allCategory);
Assert.IsTrue(result.Count == 3);
Assert.IsTrue(result.Any(c => c.Id.Equals("6")));
@@ -121,9 +121,9 @@ namespace Grand.Business.Catalog.Tests.Service.Category
{
var exprectedString = "cat5 >> cat1 >> cat6";
var allCategory = GetMockCategoryList();
- var category = new Grand.Domain.Catalog.Category() { Id = "6", Name = "cat6", ParentCategoryId = "1", Published = true };
- _aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(), It.IsAny<Customer>())).Returns(() => true);
- _aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(), It.IsAny<string>())).Returns(() => true);
+ var category = new Category() { Id = "6", Name = "cat6", ParentCategoryId = "1", Published = true };
+ _aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<Customer>())).Returns(() => true);
+ _aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<string>())).Returns(() => true);
var result = _categoryService.GetFormattedBreadCrumb(category, allCategory);
Assert.IsTrue(exprectedString.Equals(result));
}
@@ -132,8 +132,8 @@ namespace Grand.Business.Catalog.Tests.Service.Category
public void GetFormattedBreadCrumb_ReturnEmptyString()
{
var allCategory = GetMockCategoryList();
- _aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(), It.IsAny<Customer>())).Returns(() => true);
- _aclServiceMock.Setup(a => a.Authorize<Grand.Domain.Catalog.Category>(It.IsAny<Grand.Domain.Catalog.Category>(), It.IsAny<string>())).Returns(() => true);
+ _aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<Customer>())).Returns(() => true);
+ _aclServiceMock.Setup(a => a.Authorize(It.IsAny<Category>(), It.IsAny<string>())).Returns(() => true);
var result = _categoryService.GetFormattedBreadCrumb(null, allCategory);
Assert.IsTrue(string.IsNullOrEmpty(result));
}
@@ -146,7 +146,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
await _productCategoryService.DeleteProductCategory(new ProductCategory(), "1");
//TODO
//collectonMock.Verify(c => c.UpdateOneAsync(It.IsAny<FilterDefinition<Product>>(), It.IsAny<UpdateDefinition<Product>>(), null, default(CancellationToken)), Times.Once);
- _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityDeleted<ProductCategory>>(), default(CancellationToken)), Times.Once);
+ _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityDeleted<ProductCategory>>(), default), Times.Once);
//clear product cache and ProductCategory
_casheManagerMock.Verify(c => c.RemoveByPrefix(It.IsAny<string>(), true), Times.Exactly(2));
}
@@ -165,7 +165,7 @@ namespace Grand.Business.Catalog.Tests.Service.Category
await _productCategoryService.InsertProductCategory(new ProductCategory(), "id");
//TODO
//collectonMock.Verify(c => c.UpdateOneAsync(It.IsAny<FilterDefinition<Product>>(), It.IsAny<UpdateDefinition<Product>>(), null, default(CancellationToken)), Times.Once);
- _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityInserted<ProductCategory>>(), default(CancellationToken)), Times.Once);
+ _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityInserted<ProductCategory>>(), default), Times.Once);
_casheManagerMock.Verify(c => c.RemoveByPrefix(It.IsAny<string>(), true), Times.Exactly(2));
}
@@ -175,15 +175,15 @@ namespace Grand.Business.Catalog.Tests.Service.Category
Assert.ThrowsExceptionAsync<ArgumentNullException>(async () => await _productCategoryService.InsertProductCategory(null, "id"), "productCategory");
}
- private IList<Grand.Domain.Catalog.Category> GetMockCategoryList()
+ private IList<Category> GetMockCategoryList()
{
- return new List<Grand.Domain.Catalog.Category>()
+ return new List<Category>()
{
- new Grand.Domain.Catalog.Category(){ Id="1" ,Name="cat1",Published=true,ParentCategoryId="5"},
- new Grand.Domain.Catalog.Category(){ Id="2" ,Name="cat2",Published=true},
- new Grand.Domain.Catalog.Category(){ Id="3" ,Name="cat3",Published=true},
- new Grand.Domain.Catalog.Category(){ Id="4" ,Name="cat4",Published=true},
- new Grand.Domain.Catalog.Category(){ Id="5" ,Name="cat5",Published=true},
+ new Category(){ Id="1" ,Name="cat1",Published=true,ParentCategoryId="5"},
+ new Category(){ Id="2" ,Name="cat2",Published=true},
+ new Category(){ Id="3" ,Name="cat3",Published=true},
+ new Category(){ Id="4" ,Name="cat4",Published=true},
+ new Category(){ Id="5" ,Name="cat5",Published=true},
};
}
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/ProductCategoryServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/ProductCategoryServiceTests.cs
new file mode 100644
index 000000000..32b12f6ae
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Categories/ProductCategoryServiceTests.cs
@@ -0,0 +1,128 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Customers;
+using Grand.Domain.Data;
+using Grand.Infrastructure;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using Grand.SharedKernel.Extensions;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Catalog.Services.Categories.Tests
+{
+ [TestClass()]
+ public class ProductCategoryServiceTests
+ {
+ private ProductCategoryService _productCategoryService;
+ private IRepository<Product> _repository;
+ private Mock<IWorkContext> _workContextMock;
+ private Mock<IMediator> _mediatorMock;
+ private MemoryCacheBase _cacheBase;
+
+ [TestInitialize()]
+ public void InitializeTests()
+ {
+ CommonPath.BaseDirectory = "";
+
+ _repository = new MongoDBRepositoryTest<Product>();
+ _workContextMock = new Mock<IWorkContext>();
+ _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "" });
+ _workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());
+ _mediatorMock = new Mock<IMediator>();
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+ _productCategoryService = new ProductCategoryService(_repository, _cacheBase, _workContextMock.Object, _mediatorMock.Object);
+ }
+
+
+ [TestMethod()]
+ public async Task GetProductCategoriesByCategoryIdTest()
+ {
+ //Arrange
+ var p1 = new Product();
+ p1.ProductCategories.Add(new ProductCategory() { CategoryId = "1" });
+ p1.ProductCategories.Add(new ProductCategory() { CategoryId = "2" });
+ await _repository.InsertAsync(p1);
+ var p2 = new Product();
+ p2.ProductCategories.Add(new ProductCategory() { CategoryId = "2" });
+ p2.ProductCategories.Add(new ProductCategory() { CategoryId = "3" });
+ await _repository.InsertAsync(p2);
+
+ //Act
+ var pc1 = await _productCategoryService.GetProductCategoriesByCategoryId("1");
+ var pc2 = await _productCategoryService.GetProductCategoriesByCategoryId("2");
+
+ //Assert
+ Assert.AreEqual(1, pc1.Count);
+ Assert.AreEqual(2, pc2.Count);
+ }
+
+ [TestMethod()]
+ public async Task InsertProductCategoryTest()
+ {
+ //Arrange
+ var p1 = new Product();
+ await _repository.InsertAsync(p1);
+ var p2 = new Product();
+ await _repository.InsertAsync(p2);
+
+ //Act
+ await _productCategoryService.InsertProductCategory(new ProductCategory() { CategoryId = "1", DisplayOrder = 10 }, p1.Id);
+ await _productCategoryService.InsertProductCategory(new ProductCategory() { CategoryId = "2" }, p1.Id);
+
+ var pc1 = await _productCategoryService.GetProductCategoriesByCategoryId("1");
+
+ //Assert
+ Assert.AreEqual(1, pc1.Count);
+ Assert.AreEqual(10, pc1.FirstOrDefault().DisplayOrder);
+ }
+
+ [TestMethod()]
+ public async Task UpdateProductCategoryTest()
+ {
+ //Arrange
+ var p1 = new Product();
+ await _repository.InsertAsync(p1);
+ var p2 = new Product();
+ await _repository.InsertAsync(p2);
+
+ //Act
+ var pc = new ProductCategory() { CategoryId = "1", DisplayOrder = 10 };
+ await _productCategoryService.InsertProductCategory(pc, p1.Id);
+ await _productCategoryService.InsertProductCategory(new ProductCategory() { CategoryId = "2" }, p1.Id);
+
+ pc.CategoryId = "10";
+ pc.DisplayOrder = 5;
+ await _productCategoryService.UpdateProductCategory(pc, p1.Id);
+
+ var pc1 = await _productCategoryService.GetProductCategoriesByCategoryId("10");
+
+ //Assert
+ Assert.AreEqual(1, pc1.Count);
+ Assert.AreEqual(5, pc1.FirstOrDefault().DisplayOrder);
+ }
+
+ [TestMethod()]
+ public async Task DeleteProductCategoryTest()
+ {
+ //Arrange
+ var p1 = new Product();
+ await _repository.InsertAsync(p1);
+ var p2 = new Product();
+ await _repository.InsertAsync(p2);
+
+ //Act
+ var pc = new ProductCategory() { CategoryId = "1", DisplayOrder = 10 };
+ await _productCategoryService.InsertProductCategory(pc, p1.Id);
+ await _productCategoryService.InsertProductCategory(new ProductCategory() { CategoryId = "2" }, p1.Id);
+
+ await _productCategoryService.DeleteProductCategory(pc, p1.Id);
+
+ var pc1 = await _productCategoryService.GetProductCategoriesByCategoryId("1");
+
+ //Assert
+ Assert.AreEqual(0, pc1.Count);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/CollectionLayoutServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/CollectionLayoutServiceTests.cs
new file mode 100644
index 000000000..e66a55343
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/CollectionLayoutServiceTests.cs
@@ -0,0 +1,111 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Data;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Catalog.Services.Collections.Tests
+{
+ [TestClass()]
+ public class CollectionLayoutServiceTests
+ {
+ private IRepository<CollectionLayout> _repository;
+ private MemoryCacheBase _cacheBase;
+ private Mock<IMediator> _mediatorMock;
+ private CollectionLayoutService _collectionLayoutService;
+
+ [TestInitialize()]
+ public void Init()
+ {
+ _repository = new MongoDBRepositoryTest<CollectionLayout>();
+ _mediatorMock = new Mock<IMediator>();
+
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+ _collectionLayoutService = new CollectionLayoutService(_repository, _cacheBase, _mediatorMock.Object);
+ }
+
+
+ [TestMethod()]
+ public async Task GetAllCollectionLayoutsTest()
+ {
+ //Arrange
+ await _collectionLayoutService.InsertCollectionLayout(new CollectionLayout());
+ await _collectionLayoutService.InsertCollectionLayout(new CollectionLayout());
+ await _collectionLayoutService.InsertCollectionLayout(new CollectionLayout());
+
+ //Act
+ var layouts = await _collectionLayoutService.GetAllCollectionLayouts();
+
+ //Assert
+ Assert.AreEqual(3, layouts.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetCollectionLayoutByIdTest()
+ {
+ //Arrange
+ var collectionLayout = new CollectionLayout() {
+ Name = "test"
+ };
+ await _collectionLayoutService.InsertCollectionLayout(collectionLayout);
+
+ //Act
+ var layout = await _collectionLayoutService.GetCollectionLayoutById(collectionLayout.Id);
+
+ //Assert
+ Assert.IsNotNull(layout);
+ Assert.AreEqual("test", layout.Name);
+ }
+
+ [TestMethod()]
+ public async Task InsertCollectionLayoutTest()
+ {
+ //Act
+ await _collectionLayoutService.InsertCollectionLayout(new CollectionLayout());
+ //Assert
+ Assert.IsTrue(_repository.Table.Any());
+ }
+
+ [TestMethod()]
+ public async Task UpdateCollectionLayoutTest()
+ {
+ //Arrange
+ var categoryLayout = new CollectionLayout() {
+ Name = "test"
+ };
+ await _collectionLayoutService.InsertCollectionLayout(categoryLayout);
+ categoryLayout.Name = "test2";
+
+ //Act
+ await _collectionLayoutService.UpdateCollectionLayout(categoryLayout);
+
+ //Assert
+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x => x.Name == "test2"));
+ }
+
+ [TestMethod()]
+ public async Task DeleteCollectionLayoutTest()
+ {
+
+ //Arrange
+ var collectionLayout1 = new CollectionLayout() {
+ Name = "test1"
+ };
+ await _collectionLayoutService.InsertCollectionLayout(collectionLayout1);
+ var collectionLayout2 = new CollectionLayout() {
+ Name = "test2"
+ };
+ await _collectionLayoutService.InsertCollectionLayout(collectionLayout2);
+
+ //Act
+ await _collectionLayoutService.DeleteCollectionLayout(collectionLayout1);
+
+ //Assert
+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test1"));
+ Assert.AreEqual(1, _repository.Table.Count());
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Collections/CollectionServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/CollectionServiceTests.cs
similarity index 100%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Collections/CollectionServiceTests.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Collections/CollectionServiceTests.cs
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/ProductCollectionServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/ProductCollectionServiceTests.cs
new file mode 100644
index 000000000..e979736c9
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Collections/ProductCollectionServiceTests.cs
@@ -0,0 +1,128 @@
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Customers;
+using Grand.Domain.Data;
+using Grand.Infrastructure;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using Grand.SharedKernel.Extensions;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Catalog.Services.Collections.Tests
+{
+ [TestClass()]
+ public class ProductCollectionServiceTests
+ {
+ private ProductCollectionService _productCollectionService;
+ private IRepository<Product> _repository;
+ private Mock<IWorkContext> _workContextMock;
+ private Mock<IMediator> _mediatorMock;
+ private MemoryCacheBase _cacheBase;
+
+ [TestInitialize()]
+ public void InitializeTests()
+ {
+ CommonPath.BaseDirectory = "";
+
+ _repository = new MongoDBRepositoryTest<Product>();
+ _workContextMock = new Mock<IWorkContext>();
+ _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "" });
+ _workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());
+ _mediatorMock = new Mock<IMediator>();
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+ _productCollectionService = new ProductCollectionService(_cacheBase, _repository, _workContextMock.Object, _mediatorMock.Object);
+ }
+
+
+ [TestMethod()]
+ public async Task GetProductCollectionsByCollectionIdTest()
+ {
+ //Arrange
+ var p1 = new Product();
+ p1.ProductCollections.Add(new ProductCollection() { CollectionId = "1" });
+ p1.ProductCollections.Add(new ProductCollection() { CollectionId = "2" });
+ await _repository.InsertAsync(p1);
+ var p2 = new Product();
+ p2.ProductCollections.Add(new ProductCollection() { CollectionId = "2" });
+ p2.ProductCollections.Add(new ProductCollection() { CollectionId = "3" });
+ await _repository.InsertAsync(p2);
+
+ //Act
+ var pc1 = await _productCollectionService.GetProductCollectionsByCollectionId("1", "");
+ var pc2 = await _productCollectionService.GetProductCollectionsByCollectionId("2", "");
+
+ //Assert
+ Assert.AreEqual(1, pc1.Count);
+ Assert.AreEqual(2, pc2.Count);
+ }
+
+ [TestMethod()]
+ public async Task InsertProductCollectionTest()
+ {
+ //Arrange
+ var p1 = new Product();
+ await _repository.InsertAsync(p1);
+ var p2 = new Product();
+ await _repository.InsertAsync(p2);
+
+ //Act
+ await _productCollectionService.InsertProductCollection(new ProductCollection() { CollectionId = "1", DisplayOrder = 10 }, p1.Id);
+ await _productCollectionService.InsertProductCollection(new ProductCollection() { CollectionId = "2" }, p1.Id);
+
+ var pc1 = await _productCollectionService.GetProductCollectionsByCollectionId("1", "");
+
+ //Assert
+ Assert.AreEqual(1, pc1.Count);
+ Assert.AreEqual(10, pc1.FirstOrDefault().DisplayOrder);
+ }
+
+ [TestMethod()]
+ public async Task UpdateProductCollectionTest()
+ {
+ //Arrange
+ var p1 = new Product();
+ await _repository.InsertAsync(p1);
+ var p2 = new Product();
+ await _repository.InsertAsync(p2);
+
+ //Act
+ var pc = new ProductCollection() { CollectionId = "1", DisplayOrder = 10 };
+ await _productCollectionService.InsertProductCollection(pc, p1.Id);
+ await _productCollectionService.InsertProductCollection(new ProductCollection() { CollectionId = "2" }, p1.Id);
+
+ pc.CollectionId = "10";
+ pc.DisplayOrder = 5;
+ await _productCollectionService.UpdateProductCollection(pc, p1.Id);
+
+ var pc1 = await _productCollectionService.GetProductCollectionsByCollectionId("10", "");
+
+ //Assert
+ Assert.AreEqual(1, pc1.Count);
+ Assert.AreEqual(5, pc1.FirstOrDefault().DisplayOrder);
+ }
+
+ [TestMethod()]
+ public async Task DeleteProductCollectionTest()
+ {
+ //Arrange
+ var p1 = new Product();
+ await _repository.InsertAsync(p1);
+ var p2 = new Product();
+ await _repository.InsertAsync(p2);
+
+ //Act
+ var pc = new ProductCollection() { CollectionId = "1", DisplayOrder = 10 };
+ await _productCollectionService.InsertProductCollection(pc, p1.Id);
+ await _productCollectionService.InsertProductCollection(new ProductCollection() { CollectionId = "2" }, p1.Id);
+
+ await _productCollectionService.DeleteProductCollection(pc, p1.Id);
+
+ var pc1 = await _productCollectionService.GetProductCollectionsByCollectionId("1", "");
+
+ //Assert
+ Assert.AreEqual(0, pc1.Count);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Directory/GeoLookupServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Directory/GeoLookupServiceTests.cs
new file mode 100644
index 000000000..9c239edeb
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Directory/GeoLookupServiceTests.cs
@@ -0,0 +1,43 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Grand.Business.Catalog.Services.Directory;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Moq;
+using Grand.Business.Core.Interfaces.Common.Logging;
+using Grand.SharedKernel.Extensions;
+
+namespace Grand.Business.Catalog.Services.Directory.Tests
+{
+ [TestClass()]
+ public class GeoLookupServiceTests
+ {
+ private Mock<ILogger> _loggerMock;
+ private GeoLookupService _service;
+ private string IPAddressUS = "142.250.203.206";
+ [TestInitialize()]
+ public void Init()
+ {
+ CommonPath.BaseDirectory = "../../../../../Web/Grand.Web/";
+ _loggerMock = new Mock<ILogger>();
+ _service = new GeoLookupService(_loggerMock.Object);
+ }
+
+
+ [TestMethod()]
+ public void CountryIsoCodeTest()
+ {
+ var countryiso = _service.CountryIsoCode(IPAddressUS);
+ Assert.AreEqual("US", countryiso);
+ }
+
+ [TestMethod()]
+ public void CountryNameTest()
+ {
+ var countryname = _service.CountryName(IPAddressUS);
+ Assert.AreEqual("United States", countryname);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Directory/MeasureServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Directory/MeasureServiceTests.cs
similarity index 100%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Directory/MeasureServiceTests.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Directory/MeasureServiceTests.cs
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Directory/SearchTermServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Directory/SearchTermServiceTests.cs
similarity index 100%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Directory/SearchTermServiceTests.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Directory/SearchTermServiceTests.cs
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountAmountProviderTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountAmountProviderTests.cs
new file mode 100644
index 000000000..848464835
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountAmountProviderTests.cs
@@ -0,0 +1,27 @@
+using Grand.Business.Core.Interfaces.Catalog.Discounts;
+using Grand.Domain.Catalog;
+using Grand.Domain.Customers;
+using Grand.Domain.Discounts;
+
+namespace Grand.Business.Catalog.Tests.Services.Discounts
+{
+ public class DiscountAmountProviderTests : IDiscountAmountProvider
+ {
+ public string ConfigurationUrl => throw new NotImplementedException();
+
+ public string SystemName => "SampleDiscountAmountProvider";
+
+ public string FriendlyName => throw new NotImplementedException();
+
+ public int Priority => throw new NotImplementedException();
+
+ public IList<string> LimitedToStores => new List<string>();
+
+ public IList<string> LimitedToGroups => new List<string>();
+
+ public async Task<double> DiscountAmount(Discount discount, Customer customer, Product product, double amount)
+ {
+ return await Task.FromResult(9);
+ }
+ }
+}
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountProviderTest.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountProviderTest.cs
new file mode 100644
index 000000000..068fe2733
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountProviderTest.cs
@@ -0,0 +1,54 @@
+using Grand.Business.Core.Interfaces.Catalog.Discounts;
+using Grand.Business.Core.Utilities.Catalog;
+
+namespace Grand.Business.Catalog.Tests.Services.Discounts
+{
+ public class DiscountProviderTest : IDiscountProvider
+ {
+ private IList<string> limitedToStores;
+ private IList<string> limitedToGroups;
+ public DiscountProviderTest()
+ {
+ limitedToStores = new List<string>();
+ limitedToGroups = new List<string>();
+ }
+
+ public string ConfigurationUrl => throw new NotImplementedException();
+
+ public string SystemName => "SampleDiscountProvider";
+
+ public string FriendlyName => throw new NotImplementedException();
+
+ public int Priority => throw new NotImplementedException();
+
+ public IList<string> LimitedToStores => limitedToStores;
+
+ public IList<string> LimitedToGroups => limitedToGroups;
+
+ public IList<IDiscountRule> GetRequirementRules()
+ {
+ return new List<IDiscountRule> { new DiscountRuleValidTest() };
+ }
+ }
+
+ public class DiscountRuleValidTest : IDiscountRule
+ {
+ public string SystemName => throw new NotImplementedException();
+
+ public string FriendlyName => throw new NotImplementedException();
+
+ public async Task<DiscountRuleValidationResult> CheckRequirement(DiscountRuleValidationRequest request)
+ {
+ var result = new DiscountRuleValidationResult() {
+ IsValid = true,
+ };
+ return await Task.FromResult(result);
+ }
+
+ public string GetConfigurationUrl(string discountId, string discountRequirementId)
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+}
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountServiceTests.cs
new file mode 100644
index 000000000..c63a3d341
--- /dev/null
+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Discounts/DiscountServiceTests.cs
@@ -0,0 +1,858 @@
+using Grand.Business.Catalog.Tests.Services.Discounts;
+using Grand.Business.Core.Interfaces.Catalog.Discounts;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Utilities.Catalog;
+using Grand.Data.Tests.MongoDb;
+using Grand.Domain.Catalog;
+using Grand.Domain.Customers;
+using Grand.Domain.Data;
+using Grand.Domain.Discounts;
+using Grand.Infrastructure;
+using Grand.Infrastructure.Caching;
+using Grand.Infrastructure.Tests.Caching;
+using Grand.SharedKernel.Extensions;
+using MediatR;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Moq;
+
+namespace Grand.Business.Catalog.Services.Discounts.Tests
+{
+ [TestClass()]
+ public class DiscountServiceTests
+ {
+ private IRepository<Discount> _repository;
+ private IRepository<DiscountCoupon> _discountCouponRepository;
+ private IRepository<DiscountUsageHistory> _discountUsageHistoryRepository;
+ private Mock<ITranslationService> _translationServiceMock;
+
+ private Mock<IWorkContext> _workContextMock;
+ private Mock<IMediator> _mediatorMock;
+ private DiscountService _dicountService;
+ private MemoryCacheBase _cacheBase;
+
+ private IEnumerable<IDiscountProvider> _discountProviders;
+ private IEnumerable<IDiscountAmountProvider> _discountAmountProviders;
+
+ [TestInitialize()]
+ public void InitializeTests()
+ {
+ CommonPath.BaseDirectory = "";
+
+ _repository = new MongoDBRepositoryTest<Discount>();
+ _discountCouponRepository = new MongoDBRepositoryTest<DiscountCoupon>();
+ _discountUsageHistoryRepository = new MongoDBRepositoryTest<DiscountUsageHistory>();
+ _workContextMock = new Mock<IWorkContext>();
+ _translationServiceMock = new Mock<ITranslationService>();
+ _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "" });
+ _workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());
+ _mediatorMock = new Mock<IMediator>();
+ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);
+
+ _discountProviders = new List<IDiscountProvider> { new DiscountProviderTest() };
+ _discountAmountProviders = new List<IDiscountAmountProvider> { new DiscountAmountProviderTests() };
+
+ _dicountService = new DiscountService(_cacheBase, _repository, _discountCouponRepository, _discountUsageHistoryRepository, _translationServiceMock.Object,
+ _workContextMock.Object, _discountProviders, _discountAmountProviders, _mediatorMock.Object);
+ }
+
+ [TestMethod()]
+ public async Task GetDiscountByIdTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test"
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ //Act
+ var result = await _dicountService.GetDiscountById(discount.Id);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual("test", result.Name);
+ }
+
+ [TestMethod()]
+ public async Task GetAllDiscountsTest()
+ {
+ //Arrange
+ var discount1 = new Discount() {
+ Name = "test1",
+ IsEnabled = true,
+ };
+ await _dicountService.InsertDiscount(discount1);
+
+ var discount2 = new Discount() {
+ Name = "test2",
+ IsEnabled = true,
+ };
+
+ await _dicountService.InsertDiscount(discount2);
+
+ //Act
+ var result = await _dicountService.GetAllDiscounts(null, showHidden: true);
+
+ //Assert
+ Assert.IsNotNull(result);
+ Assert.AreEqual(2, result.Count());
+ }
+
+ [TestMethod()]
+ public async Task InsertDiscountTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test"
+ };
+ //Act
+ await _dicountService.InsertDiscount(discount);
+
+ //Assert
+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x=>x.Name == "test"));
+ Assert.AreEqual("test", _repository.Table.FirstOrDefault(x => x.Name == "test").Name);
+
+ }
+
+ [TestMethod()]
+ public async Task UpdateDiscountTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test"
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ //Act
+ discount.Name = "test2";
+ await _dicountService.UpdateDiscount(discount);
+
+ //Assert
+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x => x.Name == "test2"));
+ Assert.AreEqual("test2", _repository.Table.FirstOrDefault(x => x.Name == "test2").Name);
+ }
+
+ [TestMethod()]
+ public async Task DeleteDiscountTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test"
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ //Act
+ await _dicountService.DeleteDiscount(discount);
+
+ //Assert
+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test"));
+ }
+
+ //TODO
+ //[TestMethod()]
+ //public void LoadDiscountProviderBySystemNameTest_NotNull()
+ //{
+ // //Act
+ // var provider = _dicountService.LoadDiscountProviderBySystemName("SampleDiscountProvider");
+ // //Assert
+ // Assert.IsNotNull(provider);
+ //}
+ //[TestMethod()]
+ //public void LoadDiscountProviderBySystemNameTest_Null()
+ //{
+ // //Act
+ // var provider = _dicountService.LoadDiscountProviderBySystemName("SampleDiscountProvider2");
+ // //Assert
+ // Assert.IsNull(provider);
+ //}
+
+ [TestMethod()]
+ public void LoadAllDiscountProvidersTest()
+ {
+ //Act
+ var providers = _dicountService.LoadAllDiscountProviders();
+ //Assert
+ Assert.AreEqual(1, providers.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetDiscountByCouponCodeTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+
+ //Act
+ var coupon = await _dicountService.GetDiscountByCouponCode("TEST123");
+
+ //Assert
+ Assert.IsNotNull(coupon);
+ Assert.AreEqual(discount.Id, coupon.Id);
+ }
+
+ [TestMethod()]
+ public async Task ExistsCodeInDiscountTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+
+ //Act
+ var coupon = await _dicountService.ExistsCodeInDiscount("TEST123", discount.Id, null);
+
+ //Assert
+ Assert.AreEqual(true, coupon);
+ }
+
+ [TestMethod()]
+ public async Task GetAllCouponCodesByDiscountIdTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+ var discountCoupon1 = new DiscountCoupon() {
+ CouponCode = "TEST124",
+ DiscountId = discount.Id,
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon1);
+ var discountCoupon2 = new DiscountCoupon() {
+ CouponCode = "TEST125",
+ DiscountId = "id",
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon2);
+ //Act
+ var coupon = await _dicountService.GetAllCouponCodesByDiscountId(discount.Id);
+ //Assert
+ Assert.AreEqual(2, coupon.Count);
+ }
+
+ [TestMethod()]
+ public async Task GetDiscountCodeByIdTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+ var discountCoupon1 = new DiscountCoupon() {
+ CouponCode = "TEST124",
+ DiscountId = discount.Id,
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon1);
+ var discountCoupon2 = new DiscountCoupon() {
+ CouponCode = "TEST125",
+ DiscountId = "id",
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon2);
+ //Act
+ var coupon = await _dicountService.GetDiscountCodeById(discountCoupon.Id);
+ //Assert
+ Assert.IsNotNull(coupon);
+ Assert.AreEqual("TEST123", coupon.CouponCode);
+ }
+
+ [TestMethod()]
+ public async Task GetDiscountCodeByCodeTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+ var discountCoupon1 = new DiscountCoupon() {
+ CouponCode = "TEST124",
+ DiscountId = discount.Id,
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon1);
+ var discountCoupon2 = new DiscountCoupon() {
+ CouponCode = "TEST125",
+ DiscountId = "id",
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon2);
+ //Act
+ var coupon = await _dicountService.GetDiscountCodeByCode(discountCoupon.CouponCode);
+ //Assert
+ Assert.IsNotNull(coupon);
+ Assert.AreEqual("TEST123", coupon.CouponCode);
+ }
+
+ [TestMethod()]
+ public async Task DeleteDiscountCouponTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+ var discountCoupon1 = new DiscountCoupon() {
+ CouponCode = "TEST124",
+ DiscountId = discount.Id,
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon1);
+ var discountCoupon2 = new DiscountCoupon() {
+ CouponCode = "TEST125",
+ DiscountId = "id",
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon2);
+
+ //Act
+ await _dicountService.DeleteDiscountCoupon(discountCoupon);
+ //Assert
+ Assert.IsNull(_discountCouponRepository.Table.FirstOrDefault(x=>x.Id == discountCoupon.Id));
+ }
+
+ [TestMethod()]
+ public async Task InsertDiscountCouponTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ };
+ //Act
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+
+ //Assert
+ Assert.IsNotNull(_discountCouponRepository.Table.FirstOrDefault(x => x.Id == discountCoupon.Id));
+ }
+
+ [TestMethod()]
+ public async Task DiscountCouponSetAsUsedTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+
+ //Act
+ await _dicountService.DiscountCouponSetAsUsed("TEST123", true);
+
+ //Assert
+ Assert.IsNotNull(_discountCouponRepository.Table.FirstOrDefault(x => x.Id == discountCoupon.Id));
+ Assert.IsTrue(_discountCouponRepository.Table.FirstOrDefault(x => x.Id == discountCoupon.Id).Used);
+ }
+
+ [TestMethod()]
+ public async Task CancelDiscountTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ Used = true
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+
+ var discountUsageHistory = new DiscountUsageHistory() {
+ CreatedOnUtc = DateTime.UtcNow,
+ DiscountId = discount.Id,
+ OrderId = "123",
+ CouponCode = "TEST123"
+ };
+ await _discountUsageHistoryRepository.InsertAsync(discountUsageHistory);
+
+ //Act
+ await _dicountService.CancelDiscount("123");
+
+ //Assert
+ Assert.IsTrue(_discountUsageHistoryRepository.Table.FirstOrDefault(x=>x.Id == discountUsageHistory.Id).Canceled);
+ Assert.IsFalse(_discountCouponRepository.Table.FirstOrDefault(x => x.Id == discountCoupon.Id).Used);
+ }
+
+ [TestMethod()]
+ public async Task ValidateDiscountTest_Valid_CouponCodesToValidate()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true,
+ CurrencyCode = "USD"
+ };
+ await _dicountService.InsertDiscount(discount);
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ Used = true
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+ var customer = new Customer();
+ customer.UserFields.Add(new Domain.Common.UserField() { Key = SystemCustomerFieldNames.DiscountCoupons, Value = "TEST123", StoreId = "" });
+ //Act
+ var result = await _dicountService.ValidateDiscount(discount, customer, new Domain.Directory.Currency() { CurrencyCode = "USD" });
+ //Assert
+ Assert.IsTrue(result.IsValid);
+ }
+ [TestMethod()]
+ public async Task ValidateDiscountTest_InValid_CouponCodesToValidate()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true,
+ CurrencyCode = "USD",
+ RequiresCouponCode = true
+ };
+ await _dicountService.InsertDiscount(discount);
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ Used = true
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+ var customer = new Customer();
+ customer.UserFields.Add(new Domain.Common.UserField() { Key = SystemCustomerFieldNames.DiscountCoupons, Value = "TEST12", StoreId = "" });
+ //Act
+ var result = await _dicountService.ValidateDiscount(discount, customer, new Domain.Directory.Currency() { CurrencyCode = "USD" });
+ //Assert
+ Assert.IsFalse(result.IsValid);
+ }
+ [TestMethod()]
+ public async Task ValidateDiscountTest_InValid_CurrencyCode()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true,
+ CurrencyCode = "EUR",
+ };
+ await _dicountService.InsertDiscount(discount);
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ Used = true
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+ var customer = new Customer();
+ customer.UserFields.Add(new Domain.Common.UserField() { Key = SystemCustomerFieldNames.DiscountCoupons, Value = "TEST12", StoreId = "" });
+ //Act
+ var result = await _dicountService.ValidateDiscount(discount, customer, new Domain.Directory.Currency() { CurrencyCode = "USD" });
+ //Assert
+ Assert.IsFalse(result.IsValid);
+ }
+
+ [TestMethod()]
+ public async Task ValidateDiscountTest_InValid_EndDateUtc()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true,
+ CurrencyCode = "USD",
+ EndDateUtc = DateTime.UtcNow.AddDays(-1),
+ };
+ await _dicountService.InsertDiscount(discount);
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ Used = true
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+ var customer = new Customer();
+ customer.UserFields.Add(new Domain.Common.UserField() { Key = SystemCustomerFieldNames.DiscountCoupons, Value = "TEST12", StoreId = "" });
+ //Act
+ var result = await _dicountService.ValidateDiscount(discount, customer, new Domain.Directory.Currency() { CurrencyCode = "USD" });
+ //Assert
+ Assert.IsFalse(result.IsValid);
+ }
+ [TestMethod()]
+ public async Task ValidateDiscountTest_InValid_Disable()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = false,
+ CurrencyCode = "USD",
+ };
+ await _dicountService.InsertDiscount(discount);
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ Used = true
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+ var customer = new Customer();
+ customer.UserFields.Add(new Domain.Common.UserField() { Key = SystemCustomerFieldNames.DiscountCoupons, Value = "TEST12", StoreId = "" });
+ //Act
+ var result = await _dicountService.ValidateDiscount(discount, customer, new Domain.Directory.Currency() { CurrencyCode = "USD" });
+ //Assert
+ Assert.IsFalse(result.IsValid);
+ }
+ [TestMethod()]
+ public async Task GetDiscountUsageHistoryByIdTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ Used = true
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+
+ var discountUsageHistory = new DiscountUsageHistory() {
+ CreatedOnUtc = DateTime.UtcNow,
+ DiscountId = discount.Id,
+ OrderId = "123",
+ CouponCode = "TEST123"
+ };
+ await _discountUsageHistoryRepository.InsertAsync(discountUsageHistory);
+
+ //Act
+ await _dicountService.GetDiscountUsageHistoryById(discountUsageHistory.Id);
+
+ //Assert
+ Assert.IsNotNull(_discountUsageHistoryRepository.Table.FirstOrDefault(x => x.Id == discountUsageHistory.Id));
+
+ }
+
+ [TestMethod()]
+ public async Task GetAllDiscountUsageHistoryTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ Used = true
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+
+ var discountUsageHistory = new DiscountUsageHistory() {
+ CreatedOnUtc = DateTime.UtcNow,
+ DiscountId = discount.Id,
+ OrderId = "123",
+ CouponCode = "TEST123"
+ };
+ await _discountUsageHistoryRepository.InsertAsync(discountUsageHistory);
+ var discountUsageHistory2 = new DiscountUsageHistory() {
+ CreatedOnUtc = DateTime.UtcNow,
+ DiscountId = discount.Id,
+ OrderId = "124",
+ CouponCode = "TEST123"
+ };
+ await _discountUsageHistoryRepository.InsertAsync(discountUsageHistory2);
+ //Act
+ var usageHistory = await _dicountService.GetAllDiscountUsageHistory();
+
+ //Assert
+ Assert.AreEqual(2, usageHistory.Count());
+
+ }
+
+ [TestMethod()]
+ public async Task InsertDiscountUsageHistoryTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ Used = true
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+
+ var discountUsageHistory = new DiscountUsageHistory() {
+ CreatedOnUtc = DateTime.UtcNow,
+ DiscountId = discount.Id,
+ OrderId = "123",
+ CouponCode = "TEST123"
+ };
+ await _discountUsageHistoryRepository.InsertAsync(discountUsageHistory);
+
+ //Act
+ var usageHistory = await _dicountService.GetDiscountUsageHistoryById(discountUsageHistory.Id);
+
+ //Assert
+ Assert.IsNotNull(usageHistory);
+ Assert.AreEqual(discountUsageHistory.CouponCode, usageHistory.CouponCode);
+ }
+
+ [TestMethod()]
+ public async Task UpdateDiscountUsageHistoryTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ Used = true
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+
+ var discountUsageHistory = new DiscountUsageHistory() {
+ CreatedOnUtc = DateTime.UtcNow,
+ DiscountId = discount.Id,
+ OrderId = "123",
+ CouponCode = "TEST123"
+ };
+ await _discountUsageHistoryRepository.InsertAsync(discountUsageHistory);
+
+ //Act
+ discountUsageHistory.OrderId = "12";
+ await _discountUsageHistoryRepository.UpdateAsync(discountUsageHistory);
+ var usageHistory = await _dicountService.GetDiscountUsageHistoryById(discountUsageHistory.Id);
+
+ //Assert
+ Assert.IsNotNull(usageHistory);
+ Assert.AreEqual(discountUsageHistory.OrderId, usageHistory.OrderId);
+ }
+
+ [TestMethod()]
+ public async Task DeleteDiscountUsageHistoryTest()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+ var discountCoupon = new DiscountCoupon() {
+ CouponCode = "TEST123",
+ DiscountId = discount.Id,
+ Used = true
+ };
+ await _discountCouponRepository.InsertAsync(discountCoupon);
+
+ var discountUsageHistory = new DiscountUsageHistory() {
+ CreatedOnUtc = DateTime.UtcNow,
+ DiscountId = discount.Id,
+ OrderId = "123",
+ CouponCode = "TEST123"
+ };
+ await _discountUsageHistoryRepository.InsertAsync(discountUsageHistory);
+
+ //Act
+ await _discountUsageHistoryRepository.DeleteAsync(discountUsageHistory);
+ var usageHistory = await _dicountService.GetDiscountUsageHistoryById(discountUsageHistory.Id);
+
+ //Assert
+ Assert.IsNull(usageHistory);
+ }
+
+ [TestMethod()]
+ public async Task GetDiscountAmountTest_global()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ DiscountAmount = 10,
+ CurrencyCode = "USD",
+ IsEnabled = true
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ //Act
+ var discountamount = await _dicountService.GetDiscountAmount(discount,
+ new Customer(),
+ new Domain.Directory.Currency() { CurrencyCode = "USD" },new Product(), 100);
+
+ //Assert
+ Assert.AreEqual(discount.DiscountAmount, discountamount);
+ }
+ public async Task GetDiscountAmountTest_AssignedToAllProducts()
+ {
+ //Arrange
+ var discount = new Discount() {
+ Name = "test",
+ DiscountAmount = 10,
+ CurrencyCode = "USD",
+ IsEnabled = true,
+ DiscountTypeId = DiscountType.AssignedToAllProducts
+ };
+ await _dicountService.InsertDiscount(discount);
+
+ //Act
+ var discountamount = await _dicountService.GetDiscountAmount(discount,
+ new Customer(),
+ new Domain.Directory.Currency() { CurrencyCode = "USD" }, new Product(), 100);
+
+ //Assert
+ Assert.AreEqual(discount.DiscountAmount, discountamount);
+ }
+ [TestMethod()]
+ public async Task GetPreferredDiscountTest()
+ {
+ //Arrange
+ var discount1 = new Discount() {
+ Name = "test",
+ DiscountAmount = 10,
+ CurrencyCode = "USD",
+ IsEnabled = true,
+ DiscountTypeId = DiscountType.AssignedToAllProducts
+ };
+ await _dicountService.InsertDiscount(discount1);
+ var discount2 = new Discount() {
+ Name = "test",
+ DiscountAmount = 20,
+ CurrencyCode = "USD",
+ IsEnabled = true,
+ DiscountTypeId = DiscountType.AssignedToAllProducts
+ };
+ await _dicountService.InsertDiscount(discount2);
+ //Act
+ var discountamount = await _dicountService.GetPreferredDiscount(
+ new List<ApplyDiscount> {
+ new ApplyDiscount() { DiscountId = discount1.Id, IsCumulative = false },
+ new ApplyDiscount() { DiscountId = discount2.Id, IsCumulative = false }
+ },
+ new Customer(),
+ new Domain.Directory.Currency() { CurrencyCode = "USD" }, new Product(), 100);
+
+ //Assert
+ Assert.AreEqual(discount2.DiscountAmount, discountamount.discountAmount);
+ }
+
+ [TestMethod()]
+ public async Task GetPreferredDiscountTest_IsCumulative_True()
+ {
+ //Arrange
+ var discount1 = new Discount() {
+ Name = "test",
+ DiscountAmount = 10,
+ CurrencyCode = "USD",
+ IsEnabled = true,
+ DiscountTypeId = DiscountType.AssignedToAllProducts
+ };
+ await _dicountService.InsertDiscount(discount1);
+ var discount2 = new Discount() {
+ Name = "test",
+ DiscountAmount = 20,
+ CurrencyCode = "USD",
+ IsEnabled = true,
+ DiscountTypeId = DiscountType.AssignedToAllProducts
+ };
+ await _dicountService.InsertDiscount(discount2);
+ //Act
+ var discountamount = await _dicountService.GetPreferredDiscount(
+ new List<ApplyDiscount> {
+ new ApplyDiscount() { DiscountId = discount1.Id, IsCumulative = true },
+ new ApplyDiscount() { DiscountId = discount2.Id, IsCumulative = true }
+ },
+ new Customer(),
+ new Domain.Directory.Currency() { CurrencyCode = "USD" }, new Product(), 100);
+
+ //Assert
+ Assert.AreEqual(discount1.DiscountAmount + discount2.DiscountAmount, discountamount.discountAmount);
+ }
+
+ [TestMethod()]
+ public async Task GetDiscountAmountProviderTest()
+ {
+ //Arrange
+ var discount1 = new Discount() {
+ Name = "test",
+ DiscountAmount = 10,
+ CurrencyCode = "USD",
+ IsEnabled = true,
+ CalculateByPlugin = true,
+ DiscountPluginName = "SampleDiscountAmountProvider",
+ DiscountTypeId = DiscountType.AssignedToAllProducts
+ };
+ await _dicountService.InsertDiscount(discount1);
+ //Act
+ var amount = await _dicountService.GetDiscountAmountProvider(discount1, new Customer(), new Product(), 100);
+ //Assert
+ Assert.AreEqual(9, amount);
+ }
+
+ [TestMethod()]
+ public void LoadDiscountAmountProviderBySystemNameTest()
+ {
+ //Act
+ var discountProvider = _dicountService.LoadDiscountAmountProviderBySystemName("SampleDiscountAmountProvider");
+ //Assert
+ Assert.IsNotNull(discountProvider);
+ }
+
+ [TestMethod()]
+ public void LoadDiscountAmountProvidersTest()
+ {
+ //Act
+ var discountProviders = _dicountService.LoadDiscountAmountProviders();
+ //Assert
+ Assert.AreEqual(1, discountProviders.Count);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Prices/PriceFormatterTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Prices/PriceFormatterTests.cs
similarity index 100%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Prices/PriceFormatterTests.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Prices/PriceFormatterTests.cs
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Prices/PriceServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Prices/PriceServiceTests.cs
similarity index 100%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Prices/PriceServiceTests.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Prices/PriceServiceTests.cs
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Products/CopyProductServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/CopyProductServiceTests.cs
similarity index 100%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Products/CopyProductServiceTests.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Products/CopyProductServiceTests.cs
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Products/CustomerGroupProductServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/CustomerGroupProductServiceTests.cs
similarity index 100%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Products/CustomerGroupProductServiceTests.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Products/CustomerGroupProductServiceTests.cs
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Products/ProductAttributeParserTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductAttributeParserTests.cs
similarity index 100%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Products/ProductAttributeParserTests.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductAttributeParserTests.cs
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Products/StockQuantityServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/StockQuantityServiceTests.cs
similarity index 100%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Products/StockQuantityServiceTests.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Products/StockQuantityServiceTests.cs
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Tax/FixedRateTestTaxProvider.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/FixedRateTestTaxProvider.cs
similarity index 100%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Tax/FixedRateTestTaxProvider.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Tax/FixedRateTestTaxProvider.cs
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Service/Tax/TaxServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxServiceTests.cs
similarity index 100%
rename from src/Tests/Grand.Business.Catalog.Tests/Service/Tax/TaxServiceTests.cs
rename to src/Tests/Grand.Business.Catalog.Tests/Services/Tax/TaxServiceTests.cs