Skip to content

Commit d5ce8a0

Browse files
committed
added tests for SimplCommerce.Module.ShippingFree - FreeShippingServiceProvider
1 parent 6a170ab commit d5ce8a0

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

SimplCommerce.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimplCommerce.Module.Paymen
136136
EndProject
137137
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimplCommerce.Module.Checkouts", "src\Modules\SimplCommerce.Module.Checkouts\SimplCommerce.Module.Checkouts.csproj", "{4473538D-2BFA-4C53-B642-0D0DC4F16863}"
138138
EndProject
139+
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}"
140+
EndProject
139141
Global
140142
GlobalSection(SolutionConfigurationPlatforms) = preSolution
141143
Debug|Any CPU = Debug|Any CPU
@@ -710,6 +712,18 @@ Global
710712
{4473538D-2BFA-4C53-B642-0D0DC4F16863}.Release|x64.Build.0 = Release|Any CPU
711713
{4473538D-2BFA-4C53-B642-0D0DC4F16863}.Release|x86.ActiveCfg = Release|Any CPU
712714
{4473538D-2BFA-4C53-B642-0D0DC4F16863}.Release|x86.Build.0 = Release|Any CPU
715+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
716+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|Any CPU.Build.0 = Debug|Any CPU
717+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|x64.ActiveCfg = Debug|Any CPU
718+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|x64.Build.0 = Debug|Any CPU
719+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|x86.ActiveCfg = Debug|Any CPU
720+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Debug|x86.Build.0 = Debug|Any CPU
721+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|Any CPU.ActiveCfg = Release|Any CPU
722+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|Any CPU.Build.0 = Release|Any CPU
723+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|x64.ActiveCfg = Release|Any CPU
724+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|x64.Build.0 = Release|Any CPU
725+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|x86.ActiveCfg = Release|Any CPU
726+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300}.Release|x86.Build.0 = Release|Any CPU
713727
EndGlobalSection
714728
GlobalSection(SolutionProperties) = preSolution
715729
HideSolutionNode = FALSE
@@ -765,6 +779,7 @@ Global
765779
{14586564-62CC-4117-AC1B-858ED53C2D6C} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
766780
{E30CF10F-FABF-4917-8BEB-CB81E4CE2C92} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
767781
{4473538D-2BFA-4C53-B642-0D0DC4F16863} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
782+
{16BB6B44-3300-4C22-A37B-D9CD7A4EA300} = {D9FD9ABA-AE5E-4427-AA6B-6285BE2E212D}
768783
EndGlobalSection
769784
GlobalSection(ExtensibilityGlobals) = postSolution
770785
SolutionGuid = {B9D0D8F0-1AB9-44DD-839F-ED8CEE7DDB10}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System.Threading.Tasks;
2+
using Moq;
3+
using Newtonsoft.Json;
4+
using SimplCommerce.Module.Core.Services;
5+
using SimplCommerce.Module.Shipping.Models;
6+
using SimplCommerce.Module.ShippingFree.Models;
7+
using SimplCommerce.Module.ShippingFree.Services;
8+
using SimplCommerce.Module.ShippingPrices.Services;
9+
using Xunit;
10+
11+
namespace SimplCommerce.Module.ShippingFree.Tests.Services
12+
{
13+
public class FreeShippingServiceProviderTests
14+
{
15+
[Fact]
16+
public async Task GetShippingPrices_ShouldReturnFreeShipping()
17+
{
18+
// Arrange
19+
var currencyServiceMock = new Mock<ICurrencyService>();
20+
var freeShippingProvider = new ShippingProvider
21+
{
22+
AdditionalSettings = JsonConvert.SerializeObject(new FreeShippingSetting
23+
{
24+
MinimumOrderAmount = 50 // Adjust the value based on your requirement
25+
})
26+
};
27+
var freeShippingServiceProvider = new FreeShippingServiceProvider(currencyServiceMock.Object);
28+
29+
var request = new GetShippingPriceRequest
30+
{
31+
OrderAmount = 60 // Exceeds the MinimumOrderAmount
32+
};
33+
34+
// Act
35+
var response = await freeShippingServiceProvider.GetShippingPrices(request, freeShippingProvider);
36+
37+
// Assert
38+
Assert.True(response.IsSuccess);
39+
Assert.Single(response.ApplicablePrices);
40+
41+
var shippingPrice = response.ApplicablePrices[0];
42+
Assert.Equal("Free", shippingPrice.Name);
43+
Assert.Equal(0, shippingPrice.Price);
44+
}
45+
46+
[Fact]
47+
public async Task GetShippingPrices_ShouldNotReturnFreeShipping()
48+
{
49+
// Arrange
50+
var currencyServiceMock = new Mock<ICurrencyService>();
51+
var freeShippingProvider = new ShippingProvider
52+
{
53+
AdditionalSettings = JsonConvert.SerializeObject(new FreeShippingSetting
54+
{
55+
MinimumOrderAmount = 50 // Adjust the value based on your requirement
56+
})
57+
};
58+
var freeShippingServiceProvider = new FreeShippingServiceProvider(currencyServiceMock.Object);
59+
60+
var request = new GetShippingPriceRequest
61+
{
62+
OrderAmount = 40 // Below the MinimumOrderAmount
63+
};
64+
65+
// Act
66+
var response = await freeShippingServiceProvider.GetShippingPrices(request, freeShippingProvider);
67+
68+
// Assert
69+
Assert.True(response.IsSuccess);
70+
Assert.Empty(response.ApplicablePrices);
71+
}
72+
}
73+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<IsPackable>false</IsPackable>
6+
<IsTestProject>true</IsTestProject>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
11+
<PackageReference Include="Moq" Version="4.20.69" />
12+
<PackageReference Include="xunit" Version="2.5.3" />
13+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
<PrivateAssets>all</PrivateAssets>
16+
</PackageReference>
17+
<PackageReference Include="coverlet.collector" Version="6.0.0">
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
<PrivateAssets>all</PrivateAssets>
20+
</PackageReference>
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<ProjectReference Include="..\..\src\Modules\SimplCommerce.Module.Core\SimplCommerce.Module.Core.csproj" />
25+
<ProjectReference Include="..\..\src\Modules\SimplCommerce.Module.ShippingFree\SimplCommerce.Module.ShippingFree.csproj" />
26+
<ProjectReference Include="..\..\src\Modules\SimplCommerce.Module.ShippingPrices\SimplCommerce.Module.ShippingPrices.csproj" />
27+
<ProjectReference Include="..\..\src\Modules\SimplCommerce.Module.Shipping\SimplCommerce.Module.Shipping.csproj" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<Folder Include="Services\" />
32+
</ItemGroup>
33+
34+
</Project>

0 commit comments

Comments
 (0)