Browse Source

Fix UTs of the Orders module

pull/162/head
gdlcf88 4 years ago
parent
commit
3b1e2e3cbb
  1. 19
      modules/EasyAbp.EShop.Orders/test/EasyAbp.EShop.Orders.Application.Tests/Orders/OrderAppServiceTests.cs
  2. 6
      modules/EasyAbp.EShop.Orders/test/EasyAbp.EShop.Orders.Application.Tests/Orders/TestOrderLinePriceOverrider.cs
  3. 18
      modules/EasyAbp.EShop.Orders/test/EasyAbp.EShop.Orders.TestBase/OrderTestData.cs

19
modules/EasyAbp.EShop.Orders/test/EasyAbp.EShop.Orders.Application.Tests/Orders/OrderAppServiceTests.cs

@ -64,6 +64,17 @@ namespace EasyAbp.EShop.Orders.Orders
Price = 2m, Price = 2m,
Currency = "CNY", Currency = "CNY",
ProductDetailId = OrderTestData.ProductDetail2Id ProductDetailId = OrderTestData.ProductDetail2Id
},
new ProductSkuDto
{
Id = OrderTestData.ProductSku3Id,
Name = "My SKU 3",
OrderMinQuantity = 0,
OrderMaxQuantity = 100,
AttributeOptionIds = new List<Guid>(),
Price = 3m,
Currency = "CNY",
ProductDetailId = OrderTestData.ProductDetail2Id
} }
}, },
InventoryStrategy = InventoryStrategy.NoNeed, InventoryStrategy = InventoryStrategy.NoNeed,
@ -481,7 +492,7 @@ namespace EasyAbp.EShop.Orders.Orders
new() new()
{ {
ProductId = OrderTestData.Product1Id, ProductId = OrderTestData.Product1Id,
ProductSkuId = OrderTestData.ProductSku2Id, ProductSkuId = OrderTestData.ProductSku3Id,
Quantity = 2 Quantity = 2
} }
} }
@ -490,11 +501,11 @@ namespace EasyAbp.EShop.Orders.Orders
await WithUnitOfWorkAsync(async () => await WithUnitOfWorkAsync(async () =>
{ {
var order = await _orderAppService.CreateAsync(createOrderDto); var order = await _orderAppService.CreateAsync(createOrderDto);
var orderLine = order.OrderLines.Find(x => x.ProductSkuId == OrderTestData.ProductSku2Id); var orderLine = order.OrderLines.Find(x => x.ProductSkuId == OrderTestData.ProductSku3Id);
order.ProductTotalPrice.ShouldBe(10 * 1m + 2 * TestOrderLinePriceOverrider.Sku2UnitPrice); order.ProductTotalPrice.ShouldBe(10 * 1m + 2 * TestOrderLinePriceOverrider.Sku3UnitPrice);
orderLine.ShouldNotBeNull(); orderLine.ShouldNotBeNull();
orderLine.UnitPrice.ShouldBe(TestOrderLinePriceOverrider.Sku2UnitPrice); orderLine.UnitPrice.ShouldBe(TestOrderLinePriceOverrider.Sku3UnitPrice);
orderLine.TotalPrice.ShouldBe(orderLine.Quantity * orderLine.UnitPrice); orderLine.TotalPrice.ShouldBe(orderLine.Quantity * orderLine.UnitPrice);
}); });
} }

6
modules/EasyAbp.EShop.Orders/test/EasyAbp.EShop.Orders.Application.Tests/Orders/TestOrderLinePriceOverrider.cs

@ -7,14 +7,14 @@ namespace EasyAbp.EShop.Orders.Orders;
public class TestOrderLinePriceOverrider : IOrderLinePriceOverrider, ITransientDependency public class TestOrderLinePriceOverrider : IOrderLinePriceOverrider, ITransientDependency
{ {
public static decimal Sku2UnitPrice { get; set; } = 100m; public static decimal Sku3UnitPrice { get; set; } = 100m;
public async Task<decimal?> GetUnitPriceOrNullAsync(CreateOrderDto input, CreateOrderLineDto inputOrderLine, public async Task<decimal?> GetUnitPriceOrNullAsync(CreateOrderDto input, CreateOrderLineDto inputOrderLine,
ProductDto product, ProductSkuDto productSku) ProductDto product, ProductSkuDto productSku)
{ {
if (inputOrderLine.ProductSkuId == OrderTestData.ProductSku2Id) if (inputOrderLine.ProductSkuId == OrderTestData.ProductSku3Id)
{ {
return Sku2UnitPrice; return Sku3UnitPrice;
} }
return null; return null;

18
modules/EasyAbp.EShop.Orders/test/EasyAbp.EShop.Orders.TestBase/OrderTestData.cs

@ -6,25 +6,27 @@ namespace EasyAbp.EShop.Orders
public class OrderTestData public class OrderTestData
{ {
public static Guid Order1Id { get; } = Guid.NewGuid(); public static Guid Order1Id { get; } = Guid.NewGuid();
public static Guid OrderLine1Id { get; } = Guid.NewGuid(); public static Guid OrderLine1Id { get; } = Guid.NewGuid();
public static Guid Payment1Id { get; } = Guid.NewGuid(); public static Guid Payment1Id { get; } = Guid.NewGuid();
public static Guid Store1Id { get; } = Guid.NewGuid(); public static Guid Store1Id { get; } = Guid.NewGuid();
public static Guid Product1Id { get; } = Guid.NewGuid(); public static Guid Product1Id { get; } = Guid.NewGuid();
public static Guid ProductSku1Id { get; } = Guid.NewGuid(); public static Guid ProductSku1Id { get; } = Guid.NewGuid();
public static Guid ProductSku2Id { get; } = Guid.NewGuid(); public static Guid ProductSku2Id { get; } = Guid.NewGuid();
public static Guid ProductSku3Id { get; } = Guid.NewGuid();
public static Guid ProductDetail1Id { get; } = Guid.NewGuid(); public static Guid ProductDetail1Id { get; } = Guid.NewGuid();
public static Guid ProductDetail2Id { get; } = Guid.NewGuid(); public static Guid ProductDetail2Id { get; } = Guid.NewGuid();
public static DateTime ProductLastModificationTime { get; } = DateTime.Today; public static DateTime ProductLastModificationTime { get; } = DateTime.Today;
public static DateTime ProductDetailLastModificationTime { get; } = DateTime.Today; public static DateTime ProductDetailLastModificationTime { get; } = DateTime.Today;
} }
} }
Loading…
Cancel
Save