-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit tests for shipping free module - FreeShippingServiceProvid…
…er (#1080)
- Loading branch information
1 parent
6a170ab
commit 1cc3cfe
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
test/SimplCommerce.Module.ShippingFree.Tests/Services/FreeShippingServiceProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
test/SimplCommerce.Module.ShippingFree.Tests/SimplCommerce.Module.ShippingFree.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |