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
supportad4b87ec6558
diff --git a/src/Tests/Grand.Business.Messages.Tests/Grand.Business.Messages.Tests.csproj b/src/Tests/Grand.Business.Messages.Tests/Grand.Business.Messages.Tests.csprojindex c4664f983..65f9012c2 100644--- a/src/Tests/Grand.Business.Messages.Tests/Grand.Business.Messages.Tests.csproj+++ b/src/Tests/Grand.Business.Messages.Tests/Grand.Business.Messages.Tests.csproj@@ -18,6 +18,7 @@<ItemGroup><ProjectReference Include="..\..\Business\Grand.Business.Core\Grand.Business.Core.csproj" /><ProjectReference Include="..\..\Business\Grand.Business.Messages\Grand.Business.Messages.csproj" />+ <ProjectReference Include="..\Grand.Data.Tests\Grand.Data.Tests.csproj" /></ItemGroup></Project>diff --git a/src/Tests/Grand.Business.Messages.Tests/Queries/Handlers/GetBidsByProductIdQueryHandlerTests.cs b/src/Tests/Grand.Business.Messages.Tests/Queries/Handlers/GetBidsByProductIdQueryHandlerTests.csnew file mode 100644index 000000000..b2517d622--- /dev/null+++ b/src/Tests/Grand.Business.Messages.Tests/Queries/Handlers/GetBidsByProductIdQueryHandlerTests.cs@@ -0,0 +1,34 @@+using Grand.Data.Tests.MongoDb;+using Grand.Domain.Catalog;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Business.Messages.Queries.Handlers.Tests+{++ [TestClass()]+ public class GetBidsByProductIdQueryHandlerTests+ {+ private GetBidsByProductIdQueryHandler handler;++ [TestInitialize()]+ public void Init()+ {+ var _repository = new MongoDBRepositoryTest<Bid>();+ _repository.Insert(new Bid() { Id = "1", ProductId = "1" });+ _repository.Insert(new Bid());+ _repository.Insert(new Bid());+ _repository.Insert(new Bid());++ handler = new GetBidsByProductIdQueryHandler(_repository);+ }++ [TestMethod()]+ public async Task HandleTest()+ {+ //Act+ var result = await handler.Handle(new Core.Queries.Messages.GetBidsByProductIdQuery() { ProductId = "1" }, CancellationToken.None);+ //Assert+ Assert.IsNotNull(result);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Messages.Tests/Queries/Handlers/GetCustomerByIdQueryHandlerTests.cs b/src/Tests/Grand.Business.Messages.Tests/Queries/Handlers/GetCustomerByIdQueryHandlerTests.csnew file mode 100644index 000000000..9d9df1466--- /dev/null+++ b/src/Tests/Grand.Business.Messages.Tests/Queries/Handlers/GetCustomerByIdQueryHandlerTests.cs@@ -0,0 +1,36 @@+using Grand.Data.Tests.MongoDb;+using Grand.Domain.Customers;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Business.Messages.Queries.Handlers.Tests+{+ [TestClass()]+ public class GetCustomerByIdQueryHandlerTests+ {+ private GetCustomerByIdQueryHandler handler;++ [TestInitialize()]+ public void Init()+ {+ var _repository = new MongoDBRepositoryTest<Customer>();+ _repository.Insert(new Customer() { Id = "1" });+ _repository.Insert(new Customer());+ _repository.Insert(new Customer());+ _repository.Insert(new Customer());+ handler = new GetCustomerByIdQueryHandler(_repository);+ }++ [TestMethod()]+ public async Task HandleTest()+ {+ //Assert+ var customerQuery = new Core.Queries.Messages.GetCustomerByIdQuery();+ customerQuery.Id = "1";+ //Act+ var result = await handler.Handle(customerQuery, CancellationToken.None);++ //Assert+ Assert.IsNotNull(result);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Messages.Tests/Queries/Handlers/GetProductByIdQueryHandlerTests.cs b/src/Tests/Grand.Business.Messages.Tests/Queries/Handlers/GetProductByIdQueryHandlerTests.csnew file mode 100644index 000000000..55c36e05e--- /dev/null+++ b/src/Tests/Grand.Business.Messages.Tests/Queries/Handlers/GetProductByIdQueryHandlerTests.cs@@ -0,0 +1,42 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Grand.Business.Messages.Queries.Handlers;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;+using Grand.Domain.Catalog;+using Grand.Domain.Data;+using Moq;+using Grand.Data.Tests.MongoDb;++namespace Grand.Business.Messages.Queries.Handlers.Tests+{+ [TestClass()]+ public class GetProductByIdQueryHandlerTests+ {+ private GetProductByIdQueryHandler handler;++ [TestInitialize()]+ public void Init()+ {+ var _repository = new MongoDBRepositoryTest<Product>();+ _repository.Insert(new Product() { Id = "1" });+ _repository.Insert(new Product());+ _repository.Insert(new Product());+ _repository.Insert(new Product());++ handler = new GetProductByIdQueryHandler(_repository);+ }++ [TestMethod()]+ public async Task HandleTest()+ {+ //Act+ var result = await handler.Handle(new Core.Queries.Messages.GetProductByIdQuery() { Id = "1" }, CancellationToken.None);+ //Assert+ Assert.IsNotNull(result);+ }+ }++}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Messages.Tests/Queries/Handlers/GetVendorByIdQueryHandlerTests.cs b/src/Tests/Grand.Business.Messages.Tests/Queries/Handlers/GetVendorByIdQueryHandlerTests.csnew file mode 100644index 000000000..abb73e693--- /dev/null+++ b/src/Tests/Grand.Business.Messages.Tests/Queries/Handlers/GetVendorByIdQueryHandlerTests.cs@@ -0,0 +1,31 @@+using Grand.Data.Tests.MongoDb;+using Grand.Domain.Data;+using Grand.Domain.Vendors;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Business.Messages.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.Messages.GetVendorByIdQuery() { Id = "1" }, CancellationToken.None);+ //Arrange+ Assert.IsNotNull(result);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Messages.Tests/Services/EmailSenderTests.cs b/src/Tests/Grand.Business.Messages.Tests/Services/EmailSenderTests.csnew file mode 100644index 000000000..9b0742fbf--- /dev/null+++ b/src/Tests/Grand.Business.Messages.Tests/Services/EmailSenderTests.cs@@ -0,0 +1,31 @@+using Grand.Business.Core.Interfaces.Messages;+using Grand.Business.Core.Interfaces.Storage;+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Moq;+using System.Net.Sockets;++namespace Grand.Business.Messages.Services.Tests+{+ [TestClass()]+ public class EmailSenderTests+ {+ private EmailSender _sender;+ private Mock<IDownloadService> _downloadService;+ private Mock<IMimeMappingService> _mimeMappingService;++ [TestInitialize()]+ public void Init()+ {+ _downloadService = new Mock<IDownloadService>();+ _mimeMappingService = new Mock<IMimeMappingService>();++ _sender = new EmailSender(_downloadService.Object, _mimeMappingService.Object);+ }++ [TestMethod()]+ public void SendEmailTest()+ {+ Assert.ThrowsExceptionAsync<SocketException>(async () => await _sender.SendEmail(new Domain.Messages.EmailAccount() { Host = "[email protected]" }, "subject", "body", "[email protected]", "admin store", "[email protected]", "Customer name"));+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Messages.Tests/Services/MessageTokenProviderTests.cs b/src/Tests/Grand.Business.Messages.Tests/Services/MessageTokenProviderTests.csnew file mode 100644index 000000000..3810ecbab--- /dev/null+++ b/src/Tests/Grand.Business.Messages.Tests/Services/MessageTokenProviderTests.cs@@ -0,0 +1,35 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Grand.Business.Messages.Services;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;++namespace Grand.Business.Messages.Services.Tests+{+ [TestClass()]+ public class MessageTokenProviderTests+ {+ private MessageTokenProvider _provider;++ [TestInitialize()]+ public void Init()+ {+ _provider = new MessageTokenProvider();+ }++ [TestMethod()]+ public void GetListOfAllowedTokensTest()+ {+ var tokens = _provider.GetListOfAllowedTokens();+ Assert.IsTrue(tokens.Any());+ }+ [TestMethod()]+ public void GetListOfCampaignAllowedTokensTest()+ {+ var tokens = _provider.GetListOfCampaignAllowedTokens();+ Assert.IsTrue(tokens.Any());+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Messages.Tests/Services/QueuedEmailServiceTests.cs b/src/Tests/Grand.Business.Messages.Tests/Services/QueuedEmailServiceTests.csindex 03d7dbf6d..75594901a 100644--- a/src/Tests/Grand.Business.Messages.Tests/Services/QueuedEmailServiceTests.cs+++ b/src/Tests/Grand.Business.Messages.Tests/Services/QueuedEmailServiceTests.cs@@ -23,7 +23,13 @@ namespace Grand.Business.Messages.Tests.Services_service = new QueuedEmailService(_repository.Object, _mediatorMock.Object);}+ [TestMethod()]+ public async Task GetQueuedEmailByIdTest()+ {+ await _service.GetQueuedEmailById("1");+ _repository.Verify(c => c.GetByIdAsync(It.IsAny<string>()), Times.Once);+ }[TestMethod()]public async Task InsertQueuedEmail_ValidArgument_InvokeExpectedMethods(){@@ -60,7 +66,18 @@ namespace Grand.Business.Messages.Tests.Services_repository.Verify(c => c.DeleteAsync(It.IsAny<QueuedEmail>()), Times.Once);_mediatorMock.Verify(c => c.Publish(It.IsAny<EntityDeleted<QueuedEmail>>(), default), Times.Once);}-+ [TestMethod()]+ public async Task DeleteCustomerEmail_ValidArgument_InvokeExpectedMethods()+ {+ await _service.DeleteCustomerEmail("[email protected]");+ _repository.Verify(c => c.DeleteAsync(It.IsAny<IEnumerable<QueuedEmail>>()), Times.Once);+ }+ [TestMethod()]+ public async Task DeleteAllEmails_ValidArgument_InvokeExpectedMethods()+ {+ await _service.DeleteAllEmails();+ _repository.Verify(c => c.ClearAsync(), Times.Once);+ }[TestMethod]public void DeleteQueuedEmai_NullArguemnt_ThrowException(){diff --git a/src/Tests/Grand.Business.Messages.Tests/Startup/StartupApplicationTests.cs b/src/Tests/Grand.Business.Messages.Tests/Startup/StartupApplicationTests.csnew file mode 100644index 000000000..361725035--- /dev/null+++ b/src/Tests/Grand.Business.Messages.Tests/Startup/StartupApplicationTests.cs@@ -0,0 +1,31 @@+using Microsoft.Extensions.Configuration;+using Microsoft.Extensions.DependencyInjection;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Business.Messages.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 filediff --git a/src/Tests/Grand.Business.Messages.Tests/Utilities/TokenTests.cs b/src/Tests/Grand.Business.Messages.Tests/Utilities/TokenTests.csnew file mode 100644index 000000000..dabc3d243--- /dev/null+++ b/src/Tests/Grand.Business.Messages.Tests/Utilities/TokenTests.cs@@ -0,0 +1,32 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Business.Messages.Utilities.Tests+{+ [TestClass()]+ public class TokenTests+ {+ private Token _token;+ [TestInitialize]+ public void Init()+ {+ _token = new Token("key", "value");+ }+ [TestMethod()]+ public void TokenTest_key()+ {+ Assert.IsTrue("key" == _token.Key);+ }++ [TestMethod()]+ public void TokenTest_value()+ {+ Assert.IsTrue("value" == _token.Value);+ }++ [TestMethod()]+ public void ToStringTest()+ {+ Assert.IsTrue("key: value" == _token.ToString());+ }+ }+}\ No newline at end of file