Add idempotent for the client header in tests
This commit is contained in:
parent
3b59433e97
commit
8c57048c3c
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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"));
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user