-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit test: Order using coupons discount (#281)
- Loading branch information
1 parent
7a50178
commit eeedf08
Showing
8 changed files
with
229 additions
and
43 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
10 changes: 10 additions & 0 deletions
10
...pons/test/EasyAbp.EShop.Orders.Plugins.Coupons.Tests/EShopOrdersPluginsCouponsTestBase.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,10 @@ | ||
namespace EasyAbp.EShop.Plugins.Coupons | ||
{ | ||
/* Inherit from this class for your application layer tests. | ||
* See SampleAppService_Tests for example. | ||
*/ | ||
public abstract class EShopOrdersPluginsCouponsTestBase : CouponsTestBase<EShopOrdersPluginsCouponsTestModule> | ||
{ | ||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ns/test/EasyAbp.EShop.Orders.Plugins.Coupons.Tests/EShopOrdersPluginsCouponsTestModule.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,15 @@ | ||
using EasyAbp.EShop.Orders.Plugins.Coupons; | ||
using Volo.Abp.Modularity; | ||
|
||
namespace EasyAbp.EShop.Plugins.Coupons | ||
{ | ||
[DependsOn( | ||
typeof(EShopOrdersPluginsCouponsModule), | ||
typeof(CouponsApplicationTestModule), | ||
typeof(CouponsDomainTestModule) | ||
)] | ||
public class EShopOrdersPluginsCouponsTestModule : AbpModule | ||
{ | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...yAbp.EShop.Orders.Plugins.Coupons.Tests/EasyAbp.EShop.Orders.Plugins.Coupons.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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<RootNamespace>EasyAbp.EShop.Orders.Plugins.Coupons</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\modules\EasyAbp.EShop.Orders\test\EasyAbp.EShop.Orders.TestBase\EasyAbp.EShop.Orders.TestBase.csproj" /> | ||
<ProjectReference Include="..\..\src\EasyAbp.EShop.Orders.Plugins.Coupons\EasyAbp.EShop.Orders.Plugins.Coupons.csproj" /> | ||
<ProjectReference Include="..\EasyAbp.EShop.Plugins.Coupons.Application.Tests\EasyAbp.EShop.Plugins.Coupons.Application.Tests.csproj" /> | ||
<ProjectReference Include="..\EasyAbp.EShop.Plugins.Coupons.Domain.Tests\EasyAbp.EShop.Plugins.Coupons.Domain.Tests.csproj" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
3 changes: 3 additions & 0 deletions
3
plugins/Coupons/test/EasyAbp.EShop.Orders.Plugins.Coupons.Tests/FodyWeavers.xml
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,3 @@ | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<ConfigureAwait ContinueOnCapturedContext="false" /> | ||
</Weavers> |
30 changes: 30 additions & 0 deletions
30
plugins/Coupons/test/EasyAbp.EShop.Orders.Plugins.Coupons.Tests/FodyWeavers.xsd
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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> | ||
<xs:element name="Weavers"> | ||
<xs:complexType> | ||
<xs:all> | ||
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> | ||
<xs:complexType> | ||
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:all> | ||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="GenerateXsd" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:schema> |
106 changes: 106 additions & 0 deletions
106
...s/Coupons/test/EasyAbp.EShop.Orders.Plugins.Coupons.Tests/Orders/OrdersAppServiceTests.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,106 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using EasyAbp.EShop.Orders; | ||
using EasyAbp.EShop.Orders.Orders; | ||
using EasyAbp.EShop.Plugins.Coupons.CouponTemplates; | ||
using EasyAbp.EShop.Products.Products; | ||
using Shouldly; | ||
using Volo.Abp.Data; | ||
using Xunit; | ||
using static EasyAbp.EShop.Orders.Authorization.OrdersPermissions; | ||
|
||
namespace EasyAbp.EShop.Plugins.Coupons.Coupons | ||
{ | ||
public class OrdersAppServiceTests : EShopOrdersPluginsCouponsTestBase | ||
{ | ||
private readonly ICouponRepository _couponRepository; | ||
private readonly ICouponTemplateRepository _couponTemplateRepository; | ||
|
||
public OrdersAppServiceTests() | ||
{ | ||
_couponRepository = GetRequiredService<ICouponRepository>(); | ||
_couponTemplateRepository = GetRequiredService<ICouponTemplateRepository>(); | ||
} | ||
|
||
[Theory] | ||
//Meet the condition discount 1 time | ||
[InlineData(5, 2.3, 11, 2.3, CouponType.Normal)] | ||
[InlineData(5, 2.3, 10, 2.3, CouponType.Normal)] | ||
[InlineData(5, 2.3, 9, 2.3, CouponType.Normal)] | ||
//The discount condition is not met | ||
[InlineData(5, 2.3, 4, 0, CouponType.Normal)] | ||
|
||
//Meet the condition discount 2 time | ||
[InlineData(5, 2.3, 11, 4.6, CouponType.PerMeet)] | ||
[InlineData(5, 2.3, 10, 4.6, CouponType.PerMeet)] | ||
|
||
//Meet the condition discount 1 time | ||
[InlineData(5, 2.3, 9, 2.3, CouponType.PerMeet)] | ||
//The discount condition is not met | ||
[InlineData(5, 2.3, 4, 0, CouponType.PerMeet)] | ||
public async Task Should_CouponType_DiscountAmount(decimal couponConditionAmount, decimal couponDiscountAmount, decimal productSkuPrice,decimal discountAmount, CouponType couponType) | ||
{ | ||
var template = new CouponTemplate(Guid.NewGuid(), null, null, couponType, "UName", "DName", "Desc", null | ||
, DateTime.Now.AddDays(-1), DateTime.Now.AddDays(1), couponConditionAmount, couponDiscountAmount, "USD", true, null); | ||
var coupon = new Coupon(Guid.NewGuid(), null, template.Id, Guid.Parse("2e701e62-0953-4dd3-910b-dc6cc93ccb0d"), null, null); | ||
await WithUnitOfWorkAsync(async () => | ||
{ | ||
// Arrange | ||
await _couponTemplateRepository.InsertAsync(template); | ||
await _couponRepository.InsertAsync(coupon); | ||
}); | ||
Order order = null; | ||
var prodoctSku = new ProductSkuEto | ||
{ | ||
Id = OrderTestData.ProductSku2Id, | ||
AttributeOptionIds = new List<Guid>(), | ||
Price = productSkuPrice, | ||
Currency = "USD", | ||
OrderMinQuantity = 1, | ||
OrderMaxQuantity = 100, | ||
}; | ||
await WithUnitOfWorkAsync(async () => | ||
{ | ||
var orderGenerator = GetRequiredService<INewOrderGenerator>(); | ||
var createOrderLine = new CreateOrderLineInfoModel(OrderTestData.Product1Id, OrderTestData.ProductSku2Id, 1); | ||
var createOrderInfoModel = new CreateOrderInfoModel(OrderTestData.Store1Id, null, | ||
new List<CreateOrderLineInfoModel> | ||
{ | ||
createOrderLine | ||
} | ||
); | ||
createOrderInfoModel.SetProperty("CouponId", coupon.Id); | ||
var dic = new Dictionary<Guid, IProduct> | ||
{ | ||
{ | ||
OrderTestData.Product1Id, | ||
new ProductEto | ||
{ | ||
Id = OrderTestData.Product1Id, | ||
ProductSkus = new List<ProductSkuEto>{ prodoctSku } | ||
} | ||
} | ||
}; | ||
order = await orderGenerator.GenerateAsync(Guid.NewGuid(), createOrderInfoModel, dic, new Dictionary<Guid, DateTime>()); | ||
}); | ||
|
||
//assert | ||
|
||
var orderLine = order.OrderLines[0]; | ||
|
||
var orderLine2ExpectedPrice = 1 * prodoctSku.Price - discountAmount; | ||
order.ActualTotalPrice.ShouldBe(orderLine2ExpectedPrice); | ||
order.TotalDiscount.ShouldBe(order.TotalPrice - order.ActualTotalPrice); | ||
order.OrderDiscounts.Count.ShouldBe(1); | ||
var orderDiscount = order.OrderDiscounts.SingleOrDefault(x => x.OrderId == order.Id && x.OrderLineId == orderLine.Id && x.EffectGroup == "Coupon"); | ||
orderDiscount.DiscountedAmount.ShouldBe(discountAmount); | ||
} | ||
|
||
} | ||
} |