Skip to content

Commit 5d8628c

Browse files
committed
Fix test that was failing sporadically.
1 parent 6e4d946 commit 5d8628c

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
using Microsoft.AspNetCore.TestHost;
2-
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
1+
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
32
using Microsoft.eShopOnContainers.WebMVC.ViewModels;
43
using Newtonsoft.Json;
54
using System;
65
using System.Collections.Generic;
7-
using System.Data.SqlClient;
6+
using System.Linq;
87
using System.Net.Http;
98
using System.Text;
109
using System.Threading.Tasks;
@@ -22,20 +21,20 @@ public async Task Create_order_and_return_the_order_by_id()
2221
{
2322
var client = server.CreateClient();
2423

25-
//Arrange
24+
// GIVEN an order is created
2625
await client.PostAsync(Post.AddNewOrder, new StringContent(BuildOrder(), UTF8Encoding.UTF8, "application/json"));
2726

2827
var ordersResponse = await client.GetAsync(Get.Orders);
2928
var responseBody = await ordersResponse.Content.ReadAsStringAsync();
30-
dynamic orders = JsonConvert.DeserializeObject(responseBody);
31-
string orderId = orders[0].ordernumber;
29+
var orders = JsonConvert.DeserializeObject<List<Order>>(responseBody);
30+
string orderId = orders.OrderByDescending(o => o.Date).First().OrderNumber;
3231

33-
//Act
32+
//WHEN we request the order bit its id
3433
var order= await client.GetAsync(Get.OrderBy(int.Parse(orderId)));
3534
var orderBody = await order.Content.ReadAsStringAsync();
3635
var result = JsonConvert.DeserializeObject<Order>(orderBody);
3736

38-
//Assert
37+
//THEN the requested order is returned
3938
Assert.Equal(orderId, result.OrderNumber);
4039
Assert.Equal("inprocess", result.Status);
4140
Assert.Equal(1, result.OrderItems.Count);
@@ -63,7 +62,7 @@ string BuildOrder()
6362
order.AddOrderItem(new OrderItemDTO()
6463
{
6564
ProductId = 1,
66-
Discount = 10M,
65+
Discount = 12M,
6766
UnitPrice = 10,
6867
Units = 1,
6968
ProductName = "Some name"

0 commit comments

Comments
 (0)