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]
|
[DataMember]
|
||||||
public IEnumerable<OrderItemDTO> OrderItems => _orderItems;
|
public IEnumerable<OrderItemDTO> OrderItems => _orderItems;
|
||||||
|
|
||||||
public void AddOrderItem(OrderItemDTO item)
|
|
||||||
{
|
|
||||||
_orderItems.Add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CreateOrderCommand()
|
public CreateOrderCommand()
|
||||||
{
|
{
|
||||||
_orderItems = new List<OrderItemDTO>();
|
_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 cardNumber, string cardHolderName, DateTime cardExpiration,
|
||||||
string cardSecurityNumber, int cardTypeId, int paymentId, int buyerId) : this()
|
string cardSecurityNumber, int cardTypeId, int paymentId, int buyerId) : this()
|
||||||
{
|
{
|
||||||
|
_orderItems = orderItems;
|
||||||
City = city;
|
City = city;
|
||||||
Street = street;
|
Street = street;
|
||||||
State = state;
|
State = state;
|
||||||
|
@ -45,7 +45,19 @@ namespace FunctionalTests.Services.Ordering
|
|||||||
|
|
||||||
string BuildOrder()
|
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(
|
var order = new CreateOrderCommand(
|
||||||
|
orderItemsList,
|
||||||
cardExpiration: DateTime.UtcNow.AddYears(1),
|
cardExpiration: DateTime.UtcNow.AddYears(1),
|
||||||
cardNumber: "5145-555-5555",
|
cardNumber: "5145-555-5555",
|
||||||
cardHolderName: "Jhon Senna",
|
cardHolderName: "Jhon Senna",
|
||||||
@ -60,15 +72,6 @@ namespace FunctionalTests.Services.Ordering
|
|||||||
buyerId: 3
|
buyerId: 3
|
||||||
);
|
);
|
||||||
|
|
||||||
order.AddOrderItem(new OrderItemDTO()
|
|
||||||
{
|
|
||||||
ProductId = 1,
|
|
||||||
Discount = 8M,
|
|
||||||
UnitPrice = 10,
|
|
||||||
Units = 1,
|
|
||||||
ProductName = "Some name"
|
|
||||||
});
|
|
||||||
|
|
||||||
return JsonConvert.SerializeObject(order);
|
return JsonConvert.SerializeObject(order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using System.Collections;
|
||||||
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
|
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public class OrderingScenarios
|
public class OrderingScenarios
|
||||||
: OrderingScenarioBase
|
: OrderingScenarioBase
|
||||||
@ -59,7 +61,19 @@
|
|||||||
|
|
||||||
string BuildOrder()
|
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(
|
var order = new CreateOrderCommand(
|
||||||
|
orderItemsList,
|
||||||
cardExpiration: DateTime.UtcNow.AddYears(1),
|
cardExpiration: DateTime.UtcNow.AddYears(1),
|
||||||
cardNumber: "5145-555-5555",
|
cardNumber: "5145-555-5555",
|
||||||
cardHolderName: "Jhon Senna",
|
cardHolderName: "Jhon Senna",
|
||||||
@ -74,20 +88,12 @@
|
|||||||
buyerId: 1
|
buyerId: 1
|
||||||
);
|
);
|
||||||
|
|
||||||
order.AddOrderItem(new OrderItemDTO()
|
|
||||||
{
|
|
||||||
ProductId = 1,
|
|
||||||
Discount = 10M,
|
|
||||||
UnitPrice = 10,
|
|
||||||
Units = 1,
|
|
||||||
ProductName = "Some name"
|
|
||||||
});
|
|
||||||
|
|
||||||
return JsonConvert.SerializeObject(order);
|
return JsonConvert.SerializeObject(order);
|
||||||
}
|
}
|
||||||
string BuildOrderWithInvalidExperationTime()
|
string BuildOrderWithInvalidExperationTime()
|
||||||
{
|
{
|
||||||
var order = new CreateOrderCommand(
|
var order = new CreateOrderCommand(
|
||||||
|
null,
|
||||||
cardExpiration: DateTime.UtcNow.AddYears(-1),
|
cardExpiration: DateTime.UtcNow.AddYears(-1),
|
||||||
cardNumber: "5145-555-5555",
|
cardNumber: "5145-555-5555",
|
||||||
cardHolderName: "Jhon Senna",
|
cardHolderName: "Jhon Senna",
|
||||||
|
@ -70,6 +70,7 @@ namespace UnitTest.Ordering.Application
|
|||||||
private CreateOrderCommand FakeOrderRequest(Dictionary<string, object> args = null)
|
private CreateOrderCommand FakeOrderRequest(Dictionary<string, object> args = null)
|
||||||
{
|
{
|
||||||
return new CreateOrderCommand(
|
return new CreateOrderCommand(
|
||||||
|
null,
|
||||||
city: args != null && args.ContainsKey("city") ? (string)args["city"] : null,
|
city: args != null && args.ContainsKey("city") ? (string)args["city"] : null,
|
||||||
street: args != null && args.ContainsKey("street") ? (string)args["street"] : null,
|
street: args != null && args.ContainsKey("street") ? (string)args["street"] : null,
|
||||||
state: args != null && args.ContainsKey("state") ? (string)args["state"] : 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)
|
private CreateOrderCommand FakeOrderRequestWithBuyer(Dictionary<string, object> args = null)
|
||||||
{
|
{
|
||||||
return new CreateOrderCommand(
|
return new CreateOrderCommand(
|
||||||
|
null,
|
||||||
city: args != null && args.ContainsKey("city") ? (string)args["city"] : null,
|
city: args != null && args.ContainsKey("city") ? (string)args["city"] : null,
|
||||||
street: args != null && args.ContainsKey("street") ? (string)args["street"] : null,
|
street: args != null && args.ContainsKey("street") ? (string)args["street"] : null,
|
||||||
state: args != null && args.ContainsKey("state") ? (string)args["state"] : null,
|
state: args != null && args.ContainsKey("state") ? (string)args["state"] : null,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user