Fixing the CreateOrderCommand so it is 100% immutable. It shouldn't have the AddOrderItem() method. In any case, it was not really used but in the tets, since this Command is serialized in the client side, then deserialized in the service level.
This commit is contained in:
parent
22cc8daa65
commit
69d7399eec
@ -61,20 +61,16 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands
|
||||
[DataMember]
|
||||
public IEnumerable<OrderItemDTO> OrderItems => _orderItems;
|
||||
|
||||
public void AddOrderItem(OrderItemDTO item)
|
||||
{
|
||||
_orderItems.Add(item);
|
||||
}
|
||||
|
||||
public CreateOrderCommand()
|
||||
{
|
||||
_orderItems = new List<OrderItemDTO>();
|
||||
}
|
||||
|
||||
public CreateOrderCommand(string city, string street, string state, string country, string zipcode,
|
||||
public CreateOrderCommand(List<OrderItemDTO> orderItems, string city, string street, string state, string country, string zipcode,
|
||||
string cardNumber, string cardHolderName, DateTime cardExpiration,
|
||||
string cardSecurityNumber, int cardTypeId, int paymentId, int buyerId) : this()
|
||||
{
|
||||
_orderItems = orderItems;
|
||||
City = city;
|
||||
Street = street;
|
||||
State = state;
|
||||
|
@ -45,7 +45,19 @@ namespace FunctionalTests.Services.Ordering
|
||||
|
||||
string BuildOrder()
|
||||
{
|
||||
List<OrderItemDTO> orderItemsList = new List<OrderItemDTO>();
|
||||
orderItemsList.Add(new OrderItemDTO()
|
||||
{
|
||||
ProductId = 1,
|
||||
Discount = 8M,
|
||||
UnitPrice = 10,
|
||||
Units = 1,
|
||||
ProductName = "Some name"
|
||||
}
|
||||
);
|
||||
|
||||
var order = new CreateOrderCommand(
|
||||
orderItemsList,
|
||||
cardExpiration: DateTime.UtcNow.AddYears(1),
|
||||
cardNumber: "5145-555-5555",
|
||||
cardHolderName: "Jhon Senna",
|
||||
@ -60,15 +72,6 @@ namespace FunctionalTests.Services.Ordering
|
||||
buyerId: 3
|
||||
);
|
||||
|
||||
order.AddOrderItem(new OrderItemDTO()
|
||||
{
|
||||
ProductId = 1,
|
||||
Discount = 8M,
|
||||
UnitPrice = 10,
|
||||
Units = 1,
|
||||
ProductName = "Some name"
|
||||
});
|
||||
|
||||
return JsonConvert.SerializeObject(order);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,9 @@
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using System.Collections;
|
||||
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class OrderingScenarios
|
||||
: OrderingScenarioBase
|
||||
@ -59,7 +61,19 @@
|
||||
|
||||
string BuildOrder()
|
||||
{
|
||||
List<OrderItemDTO> orderItemsList = new List<OrderItemDTO>();
|
||||
orderItemsList.Add(new OrderItemDTO()
|
||||
{
|
||||
ProductId = 1,
|
||||
Discount = 10M,
|
||||
UnitPrice = 10,
|
||||
Units = 1,
|
||||
ProductName = "Some name"
|
||||
}
|
||||
);
|
||||
|
||||
var order = new CreateOrderCommand(
|
||||
orderItemsList,
|
||||
cardExpiration: DateTime.UtcNow.AddYears(1),
|
||||
cardNumber: "5145-555-5555",
|
||||
cardHolderName: "Jhon Senna",
|
||||
@ -74,20 +88,12 @@
|
||||
buyerId: 1
|
||||
);
|
||||
|
||||
order.AddOrderItem(new OrderItemDTO()
|
||||
{
|
||||
ProductId = 1,
|
||||
Discount = 10M,
|
||||
UnitPrice = 10,
|
||||
Units = 1,
|
||||
ProductName = "Some name"
|
||||
});
|
||||
|
||||
return JsonConvert.SerializeObject(order);
|
||||
}
|
||||
string BuildOrderWithInvalidExperationTime()
|
||||
{
|
||||
var order = new CreateOrderCommand(
|
||||
null,
|
||||
cardExpiration: DateTime.UtcNow.AddYears(-1),
|
||||
cardNumber: "5145-555-5555",
|
||||
cardHolderName: "Jhon Senna",
|
||||
|
@ -70,6 +70,7 @@ namespace UnitTest.Ordering.Application
|
||||
private CreateOrderCommand FakeOrderRequest(Dictionary<string, object> args = null)
|
||||
{
|
||||
return new CreateOrderCommand(
|
||||
null,
|
||||
city: args != null && args.ContainsKey("city") ? (string)args["city"] : null,
|
||||
street: args != null && args.ContainsKey("street") ? (string)args["street"] : null,
|
||||
state: args != null && args.ContainsKey("state") ? (string)args["state"] : null,
|
||||
|
@ -72,6 +72,7 @@ namespace UnitTest.Ordering.Application
|
||||
private CreateOrderCommand FakeOrderRequestWithBuyer(Dictionary<string, object> args = null)
|
||||
{
|
||||
return new CreateOrderCommand(
|
||||
null,
|
||||
city: args != null && args.ContainsKey("city") ? (string)args["city"] : null,
|
||||
street: args != null && args.ContainsKey("street") ? (string)args["street"] : null,
|
||||
state: args != null && args.ContainsKey("state") ? (string)args["state"] : null,
|
||||
|
Loading…
x
Reference in New Issue
Block a user