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 Grand.Infrastructure.Tests
support9ae5665d9fd7
diff --git a/GrandNode.sln b/GrandNode.slnindex 7d16149c1..6f62b3316 100644--- a/GrandNode.sln+++ b/GrandNode.sln@@ -116,9 +116,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Data.Tests", "src\TesEndProjectProject("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Business.Core", "src\Business\Grand.Business.Core\Grand.Business.Core.csproj", "{1C0C8328-3B03-4D43-8309-7F0F52A0475F}"EndProject-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grand.SharedKernel.Tests", "src\Tests\Grand.SharedKernel.Tests\Grand.SharedKernel.Tests.csproj", "{1301BA1F-F852-4A2A-8A01-2BE2E3C992E2}"+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.SharedKernel.Tests", "src\Tests\Grand.SharedKernel.Tests\Grand.SharedKernel.Tests.csproj", "{1301BA1F-F852-4A2A-8A01-2BE2E3C992E2}"EndProject-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grand.Domain.Tests", "src\Tests\Grand.Domain.Tests\Grand.Domain.Tests.csproj", "{EEEE2033-07A4-42BB-AFEE-3F83E0BD3044}"+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Domain.Tests", "src\Tests\Grand.Domain.Tests\Grand.Domain.Tests.csproj", "{EEEE2033-07A4-42BB-AFEE-3F83E0BD3044}"+EndProject+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grand.Infrastructure.Tests", "src\Tests\Grand.Infrastructure.Tests\Grand.Infrastructure.Tests.csproj", "{50049A49-D27E-4200-9875-F6C486FD608D}"EndProjectGlobalGlobalSection(SolutionConfigurationPlatforms) = preSolution@@ -313,6 +315,10 @@ Global{EEEE2033-07A4-42BB-AFEE-3F83E0BD3044}.Debug|Any CPU.Build.0 = Debug|Any CPU{EEEE2033-07A4-42BB-AFEE-3F83E0BD3044}.Release|Any CPU.ActiveCfg = Release|Any CPU{EEEE2033-07A4-42BB-AFEE-3F83E0BD3044}.Release|Any CPU.Build.0 = Release|Any CPU+ {50049A49-D27E-4200-9875-F6C486FD608D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU+ {50049A49-D27E-4200-9875-F6C486FD608D}.Debug|Any CPU.Build.0 = Debug|Any CPU+ {50049A49-D27E-4200-9875-F6C486FD608D}.Release|Any CPU.ActiveCfg = Release|Any CPU+ {50049A49-D27E-4200-9875-F6C486FD608D}.Release|Any CPU.Build.0 = Release|Any CPUEndGlobalSectionGlobalSection(SolutionProperties) = preSolutionHideSolutionNode = FALSE@@ -364,6 +370,7 @@ Global{1C0C8328-3B03-4D43-8309-7F0F52A0475F} = {6EAC4D2C-4A86-4C9F-8427-CB374F69F08C}{1301BA1F-F852-4A2A-8A01-2BE2E3C992E2} = {6360202A-F931-4BBD-ADBD-C9A628EE59F8}{EEEE2033-07A4-42BB-AFEE-3F83E0BD3044} = {6360202A-F931-4BBD-ADBD-C9A628EE59F8}+ {50049A49-D27E-4200-9875-F6C486FD608D} = {6360202A-F931-4BBD-ADBD-C9A628EE59F8}EndGlobalSectionGlobalSection(ExtensibilityGlobals) = postSolutionSolutionGuid = {88B478F4-FD3B-4C24-9E84-4FAAF0254397}diff --git a/src/Tests/Grand.Infrastructure.Tests/Caching/MemoryCacheBaseTests.cs b/src/Tests/Grand.Infrastructure.Tests/Caching/MemoryCacheBaseTests.csnew file mode 100644index 000000000..55673fc38--- /dev/null+++ b/src/Tests/Grand.Infrastructure.Tests/Caching/MemoryCacheBaseTests.cs@@ -0,0 +1,100 @@+using Grand.SharedKernel.Extensions;+using MediatR;+using Microsoft.Extensions.Caching.Memory;+using Microsoft.Extensions.DependencyInjection;+using Microsoft.VisualStudio.TestTools.UnitTesting;+using Moq;++namespace Grand.Infrastructure.Caching.Tests+{+ [TestClass()]+ public class MemoryCacheBaseTests+ {+ private Mock<IMediator> _mediatorMock;+ private MemoryCacheBase _service;+ private IMemoryCache _memoryCache;++ [TestInitialize]+ public void Init()+ {+ CommonHelper.CacheTimeMinutes = 1;++ var services = new ServiceCollection();+ services.AddMemoryCache();+ var serviceProvider = services.BuildServiceProvider();++ _memoryCache = serviceProvider.GetService<IMemoryCache>();+ _mediatorMock = new Mock<IMediator>();+ _service = new MemoryCacheBase(_memoryCache, _mediatorMock.Object);+ }++ [TestMethod()]+ public async Task GetAsyncTest()+ {+ CommonHelper.CacheTimeMinutes = 10;+ var result = await _service.GetAsync<string>("key", () => { return Task.FromResult("test"); });+ Assert.AreEqual(result, "test");+ }++ [TestMethod()]+ public async Task GetAsyncTest_CacheTimeMinutes()+ {+ var result = await _service.GetAsync<string>("key", () => { return Task.FromResult("test"); }, 1);+ Assert.AreEqual(result, "test");+ }++ [TestMethod()]+ public void GetTest()+ {+ var result = _service.Get<string>("key", () => { return "test"; });+ Assert.AreEqual(result, "test");+ }++ [TestMethod()]+ public void GetTest_CacheTimeMinutes()+ {+ var result = _service.Get<string>("key", () => { return "test"; }, 1);+ Assert.AreEqual(result, "test");+ }++ [TestMethod()]+ public async Task RemoveAsyncTest_IsNull()+ {+ _service.Get<string>("key", () => { return "test"; }, 1);+ await _service.RemoveAsync("key");+ var result = _memoryCache.Get("key");+ Assert.IsNull(result);+ }++ [TestMethod()]+ public async Task RemoveAsyncTest_NotNull()+ {+ _service.Get<string>("key", () => { return "test"; }, 1);+ await _service.RemoveAsync("key1");+ var result = _memoryCache.Get("key");+ Assert.IsNotNull(result);+ }++ [TestMethod()]+ public async Task RemoveByPrefixTest()+ {+ _service.Get<string>("key1", () => { return "test"; }, 1);+ _service.Get<string>("key2", () => { return "test"; }, 1);+ _service.Get<string>("test", () => { return "test"; }, 1);+ await _service.RemoveByPrefix("key");+ var result = _memoryCache.Get("key1");+ Assert.IsNull(result);+ }++ [TestMethod()]+ public async Task ClearTest()+ {+ _service.Get<string>("key1", () => { return "test"; }, 1);+ _service.Get<string>("key2", () => { return "test"; }, 1);+ _service.Get<string>("test", () => { return "test"; }, 1);+ await _service.Clear();+ var result = _memoryCache.Get("key1");+ Assert.IsNull(result);+ }+ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Infrastructure.Tests/Extensions/CommonExtensionsTests.cs b/src/Tests/Grand.Infrastructure.Tests/Extensions/CommonExtensionsTests.csnew file mode 100644index 000000000..d197d4e31--- /dev/null+++ b/src/Tests/Grand.Infrastructure.Tests/Extensions/CommonExtensionsTests.cs@@ -0,0 +1,48 @@+using Grand.Domain.Common;+using Grand.Infrastructure.Extensions;+using Microsoft.VisualStudio.TestTools.UnitTesting;++namespace Grand.Infrastructure.Extensions.Tests+{+ [TestClass()]+ public class CommonExtensionsTests+ {+ [TestMethod()]+ public void ModifyQueryStringTest_url_withoutparam()+ {+ var url = new Uri("http://google.com");+ var param = "param";+ var value = "value";+ var query = CommonExtensions.ModifyQueryString(url.ToString(), param, value);+ Assert.AreEqual(query, $"http://google.com/?{param}={value}");+ }+ [TestMethod()]+ public void ModifyQueryStringTest_url_with1param()+ {+ var url = new Uri("http://google.com?param=aaa");+ var param = "param";+ var value = "value";+ var query = CommonExtensions.ModifyQueryString(url.ToString(), param, value);+ Assert.AreEqual(query, $"http://google.com/?{param}={value}");+ }+ [TestMethod()]+ public void ModifyQueryStringTest_url_with2params()+ {+ var url = new Uri("http://google.com?param=bbb¶m2=cccc");+ var param = "param";+ var value = "value";+ var query = CommonExtensions.ModifyQueryString(url.ToString(), param, value);+ Assert.AreEqual(query, $"http://google.com/?param2=cccc&{param}={value}");+ }+ [TestMethod()]+ public void ModifyQueryStringTest_url_with3params()+ {+ var url = new Uri("http://google.com?vvv=azaz¶m=bbb¶m2=cccc");+ var param = "param";+ var value = "value";+ var query = CommonExtensions.ModifyQueryString(url.ToString(), param, value);+ Assert.AreEqual(query, $"http://google.com/?vvv=azaz¶m2=cccc&{param}={value}");+ }++ }+}\ No newline at end of filediff --git a/src/Tests/Grand.Infrastructure.Tests/Grand.Infrastructure.Tests.csproj b/src/Tests/Grand.Infrastructure.Tests/Grand.Infrastructure.Tests.csprojnew file mode 100644index 000000000..13dfa3620--- /dev/null+++ b/src/Tests/Grand.Infrastructure.Tests/Grand.Infrastructure.Tests.csproj@@ -0,0 +1,23 @@+<Project Sdk="Microsoft.NET.Sdk">+ <Import Project="..\..\Build\Grand.Common.props" />+ <PropertyGroup>+ <IsPackable>false</IsPackable>+ </PropertyGroup>+ <ItemGroup>+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />+ <PackageReference Include="Moq" Version="4.18.2" />+ <PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />+ <PackageReference Include="MSTest.TestFramework" Version="2.2.10" />+ <PackageReference Include="coverlet.collector" Version="3.1.2">+ <PrivateAssets>all</PrivateAssets>+ <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>+ </PackageReference>+ <PackageReference Include="NUnit" Version="3.13.3" />+ </ItemGroup>++ <ItemGroup>+ <ProjectReference Include="..\..\Core\Grand.Domain\Grand.Domain.csproj" />+ <ProjectReference Include="..\..\Core\Grand.Infrastructure\Grand.Infrastructure.csproj" />+ <ProjectReference Include="..\..\Core\Grand.SharedKernel\Grand.SharedKernel.csproj" />+ </ItemGroup>+</Project>