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 tests
supportef3f251f0523
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductLayoutServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductLayoutServiceTests.csnew file mode 100644index 000000000..fab6d8815--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductLayoutServiceTests.cs@@ -0,0 +1,110 @@+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.Products.Tests+{+ [TestClass()]+ public class ProductLayoutServiceTests+ {+ private IRepository<ProductLayout> _repository;+ private MemoryCacheBase _cacheBase;+ private Mock<IMediator> _mediatorMock;+ private ProductLayoutService _productLayoutService;++ [TestInitialize()]+ public void Init()+ {+ _repository = new MongoDBRepositoryTest<ProductLayout>();+ _mediatorMock = new Mock<IMediator>();++ _cacheBase = new MemoryCacheBase(MemoryCacheTest.Get(), _mediatorMock.Object);+ _productLayoutService = new ProductLayoutService(_repository, _cacheBase, _mediatorMock.Object);+ }+++ [TestMethod()]+ public async Task GetAllProductLayoutsTest()+ {+ //Arrange+ await _productLayoutService.InsertProductLayout(new ProductLayout());+ await _productLayoutService.InsertProductLayout(new ProductLayout());+ await _productLayoutService.InsertProductLayout(new ProductLayout());++ //Act+ var layouts = await _productLayoutService.GetAllProductLayouts();++ //Assert+ Assert.AreEqual(3, layouts.Count);+ }++ [TestMethod()]+ public async Task GetProductLayoutByIdTest()+ {+ //Arrange+ var productLayout = new ProductLayout() {+ Name = "test"+ };+ await _productLayoutService.InsertProductLayout(productLayout);++ //Act+ var layout = await _productLayoutService.GetProductLayoutById(productLayout.Id);++ //Assert+ Assert.IsNotNull(layout);+ Assert.AreEqual("test", layout.Name);+ }++ [TestMethod()]+ public async Task InsertProductLayoutTest()+ {+ //Act+ await _productLayoutService.InsertProductLayout(new ProductLayout());+ //Assert+ Assert.IsTrue(_repository.Table.Any());+ }++ [TestMethod()]+ public async Task UpdateProductLayoutTest()+ {+ //Arrange+ var categoryLayout = new ProductLayout() {+ Name = "test"+ };+ await _productLayoutService.InsertProductLayout(categoryLayout);+ categoryLayout.Name = "test2";++ //Act+ await _productLayoutService.UpdateProductLayout(categoryLayout);++ //Assert+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x => x.Name == "test2"));+ }++ [TestMethod()]+ public async Task DeleteProductLayoutTest()+ {+ //Arrange+ var productLayout1 = new ProductLayout() {+ Name = "test1"+ };+ await _productLayoutService.InsertProductLayout(productLayout1);+ var productLayout2 = new ProductLayout() {+ Name = "test2"+ };+ await _productLayoutService.InsertProductLayout(productLayout2);++ //Act+ await _productLayoutService.DeleteProductLayout(productLayout1);++ //Assert+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.Name == "test1"));+ Assert.AreEqual(1, _repository.Table.Count());+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductReservationServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductReservationServiceTests.csnew file mode 100644index 000000000..93ed4bef3--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductReservationServiceTests.cs@@ -0,0 +1,167 @@+using Grand.Data.Tests.MongoDb;+using Grand.Domain.Catalog;+using Grand.Domain.Data;+using MediatR;+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Moq;++namespace Grand.Business.Catalog.Services.Products.Tests+{+ [TestClass()]+ public class ProductReservationServiceTests+ {++ ProductReservationService _service;+ private IRepository<ProductReservation> _repository;+ private IRepository<CustomerReservationsHelper> _repositoryCustomerReservationsHelper;+ private Mock<IMediator> _mediatorMock;++ [TestInitialize()]+ public void Init()+ {+ _repository = new MongoDBRepositoryTest<ProductReservation>();+ _repositoryCustomerReservationsHelper = new MongoDBRepositoryTest<CustomerReservationsHelper>();+ _mediatorMock = new Mock<IMediator>();++ _service = new ProductReservationService(_repository, _repositoryCustomerReservationsHelper, _mediatorMock.Object);+ }++ [TestMethod()]+ public async Task GetProductReservationsByProductIdTest()+ {+ //Arrange+ await _repository.InsertAsync(new ProductReservation() { ProductId = "1" });+ await _repository.InsertAsync(new ProductReservation() { ProductId = "1" });+ await _repository.InsertAsync(new ProductReservation() { ProductId = "2" });+ //Act+ var result = await _service.GetProductReservationsByProductId("1", null, null);++ Assert.AreEqual(2, result.Count);+ }++ [TestMethod()]+ public async Task InsertProductReservationTest()+ {+ //Arrange+ var p = new ProductReservation() { ProductId = "1" };+ //Act+ await _service.InsertProductReservation(p);+ //Assert+ Assert.AreEqual(1, _repository.Table.Count());+ }++ [TestMethod()]+ public async Task UpdateProductReservationTest()+ {+ //Arrange+ var p = new ProductReservation() { ProductId = "1" };+ await _repository.InsertAsync(p);+ //Act+ p.ProductId = "2";+ await _service.UpdateProductReservation(p);++ Assert.AreEqual("2", _repository.Table.FirstOrDefault().ProductId);+ }++ [TestMethod()]+ public async Task DeleteProductReservationTest()+ {+ //Arrange+ var p = new ProductReservation() { ProductId = "1" };+ await _repository.InsertAsync(p);+ //Act+ await _service.DeleteProductReservation(p);+ //Assert+ Assert.AreEqual(0, _repository.Table.Count());+ }++ [TestMethod()]+ public async Task GetProductReservationTest()+ {+ //Arrange+ var p = new ProductReservation() { ProductId = "1" };+ await _repository.InsertAsync(p);+ //Act+ var result = await _service.GetProductReservation(p.Id);+ //Assert+ Assert.IsNotNull(result);+ Assert.AreEqual("1", result.ProductId);+ }++ [TestMethod()]+ public async Task InsertCustomerReservationsHelperTest()+ {+ //Arrange+ var p = new CustomerReservationsHelper();+ //Act+ await _service.InsertCustomerReservationsHelper(p);+ //Assert+ Assert.AreEqual(1, _repositoryCustomerReservationsHelper.Table.Count());+ }++ [TestMethod()]+ public async Task DeleteCustomerReservationsHelperTest()+ {+ //Arrange+ var p = new CustomerReservationsHelper();+ await _repositoryCustomerReservationsHelper.InsertAsync(p);+ //Act+ await _service.DeleteCustomerReservationsHelper(p);+ //Assert+ Assert.AreEqual(0, _repository.Table.Count());+ }++ [TestMethod()]+ public async Task CancelReservationsByOrderIdTest()+ {+ //Arrange+ await _repository.InsertAsync(new ProductReservation() { OrderId = "1" });+ await _repository.InsertAsync(new ProductReservation() { OrderId = "2" });+ //Act+ await _service.CancelReservationsByOrderId("1");+ //Assert+ Assert.AreEqual(0, _repository.Table.Where(x=>x.OrderId == "1").Count());+ }++ [TestMethod()]+ public async Task GetCustomerReservationsHelperByIdTest()+ {+ //Arrange+ var p = new CustomerReservationsHelper() { CustomerId = "1" };+ await _repositoryCustomerReservationsHelper.InsertAsync(p);+ //Act+ var result = await _service.GetCustomerReservationsHelperById(p.Id);+ //Assert+ Assert.IsNotNull(result);+ Assert.AreEqual("1", result.CustomerId);+ }++ [TestMethod()]+ public async Task GetCustomerReservationsHelpersTest()+ {+ //Arrange+ await _repositoryCustomerReservationsHelper.InsertAsync(new CustomerReservationsHelper() { CustomerId = "1" });+ await _repositoryCustomerReservationsHelper.InsertAsync(new CustomerReservationsHelper() { CustomerId = "1" });+ await _repositoryCustomerReservationsHelper.InsertAsync(new CustomerReservationsHelper() { CustomerId = "2" });+ //Act+ var result = await _service.GetCustomerReservationsHelpers("1");+ //Assert+ Assert.IsNotNull(result);+ Assert.AreEqual(2, result.Count);+ }++ [TestMethod()]+ public async Task GetCustomerReservationsHelperBySciIdTest()+ {+ //Arrange+ await _repositoryCustomerReservationsHelper.InsertAsync(new CustomerReservationsHelper() { ShoppingCartItemId = "1" });+ await _repositoryCustomerReservationsHelper.InsertAsync(new CustomerReservationsHelper() { ShoppingCartItemId = "1" });+ await _repositoryCustomerReservationsHelper.InsertAsync(new CustomerReservationsHelper() { CustomerId = "2" });+ //Act+ var result = await _service.GetCustomerReservationsHelperBySciId("1");+ //Assert+ Assert.IsNotNull(result);+ Assert.AreEqual(2, result.Count);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductReviewServiceTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductReviewServiceTests.csnew file mode 100644index 000000000..c20afca71--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Services/Products/ProductReviewServiceTests.cs@@ -0,0 +1,103 @@+using Grand.Data.Tests.MongoDb;+using Grand.Domain.Catalog;+using Grand.Domain.Data;+using MediatR;+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Moq;++namespace Grand.Business.Catalog.Services.Products.Tests+{+ [TestClass()]+ public class ProductReviewServiceTests+ {+ private IRepository<ProductReview> _repository;+ private Mock<IMediator> _mediatorMock;+ private ProductReviewService _productReviewService;++ [TestInitialize()]+ public void Init()+ {+ _repository = new MongoDBRepositoryTest<ProductReview>();+ _mediatorMock = new Mock<IMediator>();+ _productReviewService = new ProductReviewService(_repository, _mediatorMock.Object);+ }+++ [TestMethod()]+ public async Task GetAllProductReviewsTest()+ {+ //Arrange+ await _repository.InsertManyAsync(new[] {+ new ProductReview(){ CustomerId = "1" },+ new ProductReview(){ CustomerId = "1"},+ new ProductReview(){ },+ new ProductReview(){ },+ });++ //Act+ var result = await _productReviewService.GetAllProductReviews("1", null);++ //Assert+ Assert.AreEqual(2, result.Count());+ }++ [TestMethod()]+ public async Task InsertProductReviewTest()+ {+ //Act+ await _productReviewService.InsertProductReview(new ProductReview());+ //Assert+ Assert.IsTrue(_repository.Table.Any());+ }++ [TestMethod()]+ public async Task UpdateProductReviewTest()+ {+ //Arrange+ var productReview = new ProductReview() {+ ReviewText = "test"+ };+ await _productReviewService.InsertProductReview(productReview);+ productReview.ReviewText = "test2";++ //Act+ await _productReviewService.UpdateProductReview(productReview);++ //Assert+ Assert.IsNotNull(_repository.Table.FirstOrDefault(x => x.ReviewText == "test2"));+ }++ [TestMethod()]+ public async Task DeleteProductReviewTest()+ {+ //Arrange+ var productReview = new ProductReview() {+ ReviewText = "test"+ };+ await _productReviewService.InsertProductReview(productReview);+ //Act+ await _productReviewService.DeleteProductReview(productReview);++ //Assert+ Assert.IsNull(_repository.Table.FirstOrDefault(x => x.ReviewText == "test1"));+ Assert.AreEqual(1, _repository.Table.Count());+ }++ [TestMethod()]+ public async Task GetProductReviewByIdTest()+ {+ //Arrange+ var productReview = new ProductReview() {+ ReviewText = "test"+ };+ await _productReviewService.InsertProductReview(productReview);++ //Act+ var result = await _productReviewService.GetProductReviewById(productReview.Id);++ //Assert+ Assert.IsNotNull(result);+ Assert.AreEqual("test", result.ReviewText);+ }+ }+}\ No newline at end of file