Browse Source

Add idempotent for the client header in tests

pull/142/head
dsanz 7 years ago
parent
commit
8c57048c3c
4 changed files with 45 additions and 6 deletions
  1. +18
    -0
      test/Services/FunctionalTests/Extensions/HttpClientExtensions.cs
  2. +3
    -2
      test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs
  3. +18
    -0
      test/Services/IntegrationTests/Services/Extensions/HttpClientExtensions.cs
  4. +6
    -4
      test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs

+ 18
- 0
test/Services/FunctionalTests/Extensions/HttpClientExtensions.cs View File

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

+ 3
- 2
test/Services/FunctionalTests/Services/Ordering/OrderingScenarios.cs View File

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


+ 18
- 0
test/Services/IntegrationTests/Services/Extensions/HttpClientExtensions.cs View File

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

+ 6
- 4
test/Services/IntegrationTests/Services/Ordering/OrderingScenarios.cs View File

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