diff --git a/test/Services/FunctionalTests/Extensions/HttpClientExtensions.cs b/test/Services/FunctionalTests/Extensions/HttpClientExtensions.cs new file mode 100644 index 000000000..a41ffd3a2 --- /dev/null +++ b/test/Services/FunctionalTests/Extensions/HttpClientExtensions.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNetCore.TestHost; +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; + +namespace FunctionalTests.Extensions +{ + static class HttpClientExtensions + { + public static HttpClient CreateIdempotentClient(this TestServer server) + { + var client = server.CreateClient(); + client.DefaultRequestHeaders.Add("x-requestid", Guid.NewGuid().ToString()); + return client; + } + } +} diff --git a/test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs b/test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs index 11040aeaa..5f52e1771 100644 --- a/test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs +++ b/test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs @@ -1,4 +1,5 @@ -using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; +using FunctionalTests.Extensions; +using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; using Microsoft.eShopOnContainers.WebMVC.ViewModels; using Newtonsoft.Json; using System; @@ -19,7 +20,7 @@ namespace FunctionalTests.Services.Ordering { using (var server = CreateServer()) { - var client = server.CreateClient(); + var client = server.CreateIdempotentClient(); // GIVEN an order is created await client.PostAsync(Post.AddNewOrder, new StringContent(BuildOrder(), UTF8Encoding.UTF8, "application/json")); diff --git a/test/Services/IntegrationTests/Services/Extensions/HttpClientExtensions.cs b/test/Services/IntegrationTests/Services/Extensions/HttpClientExtensions.cs new file mode 100644 index 000000000..00ed918b6 --- /dev/null +++ b/test/Services/IntegrationTests/Services/Extensions/HttpClientExtensions.cs @@ -0,0 +1,18 @@ +using Microsoft.AspNetCore.TestHost; +using System; +using System.Collections.Generic; +using System.Net.Http; +using System.Text; + +namespace IntegrationTests.Services.Extensions +{ + static class HttpClientExtensions + { + public static HttpClient CreateIdempotentClient(this TestServer server) + { + var client = server.CreateClient(); + client.DefaultRequestHeaders.Add("x-requestid", Guid.NewGuid().ToString()); + return client; + } + } +} diff --git a/test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs b/test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs index ba77a3e7c..3e2350c9d 100644 --- a/test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs +++ b/test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs @@ -1,5 +1,7 @@ namespace IntegrationTests.Services.Ordering { + using IntegrationTests.Services.Extensions; + using Microsoft.AspNetCore.TestHost; using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; using Newtonsoft.Json; using System; @@ -28,9 +30,9 @@ public async Task AddNewOrder_add_new_order_and_response_ok_status_code() { using (var server = CreateServer()) - { + { var content = new StringContent(BuildOrder(), UTF8Encoding.UTF8, "application/json"); - var response = await server.CreateClient() + var response = await server.CreateIdempotentClient() .PostAsync(Post.AddNewOrder, content); response.EnsureSuccessStatusCode(); @@ -44,7 +46,7 @@ { var content = new StringContent(BuildOrderWithInvalidExperationTime(), UTF8Encoding.UTF8, "application/json"); - var response = await server.CreateClient() + var response = await server.CreateIdempotentClient() .PostAsync(Post.AddNewOrder, content); Assert.True(response.StatusCode == System.Net.HttpStatusCode.BadRequest); @@ -102,5 +104,5 @@ return JsonConvert.SerializeObject(order); } - } + } }