Fix bug #263
This commit is contained in:
parent
eb4396e659
commit
3d552b3219
@ -72,8 +72,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
if (discount > existingOrderForProduct.GetCurrentDiscount())
|
if (discount > existingOrderForProduct.GetCurrentDiscount())
|
||||||
{
|
{
|
||||||
existingOrderForProduct.SetNewDiscount(discount);
|
existingOrderForProduct.SetNewDiscount(discount);
|
||||||
existingOrderForProduct.AddUnits(units);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
existingOrderForProduct.AddUnits(units);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -187,6 +188,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
{
|
{
|
||||||
throw new OrderingDomainException($"Not possible to change order status from {OrderStatus.Name} to {orderStatusToChange.Name}.");
|
throw new OrderingDomainException($"Not possible to change order status from {OrderStatus.Name} to {orderStatusToChange.Name}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public decimal GetTotal()
|
||||||
|
{
|
||||||
|
return _orderItems.Sum(o => o.GetUnits() * o.GetUnitPrice());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
return _units;
|
return _units;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public decimal GetUnitPrice()
|
||||||
|
{
|
||||||
|
return _unitPrice;
|
||||||
|
}
|
||||||
|
|
||||||
public string GetOrderItemProductName() => _productName;
|
public string GetOrderItemProductName() => _productName;
|
||||||
|
|
||||||
public void SetNewDiscount(decimal discount)
|
public void SetNewDiscount(decimal discount)
|
||||||
|
47
test/Services/UnitTest/Ordering/Builders.cs
Normal file
47
test/Services/UnitTest/Ordering/Builders.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||||
|
|
||||||
|
namespace UnitTest.Ordering
|
||||||
|
{
|
||||||
|
public class AddressBuilder
|
||||||
|
{
|
||||||
|
public Address Build()
|
||||||
|
{
|
||||||
|
return new Address("street", "city", "state", "country", "zipcode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OrderBuilder
|
||||||
|
{
|
||||||
|
private readonly Order order;
|
||||||
|
|
||||||
|
public OrderBuilder(Address address)
|
||||||
|
{
|
||||||
|
order = new Order(
|
||||||
|
"userId",
|
||||||
|
address,
|
||||||
|
cardTypeId:5,
|
||||||
|
cardNumber:"12",
|
||||||
|
cardSecurityNumber:"123",
|
||||||
|
cardHolderName:"name",
|
||||||
|
cardExpiration:DateTime.UtcNow);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderBuilder AddOne(
|
||||||
|
int productId,
|
||||||
|
string productName,
|
||||||
|
decimal unitPrice,
|
||||||
|
decimal discount,
|
||||||
|
string pictureUrl,
|
||||||
|
int units = 1)
|
||||||
|
{
|
||||||
|
order.AddOrderItem(productId, productName, unitPrice, discount, pictureUrl, units);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Order Build()
|
||||||
|
{
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,8 @@
|
|||||||
using Ordering.Domain.Events;
|
using Ordering.Domain.Events;
|
||||||
using Ordering.Domain.Exceptions;
|
using Ordering.Domain.Exceptions;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using UnitTest.Ordering;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
public class OrderAggregateTest
|
public class OrderAggregateTest
|
||||||
@ -93,6 +95,18 @@ public class OrderAggregateTest
|
|||||||
Assert.Throws<OrderingDomainException>(() => fakeOrderItem.AddUnits(-1));
|
Assert.Throws<OrderingDomainException>(() => fakeOrderItem.AddUnits(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void when_add_two_times_on_the_same_item_then_the_total_of_order_should_be_the_sum_of_the_two_items()
|
||||||
|
{
|
||||||
|
var address = new AddressBuilder().Build();
|
||||||
|
var order = new OrderBuilder(address)
|
||||||
|
.AddOne(1,"cup",10.0m,0,string.Empty)
|
||||||
|
.AddOne(1,"cup",10.0m,0,string.Empty)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
Assert.Equal(20.0m, order.GetTotal());
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Add_new_Order_raises_new_event()
|
public void Add_new_Order_raises_new_event()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user