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
supportaf4c6b0e878b
diff --git a/src/Tests/Grand.Business.Authentication.Tests/Events/CustomerDeletedEventHandlerTests.cs b/src/Tests/Grand.Business.Authentication.Tests/Events/CustomerDeletedEventHandlerTests.csnew file mode 100644index 000000000..ce3884186--- /dev/null+++ b/src/Tests/Grand.Business.Authentication.Tests/Events/CustomerDeletedEventHandlerTests.cs@@ -0,0 +1,32 @@+using Grand.Data.Tests.MongoDb;+using Grand.Domain.Customers;+using Grand.Domain.Data;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Business.Authentication.Events.Tests+{+ [TestClass()]+ public class CustomerDeletedEventHandlerTests+ {+ private IRepository<ExternalAuthentication> _repository;+ private CustomerDeletedEventHandler _handler;++ [TestInitialize()]+ public void Init()+ {+ _repository = new MongoDBRepositoryTest<ExternalAuthentication>();+ _handler = new CustomerDeletedEventHandler(_repository);+ }++ [TestMethod()]+ public async Task HandleTest()+ {+ //Arrange+ await _repository.InsertAsync(new ExternalAuthentication() { CustomerId = "1" });+ //Act+ await _handler.Handle(new Infrastructure.Events.EntityDeleted<Customer>(new Customer() { Id = "1" }), CancellationToken.None);+ //Assert+ Assert.AreEqual(0, _repository.Table.Count());+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Authentication.Tests/Services/RefreshTokenServiceTests.cs b/src/Tests/Grand.Business.Authentication.Tests/Services/RefreshTokenServiceTests.csnew file mode 100644index 000000000..d60a6905e--- /dev/null+++ b/src/Tests/Grand.Business.Authentication.Tests/Services/RefreshTokenServiceTests.cs@@ -0,0 +1,70 @@+using Grand.Business.Core.Interfaces.Common.Directory;+using Grand.Domain;+using Grand.Domain.Security;+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Moq;++namespace Grand.Business.Authentication.Services.Tests+{+ [TestClass()]+ public class RefreshTokenServiceTests+ {+ private Mock<IUserFieldService> _userFieldServiceMock;+ private RefreshTokenService _service;++ [TestInitialize()]+ public void Init()+ {+ _userFieldServiceMock = new Mock<IUserFieldService>();+ _service = new RefreshTokenService(_userFieldServiceMock.Object, new Infrastructure.Configuration.FrontendAPIConfig() {+ SecretKey = "JWTRefreshTokenHIGHsecuredPasswordVVVp1OH7Xzyr",+ ValidIssuer = "http://localhost:4200",+ ValidAudience = "http://localhost:4200",+ ValidateLifetime = false,+ ValidateAudience = false,+ ValidateIssuerSigningKey = false,+ ExpiryInMinutes = 1440,+ RefreshTokenExpiryInMinutes = 1440,+ Enabled = true,+ ValidateIssuer = false,+ });+ }++ [TestMethod()]+ public void GenerateRefreshTokenTest()+ {+ //Act+ var result = _service.GenerateRefreshToken();+ //Assert+ Assert.IsNotNull(result);+ }++ [TestMethod()]+ public async Task SaveRefreshTokenToCustomerTest()+ {+ //Arrange+ _userFieldServiceMock.Setup(c => c.SaveField<string>(It.IsAny<BaseEntity>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()));+ var token = Guid.NewGuid().ToString();+ //Act+ var result = await _service.SaveRefreshTokenToCustomer(new Domain.Customers.Customer(), token);+ //Assert+ Assert.IsNotNull(result);+ Assert.AreEqual(token, result.Token);+ }++ [TestMethod()]+ public async Task GetCustomerRefreshTokenTest()+ {+ //Arrange+ _userFieldServiceMock.Setup(c => c.GetFieldsForEntity<RefreshToken>(It.IsAny<BaseEntity>(), It.IsAny<string>(), It.IsAny<string>()))+ .Returns(Task.FromResult(new RefreshToken() { Token = "123" }));+ //Act+ var result = await _service.GetCustomerRefreshToken(new Domain.Customers.Customer());+ //Assert+ Assert.IsNotNull(result);+ Assert.AreEqual("123", result.Token);+ }+++ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Authentication.Tests/Services/TwoFactorAuthenticationServiceTests.cs b/src/Tests/Grand.Business.Authentication.Tests/Services/TwoFactorAuthenticationServiceTests.csnew file mode 100644index 000000000..e9c99cd57--- /dev/null+++ b/src/Tests/Grand.Business.Authentication.Tests/Services/TwoFactorAuthenticationServiceTests.cs@@ -0,0 +1,69 @@+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Grand.Business.Authentication.Services;+using System;+using System.Collections.Generic;+using System.Linq;+using System.Text;+using System.Threading.Tasks;+using Grand.Infrastructure;+using Moq;+using Grand.Business.Core.Interfaces.Common.Directory;+using Google.Authenticator;+using Grand.Domain.Customers;++namespace Grand.Business.Authentication.Services.Tests+{+ [TestClass()]+ public class TwoFactorAuthenticationServiceTests+ {+ private Mock<IWorkContext> _workContextMock;+ private Mock<IUserFieldService> _userFieldServiceMock;+ private Mock<IServiceProvider> _serviceProviderMock;+ private TwoFactorAuthenticationService _twoFactorAuthenticationService;+ [TestInitialize()]+ public void Init()+ {+ _workContextMock = new Mock<IWorkContext>();+ _userFieldServiceMock = new Mock<IUserFieldService>();+ _serviceProviderMock = new Mock<IServiceProvider>();+ _twoFactorAuthenticationService = new TwoFactorAuthenticationService(_workContextMock.Object,+ _userFieldServiceMock.Object, _serviceProviderMock.Object);+ }++ [TestMethod()]+ public void AuthenticateTwoFactorTest()+ {+ Assert.Fail();+ }++ [TestMethod()]+ public async Task GenerateCodeSetupTest_AppVerification()+ {+ //Arrange+ _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "", Name = "test store" });+ _workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());+ //Act+ var result = await _twoFactorAuthenticationService.GenerateCodeSetup(Guid.NewGuid().ToString(),+ new Customer() { Email = "[email protected]" },+ new Domain.Localization.Language() { LanguageCulture = "en" }, TwoFactorAuthenticationType.AppVerification);+ //Assert+ Assert.IsTrue(result.CustomValues.ContainsKey("QrCodeImageUrl"));+ Assert.IsTrue(result.CustomValues.ContainsKey("ManualEntryQrCode"));+ }+ [TestMethod()]+ public async Task GenerateCodeSetupTest_Email()+ {+ //Arrange+ _workContextMock.Setup(c => c.CurrentStore).Returns(() => new Domain.Stores.Store() { Id = "", Name = "test store" });+ _workContextMock.Setup(c => c.CurrentCustomer).Returns(() => new Customer());+ //Act+ var result = await _twoFactorAuthenticationService.GenerateCodeSetup(Guid.NewGuid().ToString(),+ new Customer() { Email = "[email protected]" },+ new Domain.Localization.Language() { LanguageCulture = "en" }, TwoFactorAuthenticationType.EmailVerification);+ //Assert+ Assert.IsTrue(result.CustomValues.ContainsKey("Token"));+ }+++ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Business.Authentication.Tests/Startup/StartupApplicationTests.cs b/src/Tests/Grand.Business.Authentication.Tests/Startup/StartupApplicationTests.csnew file mode 100644index 000000000..b89daa1e0--- /dev/null+++ b/src/Tests/Grand.Business.Authentication.Tests/Startup/StartupApplicationTests.cs@@ -0,0 +1,32 @@+using Grand.Business.Authentication.Startup;+using Microsoft.Extensions.Configuration;+using Microsoft.Extensions.DependencyInjection;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Business.Authentication.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