From 4e71c3265f25b87338ad9fb5397658caa3b25dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Modestas=20=C5=A0aulys?= Date: Fri, 2 Jul 2021 14:01:53 +0300 Subject: [PATCH 1/3] fix integration test url's to https://api.publicapis.org/entries since http://geoip.nekudo.com/api/ was deprecated --- src/RA.Tests/JsonIpIntegration.cs | 7 +++---- src/RA.Tests/LoadIntegrationTest.cs | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/RA.Tests/JsonIpIntegration.cs b/src/RA.Tests/JsonIpIntegration.cs index a530ba7..12f832d 100644 --- a/src/RA.Tests/JsonIpIntegration.cs +++ b/src/RA.Tests/JsonIpIntegration.cs @@ -1,5 +1,4 @@ using NUnit.Framework; -// using RA.Tests.Data; namespace RA.Tests { @@ -13,11 +12,11 @@ public void ResponseShouldShow() .Given() .Name("JsonIP") .When() - .Get("http://geoip.nekudo.com/api/") + .Get("https://api.publicapis.org/entries") .Then() .Debug() - .TestBody("ip exist", x => x.ip != null) - .Assert("ip exist"); + .TestBody("entries exist", x => x.entries != null) + .Assert("entries exist"); } } diff --git a/src/RA.Tests/LoadIntegrationTest.cs b/src/RA.Tests/LoadIntegrationTest.cs index 4f44d99..7bfbde5 100644 --- a/src/RA.Tests/LoadIntegrationTest.cs +++ b/src/RA.Tests/LoadIntegrationTest.cs @@ -14,7 +14,7 @@ public void SingleThread() .When() //one thread for 15 seconds .Load(1, 10) - .Get("http://geoip.nekudo.com/api/") + .Get("https://api.publicapis.org/entries") .Then() .Debug(); } @@ -28,7 +28,7 @@ public void MultiThread() .When() //one thread for 15 seconds .Load(6, 10) - .Get("http://geoip.nekudo.com/api/") + .Get("https://api.publicapis.org/entries") .Then() .Debug(); } From cd0f573ef8424ff7d0d8704c5e5e8752efd2bf88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Modestas=20=C5=A0aulys?= Date: Fri, 2 Jul 2021 14:06:25 +0300 Subject: [PATCH 2/3] add Response.Headers to headers dictionary from response. unit tests --- src/RA.Tests/MockResponseContextWithJson.cs | 30 +++++++++++++++------ src/RA/ExecutionContext.cs | 20 +++++++++++--- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/RA.Tests/MockResponseContextWithJson.cs b/src/RA.Tests/MockResponseContextWithJson.cs index c00eb8c..79a8df4 100644 --- a/src/RA.Tests/MockResponseContextWithJson.cs +++ b/src/RA.Tests/MockResponseContextWithJson.cs @@ -32,23 +32,21 @@ public MockResponseContextWithJson() "{\"key\":\"AK\", \"value\":\"Alaska\"}" + "]"; - var header = new Dictionary> + var headers = new Dictionary> { - { - "Content-Type", - new List {"application/json"} - } + {"Content-Type", new List {"application/json"}}, + {"Date", new List {"Fri, 02 Jul 2021 10:29:50 GMT"}} }; var emptyHeader = new Dictionary>(); var loadResults = new List {new LoadResponse(200, 78978078)}; - _responseWithObject = new ResponseContext(HttpStatusCode.OK, responseObjectContent, header, + _responseWithObject = new ResponseContext(HttpStatusCode.OK, responseObjectContent, headers, _mockElapsedTimespan, loadResults); - _responseWithObject2 = new ResponseContext(HttpStatusCode.OK, responseObjectContent, header, + _responseWithObject2 = new ResponseContext(HttpStatusCode.OK, responseObjectContent, headers, _mockElapsedTimespan, loadResults); - _responseWithArray = new ResponseContext(HttpStatusCode.OK, responseArrayContent, header, + _responseWithArray = new ResponseContext(HttpStatusCode.OK, responseArrayContent, headers, _mockElapsedTimespan, loadResults); _responseWithNothing = new ResponseContext(HttpStatusCode.OK, "", emptyHeader, _mockElapsedTimespan, loadResults); @@ -165,6 +163,22 @@ public void TestHeaderWithContentTypeUpperCased() .Assert("content header has app/json upper"); } + [Test] + public void TestHeaderWithDateUpperCased() + { + _responseWithObject + .TestHeader("content header has DATE upper", "DATE", x => x == "Fri, 02 Jul 2021 10:29:50 GMT") + .Assert("content header has date upper"); + } + + [Test] + public void TestHeaderWithDateLowerCased() + { + _responseWithObject + .TestHeader("content header has date upper", "date", x => x == "Fri, 02 Jul 2021 10:29:50 GMT") + .Assert("content header has date upper"); + } + [Test] public void TestLoadforMoreThanTotalCallShouldThrow() { diff --git a/src/RA/ExecutionContext.cs b/src/RA/ExecutionContext.cs index d5c97d0..3e71958 100644 --- a/src/RA/ExecutionContext.cs +++ b/src/RA/ExecutionContext.cs @@ -292,17 +292,29 @@ private async Task ExecuteCall() private ResponseContext BuildFromResponse(HttpResponseMessageWrapper result) { - // var content = AsyncContext.Run(async () => await result.Response.Content.ReadAsStringAsync()); var content = result.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); + var headers = GetHeaders(result); return new ResponseContext( result.Response.StatusCode, content, - result.Response.Content.Headers.ToDictionary(x => x.Key.Trim(), x => x.Value), + headers, result.ElaspedExecution, - _loadReponses.ToList() - ); + _loadReponses.ToList()); + } + + private static Dictionary> GetHeaders(HttpResponseMessageWrapper result) + { + var headers = result.Response.Headers.ToDictionary(x => x.Key.Trim(), x => x.Value); + var contentHeaders = result.Response.Content.Headers.ToDictionary(x => x.Key.Trim(), x => x.Value); + + foreach (var contentHeader in contentHeaders) + { + if(!headers.ContainsKey(contentHeader.Key)) + headers.Add(contentHeader.Key, contentHeader.Value); + } + return headers; } /// From dfaec8d6e6d97eb08deb0e0c8b683fa099116db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Modestas=20=C5=A0aulys?= Date: Fri, 2 Jul 2021 14:07:20 +0300 Subject: [PATCH 3/3] cleanup. typo fix --- src/RA.Tests/MockResponseContextWithJson.cs | 1 - src/RA/ExecutionContext.cs | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/RA.Tests/MockResponseContextWithJson.cs b/src/RA.Tests/MockResponseContextWithJson.cs index 79a8df4..ddecfef 100644 --- a/src/RA.Tests/MockResponseContextWithJson.cs +++ b/src/RA.Tests/MockResponseContextWithJson.cs @@ -3,7 +3,6 @@ using System.Net; using NUnit.Framework; using RA.Exceptions; -// using RA.Tests.Data; namespace RA.Tests { diff --git a/src/RA/ExecutionContext.cs b/src/RA/ExecutionContext.cs index 3e71958..9e5692d 100644 --- a/src/RA/ExecutionContext.cs +++ b/src/RA/ExecutionContext.cs @@ -21,7 +21,7 @@ public class ExecutionContext private readonly SetupContext _setupContext; private readonly HttpActionContext _httpActionContext; private readonly HttpClient _httpClient; - private ConcurrentQueue _loadReponses = new ConcurrentQueue(); + private ConcurrentQueue _loadResponses = new ConcurrentQueue(); public ExecutionContext(SetupContext setupContext, HttpActionContext httpActionContext) { @@ -272,7 +272,7 @@ public async Task SingleThread(CancellationToken cancellationToken) public async Task MapCall() { var loadResponse = new LoadResponse(-1, -1); - _loadReponses.Enqueue(loadResponse); + _loadResponses.Enqueue(loadResponse); var result = await ExecuteCall(); loadResponse.StatusCode = (int)result.Response.StatusCode; @@ -300,7 +300,7 @@ private ResponseContext BuildFromResponse(HttpResponseMessageWrapper result) content, headers, result.ElaspedExecution, - _loadReponses.ToList()); + _loadResponses.ToList()); } private static Dictionary> GetHeaders(HttpResponseMessageWrapper result)