Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added unit tests for shipping free module - FreeShippingServiceProvider #1080

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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<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);

hishamco marked this conversation as resolved.
Show resolved Hide resolved
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);

hishamco marked this conversation as resolved.
Show resolved Hide resolved
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,34 @@
<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>

<ItemGroup>
<Folder Include="Services\" />
hishamco marked this conversation as resolved.
Show resolved Hide resolved
</ItemGroup>

</Project>
Loading