Skip to content

Commit 69d7399

Browse files
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.
1 parent 22cc8da commit 69d7399

5 files changed

Lines changed: 31 additions & 24 deletions

File tree

src/Services/Ordering/Ordering.API/Application/Commands/CreateOrderCommand.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,16 @@ public class CreateOrderCommand
6161
[DataMember]
6262
public IEnumerable<OrderItemDTO> OrderItems => _orderItems;
6363

64-
public void AddOrderItem(OrderItemDTO item)
65-
{
66-
_orderItems.Add(item);
67-
}
68-
6964
public CreateOrderCommand()
7065
{
7166
_orderItems = new List<OrderItemDTO>();
7267
}
7368

74-
public CreateOrderCommand(string city, string street, string state, string country, string zipcode,
69+
public CreateOrderCommand(List<OrderItemDTO> orderItems, string city, string street, string state, string country, string zipcode,
7570
string cardNumber, string cardHolderName, DateTime cardExpiration,
7671
string cardSecurityNumber, int cardTypeId, int paymentId, int buyerId) : this()
7772
{
73+
_orderItems = orderItems;
7874
City = city;
7975
Street = street;
8076
State = state;

test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,19 @@ public async Task Create_order_and_return_the_order_by_id()
4545

4646
string BuildOrder()
4747
{
48+
List<OrderItemDTO> orderItemsList = new List<OrderItemDTO>();
49+
orderItemsList.Add(new OrderItemDTO()
50+
{
51+
ProductId = 1,
52+
Discount = 8M,
53+
UnitPrice = 10,
54+
Units = 1,
55+
ProductName = "Some name"
56+
}
57+
);
58+
4859
var order = new CreateOrderCommand(
60+
orderItemsList,
4961
cardExpiration: DateTime.UtcNow.AddYears(1),
5062
cardNumber: "5145-555-5555",
5163
cardHolderName: "Jhon Senna",
@@ -60,15 +72,6 @@ string BuildOrder()
6072
buyerId: 3
6173
);
6274

63-
order.AddOrderItem(new OrderItemDTO()
64-
{
65-
ProductId = 1,
66-
Discount = 8M,
67-
UnitPrice = 10,
68-
Units = 1,
69-
ProductName = "Some name"
70-
});
71-
7275
return JsonConvert.SerializeObject(order);
7376
}
7477
}

test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
using System.Text;
1010
using System.Threading.Tasks;
1111
using Xunit;
12+
using System.Collections;
1213
using static Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands.CreateOrderCommand;
14+
using System.Collections.Generic;
1315

1416
public class OrderingScenarios
1517
: OrderingScenarioBase
@@ -59,7 +61,19 @@ public async Task AddNewOrder_response_bad_request_if_card_expiration_is_invalid
5961

6062
string BuildOrder()
6163
{
64+
List<OrderItemDTO> orderItemsList = new List<OrderItemDTO>();
65+
orderItemsList.Add(new OrderItemDTO()
66+
{
67+
ProductId = 1,
68+
Discount = 10M,
69+
UnitPrice = 10,
70+
Units = 1,
71+
ProductName = "Some name"
72+
}
73+
);
74+
6275
var order = new CreateOrderCommand(
76+
orderItemsList,
6377
cardExpiration: DateTime.UtcNow.AddYears(1),
6478
cardNumber: "5145-555-5555",
6579
cardHolderName: "Jhon Senna",
@@ -74,20 +88,12 @@ string BuildOrder()
7488
buyerId: 1
7589
);
7690

77-
order.AddOrderItem(new OrderItemDTO()
78-
{
79-
ProductId = 1,
80-
Discount = 10M,
81-
UnitPrice = 10,
82-
Units = 1,
83-
ProductName = "Some name"
84-
});
85-
8691
return JsonConvert.SerializeObject(order);
8792
}
8893
string BuildOrderWithInvalidExperationTime()
8994
{
9095
var order = new CreateOrderCommand(
96+
null,
9197
cardExpiration: DateTime.UtcNow.AddYears(-1),
9298
cardNumber: "5145-555-5555",
9399
cardHolderName: "Jhon Senna",

test/Services/UnitTest/Ordering/Application/IdentifierCommandHandlerTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public async Task Handler_sends_no_command_when_order_already_exists()
7070
private CreateOrderCommand FakeOrderRequest(Dictionary<string, object> args = null)
7171
{
7272
return new CreateOrderCommand(
73+
null,
7374
city: args != null && args.ContainsKey("city") ? (string)args["city"] : null,
7475
street: args != null && args.ContainsKey("street") ? (string)args["street"] : null,
7576
state: args != null && args.ContainsKey("state") ? (string)args["state"] : null,

test/Services/UnitTest/Ordering/Application/NewOrderCommandHandlerTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ private Order FakeOrder()
7272
private CreateOrderCommand FakeOrderRequestWithBuyer(Dictionary<string, object> args = null)
7373
{
7474
return new CreateOrderCommand(
75+
null,
7576
city: args != null && args.ContainsKey("city") ? (string)args["city"] : null,
7677
street: args != null && args.ContainsKey("street") ? (string)args["street"] : null,
7778
state: args != null && args.ContainsKey("state") ? (string)args["state"] : null,

0 commit comments

Comments
 (0)