From d5ce8a098db538823b13343911f8609153cba0c4 Mon Sep 17 00:00:00 2001 From: "Yada.ArunKumar" Date: Wed, 10 Jan 2024 07:37:12 +0000 Subject: [PATCH 1/3] added tests for SimplCommerce.Module.ShippingFree - FreeShippingServiceProvider --- SimplCommerce.sln | 15 ++++ .../FreeShippingServiceProviderTests.cs | 73 +++++++++++++++++++ ...lCommerce.Module.ShippingFree.Tests.csproj | 34 +++++++++ 3 files changed, 122 insertions(+) create mode 100644 test/SimplCommerce.Module.ShippingFree.Tests/Services/FreeShippingServiceProviderTests.cs create mode 100644 test/SimplCommerce.Module.ShippingFree.Tests/SimplCommerce.Module.ShippingFree.Tests.csproj diff --git a/SimplCommerce.sln b/SimplCommerce.sln index 2c5362143..658e554ae 100644 --- a/SimplCommerce.sln +++ b/SimplCommerce.sln @@ -136,6 +136,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimplCommerce.Module.Paymen EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimplCommerce.Module.Checkouts", "src\Modules\SimplCommerce.Module.Checkouts\SimplCommerce.Module.Checkouts.csproj", "{4473538D-2BFA-4C53-B642-0D0DC4F16863}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplCommerce.Module.ShippingFree.Tests", "test\SimplCommerce.Module.ShippingFree.Tests\SimplCommerce.Module.ShippingFree.Tests.csproj", "{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -710,6 +712,18 @@ Global {4473538D-2BFA-4C53-B642-0D0DC4F16863}.Release|x64.Build.0 = Release|Any CPU {4473538D-2BFA-4C53-B642-0D0DC4F16863}.Release|x86.ActiveCfg = Release|Any CPU {4473538D-2BFA-4C53-B642-0D0DC4F16863}.Release|x86.Build.0 = Release|Any CPU + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|x64.ActiveCfg = Debug|Any CPU + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|x64.Build.0 = Debug|Any CPU + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|x86.ActiveCfg = Debug|Any CPU + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|x86.Build.0 = Debug|Any CPU + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|Any CPU.Build.0 = Release|Any CPU + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|x64.ActiveCfg = Release|Any CPU + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|x64.Build.0 = Release|Any CPU + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|x86.ActiveCfg = Release|Any CPU + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -765,6 +779,7 @@ Global {14586564-62CC-4117-AC1B-858ED53C2D6C} = {7EFA2FA7-32DD-4047-B021-50E77A83D714} {E30CF10F-FABF-4917-8BEB-CB81E4CE2C92} = {7EFA2FA7-32DD-4047-B021-50E77A83D714} {4473538D-2BFA-4C53-B642-0D0DC4F16863} = {7EFA2FA7-32DD-4047-B021-50E77A83D714} + {16BB6B44-3300-4C22-A37B-D9CD7A4EA300} = {D9FD9ABA-AE5E-4427-AA6B-6285BE2E212D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B9D0D8F0-1AB9-44DD-839F-ED8CEE7DDB10} diff --git a/test/SimplCommerce.Module.ShippingFree.Tests/Services/FreeShippingServiceProviderTests.cs b/test/SimplCommerce.Module.ShippingFree.Tests/Services/FreeShippingServiceProviderTests.cs new file mode 100644 index 000000000..f85436349 --- /dev/null +++ b/test/SimplCommerce.Module.ShippingFree.Tests/Services/FreeShippingServiceProviderTests.cs @@ -0,0 +1,73 @@ +using System.Threading.Tasks; +using Moq; +using Newtonsoft.Json; +using SimplCommerce.Module.Core.Services; +using SimplCommerce.Module.Shipping.Models; +using SimplCommerce.Module.ShippingFree.Models; +using SimplCommerce.Module.ShippingFree.Services; +using SimplCommerce.Module.ShippingPrices.Services; +using Xunit; + +namespace SimplCommerce.Module.ShippingFree.Tests.Services +{ + public class FreeShippingServiceProviderTests + { + [Fact] + public async Task GetShippingPrices_ShouldReturnFreeShipping() + { + // Arrange + var currencyServiceMock = new Mock(); + var freeShippingProvider = new ShippingProvider + { + AdditionalSettings = JsonConvert.SerializeObject(new FreeShippingSetting + { + MinimumOrderAmount = 50 // Adjust the value based on your requirement + }) + }; + var freeShippingServiceProvider = new FreeShippingServiceProvider(currencyServiceMock.Object); + + var request = new GetShippingPriceRequest + { + OrderAmount = 60 // Exceeds the MinimumOrderAmount + }; + + // Act + var response = await freeShippingServiceProvider.GetShippingPrices(request, freeShippingProvider); + + // Assert + Assert.True(response.IsSuccess); + Assert.Single(response.ApplicablePrices); + + var shippingPrice = response.ApplicablePrices[0]; + Assert.Equal("Free", shippingPrice.Name); + Assert.Equal(0, shippingPrice.Price); + } + + [Fact] + public async Task GetShippingPrices_ShouldNotReturnFreeShipping() + { + // Arrange + var currencyServiceMock = new Mock(); + var freeShippingProvider = new ShippingProvider + { + AdditionalSettings = JsonConvert.SerializeObject(new FreeShippingSetting + { + MinimumOrderAmount = 50 // Adjust the value based on your requirement + }) + }; + var freeShippingServiceProvider = new FreeShippingServiceProvider(currencyServiceMock.Object); + + var request = new GetShippingPriceRequest + { + OrderAmount = 40 // Below the MinimumOrderAmount + }; + + // Act + var response = await freeShippingServiceProvider.GetShippingPrices(request, freeShippingProvider); + + // Assert + Assert.True(response.IsSuccess); + Assert.Empty(response.ApplicablePrices); + } + } +} diff --git a/test/SimplCommerce.Module.ShippingFree.Tests/SimplCommerce.Module.ShippingFree.Tests.csproj b/test/SimplCommerce.Module.ShippingFree.Tests/SimplCommerce.Module.ShippingFree.Tests.csproj new file mode 100644 index 000000000..308a37497 --- /dev/null +++ b/test/SimplCommerce.Module.ShippingFree.Tests/SimplCommerce.Module.ShippingFree.Tests.csproj @@ -0,0 +1,34 @@ + + + + net8.0 + false + true + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + + + + + + From ce54f85f7c94d005da07090156d9144ce03e0b53 Mon Sep 17 00:00:00 2001 From: Arun kumar <49372861+Arunkumar0610@users.noreply.github.com> Date: Thu, 11 Jan 2024 10:09:18 +0530 Subject: [PATCH 2/3] Update SimplCommerce.Module.ShippingFree.Tests.csproj --- .../SimplCommerce.Module.ShippingFree.Tests.csproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/SimplCommerce.Module.ShippingFree.Tests/SimplCommerce.Module.ShippingFree.Tests.csproj b/test/SimplCommerce.Module.ShippingFree.Tests/SimplCommerce.Module.ShippingFree.Tests.csproj index 308a37497..0c5a006d1 100644 --- a/test/SimplCommerce.Module.ShippingFree.Tests/SimplCommerce.Module.ShippingFree.Tests.csproj +++ b/test/SimplCommerce.Module.ShippingFree.Tests/SimplCommerce.Module.ShippingFree.Tests.csproj @@ -27,8 +27,4 @@ - - - - From 1665229aff5d4c8501e1921c09e4176442edecb4 Mon Sep 17 00:00:00 2001 From: Arun kumar <49372861+Arunkumar0610@users.noreply.github.com> Date: Thu, 11 Jan 2024 10:10:16 +0530 Subject: [PATCH 3/3] Update FreeShippingServiceProviderTests.cs --- .../Services/FreeShippingServiceProviderTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/SimplCommerce.Module.ShippingFree.Tests/Services/FreeShippingServiceProviderTests.cs b/test/SimplCommerce.Module.ShippingFree.Tests/Services/FreeShippingServiceProviderTests.cs index f85436349..3f8ba7d28 100644 --- a/test/SimplCommerce.Module.ShippingFree.Tests/Services/FreeShippingServiceProviderTests.cs +++ b/test/SimplCommerce.Module.ShippingFree.Tests/Services/FreeShippingServiceProviderTests.cs @@ -25,7 +25,6 @@ public async Task GetShippingPrices_ShouldReturnFreeShipping() }) }; var freeShippingServiceProvider = new FreeShippingServiceProvider(currencyServiceMock.Object); - var request = new GetShippingPriceRequest { OrderAmount = 60 // Exceeds the MinimumOrderAmount @@ -56,7 +55,6 @@ public async Task GetShippingPrices_ShouldNotReturnFreeShipping() }) }; var freeShippingServiceProvider = new FreeShippingServiceProvider(currencyServiceMock.Object); - var request = new GetShippingPriceRequest { OrderAmount = 40 // Below the MinimumOrderAmount