Browse Source

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.

pull/181/head
Cesar De la Torre 7 years ago
parent
commit
4b1467a7b9
5 changed files with 31 additions and 24 deletions
  1. +2
    -6
      src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommand.cs
  2. +12
    -9
      test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs
  3. +15
    -9
      test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs
  4. +1
    -0
      test/Services/UnitTest/Ordering/Application/IdentifierCommandHandlerTest.cs
  5. +1
    -0
      test/Services/UnitTest/Ordering/Application/NewOrderCommandHandlerTest.cs

+ 2
- 6
src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommand.cs View File

@ -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;


+ 12
- 9
test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs View File

@ -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);
}
}


+ 15
- 9
test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs View File

@ -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",


+ 1
- 0
test/Services/UnitTest/Ordering/Application/IdentifierCommandHandlerTest.cs View File

@ -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,


+ 1
- 0
test/Services/UnitTest/Ordering/Application/NewOrderCommandHandlerTest.cs View File

@ -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…
Cancel
Save