Skip to content

Commit

Permalink
added unit tests for shipping free module - FreeShippingServiceProvid…
Browse files Browse the repository at this point in the history
…er (#1080)
  • Loading branch information
Arunkumar0610 committed Jan 11, 2024
1 parent 6a170ab commit 1cc3cfe
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
15 changes: 15 additions & 0 deletions SimplCommerce.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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<ICurrencyService>();
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<ICurrencyService>();
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Modules\SimplCommerce.Module.Core\SimplCommerce.Module.Core.csproj" />
<ProjectReference Include="..\..\src\Modules\SimplCommerce.Module.ShippingFree\SimplCommerce.Module.ShippingFree.csproj" />
<ProjectReference Include="..\..\src\Modules\SimplCommerce.Module.ShippingPrices\SimplCommerce.Module.ShippingPrices.csproj" />
<ProjectReference Include="..\..\src\Modules\SimplCommerce.Module.Shipping\SimplCommerce.Module.Shipping.csproj" />
</ItemGroup>

</Project>

0 comments on commit 1cc3cfe

Please sign in to comment.