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
support044fc1f21c40
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetRecommendedProductsQueryHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetRecommendedProductsQueryHandlerTests.csindex fce34c55a..28bad4b94 100644--- a/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetRecommendedProductsQueryHandlerTests.cs+++ b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetRecommendedProductsQueryHandlerTests.cs@@ -1,26 +1,40 @@-using Microsoft.VisualStudio.TestTools.UnitTesting;-using Grand.Business.Catalog.Queries.Handlers;-using System;-using System.Collections.Generic;-using System.Linq;-using System.Text;-using System.Threading.Tasks;+using Grand.Business.Core.Interfaces.Catalog.Products;+using Grand.Domain.Catalog;+using Grand.Domain.Customers;+using Grand.Domain.Data;+using Grand.Infrastructure.Caching;+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Moq;namespace Grand.Business.Catalog.Queries.Handlers.Tests{[TestClass()]public class GetRecommendedProductsQueryHandlerTests{- [TestMethod()]- public void GetRecommendedProductsQueryHandlerTest()+ private Mock<ICacheBase> _casheManagerMock;+ private Mock<IProductService> _productServiceMock;+ private Mock<IRepository<CustomerGroupProduct>> _customerGroupProductRepositoryMock;++ private GetRecommendedProductsQueryHandler handler;++ [TestInitialize()]+ public void Init(){- Assert.Fail();+ _casheManagerMock = new Mock<ICacheBase>();+ _productServiceMock = new Mock<IProductService>();+ _customerGroupProductRepositoryMock = new Mock<IRepository<CustomerGroupProduct>>();++ handler = new GetRecommendedProductsQueryHandler(_productServiceMock.Object, _casheManagerMock.Object, _customerGroupProductRepositoryMock.Object);}[TestMethod()]- public void HandleTest()+ public async Task HandleTest(){- Assert.Fail();+ var getRecommendedProductsQuery = new Core.Queries.Catalog.GetRecommendedProductsQuery();+ getRecommendedProductsQuery.CustomerGroupIds = new[] { "1" };+ getRecommendedProductsQuery.StoreId = "1";+ await handler.Handle(getRecommendedProductsQuery, CancellationToken.None);+ _casheManagerMock.Verify(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<Product>>>>()), Times.Once);}}}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetSearchProductsQueryHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetSearchProductsQueryHandlerTests.csnew file mode 100644index 000000000..6abc5e9c2--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetSearchProductsQueryHandlerTests.cs@@ -0,0 +1,42 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Grand.Business.Catalog.Queries.Handlers;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;+using Grand.Domain.Data;+using Grand.Domain.Catalog;+using Grand.Data.Tests.MongoDb;+using Grand.Business.Core.Interfaces.Catalog.Products;+using Moq;++namespace Grand.Business.Catalog.Queries.Handlers.Tests+{+ [TestClass()]+ public class GetSearchProductsQueryHandlerTests+ {+ private IRepository<Product> _repository;+ private GetSearchProductsQueryHandler handler;+ [TestInitialize()]+ public void Init()+ {+ _repository = new MongoDBRepositoryTest<Product>();+ handler = new GetSearchProductsQueryHandler(_repository, new Mock<ISpecificationAttributeService>().Object, new CatalogSettings() { IgnoreFilterableSpecAttributeOption = true});+ }+++ [TestMethod()]+ public async Task HandleTest()+ {+ //Arrange+ await _repository.InsertAsync(new Product() { Published = true, VisibleIndividually = true });+ var searchProductsQuery = new Core.Queries.Catalog.GetSearchProductsQuery();+ searchProductsQuery.Customer = new Domain.Customers.Customer();+ //Act+ var result = await handler.Handle(searchProductsQuery, CancellationToken.None);+ //Arrange+ Assert.IsNotNull(result);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetSuggestedProductsQueryHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetSuggestedProductsQueryHandlerTests.csnew file mode 100644index 000000000..7eaf6af08--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetSuggestedProductsQueryHandlerTests.cs@@ -0,0 +1,40 @@+using Grand.Business.Core.Interfaces.Catalog.Products;+using Grand.Domain.Catalog;+using Grand.Domain.Customers;+using Grand.Domain.Data;+using Grand.Infrastructure.Caching;+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Moq;++namespace Grand.Business.Catalog.Queries.Handlers.Tests+{+ [TestClass()]+ public class GetSuggestedProductsQueryHandlerTests+ {+ private Mock<ICacheBase> _casheManagerMock;+ private Mock<IProductService> _productServiceMock;+ private Mock<IRepository<CustomerTagProduct>> _customerGroupProductRepositoryMock;++ private GetSuggestedProductsQueryHandler handler;++ [TestInitialize()]+ public void Init()+ {+ _casheManagerMock = new Mock<ICacheBase>();+ _productServiceMock = new Mock<IProductService>();+ _customerGroupProductRepositoryMock = new Mock<IRepository<CustomerTagProduct>>();++ handler = new GetSuggestedProductsQueryHandler(_productServiceMock.Object, _casheManagerMock.Object, _customerGroupProductRepositoryMock.Object);+ }++ [TestMethod()]+ public async Task HandleTest()+ {+ var suggestedProductsQuery = new Core.Queries.Catalog.GetSuggestedProductsQuery();+ suggestedProductsQuery.CustomerTagIds = new[] { "1" };+ suggestedProductsQuery.ProductsNumber = 10;+ await handler.Handle(suggestedProductsQuery, CancellationToken.None);+ _casheManagerMock.Verify(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<Product>>>>()), Times.Once);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetVendorByIdQueryHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetVendorByIdQueryHandlerTests.csnew file mode 100644index 000000000..b9352a826--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Queries/Handlers/GetVendorByIdQueryHandlerTests.cs@@ -0,0 +1,37 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Grand.Business.Catalog.Queries.Handlers;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;+using Grand.Domain.Data;+using Grand.Domain.Vendors;+using Grand.Data.Tests.MongoDb;++namespace Grand.Business.Catalog.Queries.Handlers.Tests+{+ [TestClass()]+ public class GetVendorByIdQueryHandlerTests+ {+ private IRepository<Vendor> _repository;+ private GetVendorByIdQueryHandler handler;+ [TestInitialize()]+ public void Init()+ {+ _repository = new MongoDBRepositoryTest<Vendor>();+ handler = new GetVendorByIdQueryHandler(_repository);+ }++ [TestMethod()]+ public async Task HandleTest()+ {+ //Arrange+ await _repository.InsertAsync(new Vendor() { Id = "1" });+ //Act+ var result = await handler.Handle(new Core.Queries.Catalog.GetVendorByIdQuery() { Id = "1" }, CancellationToken.None);+ //Arrange+ Assert.IsNotNull(result);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Catalog.Tests/Startup/StartupApplicationTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Startup/StartupApplicationTests.csnew file mode 100644index 000000000..5dfa2a4ba--- /dev/null+++ b/src/Tests/Grand.Business.Catalog.Tests/Startup/StartupApplicationTests.cs@@ -0,0 +1,37 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Grand.Business.Catalog.Startup;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;+using Microsoft.Extensions.DependencyInjection;+using Microsoft.Extensions.Configuration;++namespace Grand.Business.Catalog.Startup.Tests+{+ [TestClass()]+ public class StartupApplicationTests+ {+ StartupApplication _application;+ ServiceCollection _serviceCollection;+ IConfiguration _configuration;++ [TestInitialize]+ public void Init()+ {+ _serviceCollection = new ServiceCollection();+ _configuration = new ConfigurationBuilder().Build();+ _application = new StartupApplication();++ }+ [TestMethod()]+ public void ConfigureServicesTest()+ {+ //Act+ _application.ConfigureServices(_serviceCollection, _configuration);+ //Assert+ Assert.IsTrue(_serviceCollection.Count > 0);+ }+ }+}\ No newline at end of file