Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/RA.Tests/JsonIpIntegration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NUnit.Framework;
// using RA.Tests.Data;

namespace RA.Tests
{
Expand All @@ -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");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/RA.Tests/LoadIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
31 changes: 22 additions & 9 deletions src/RA.Tests/MockResponseContextWithJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Net;
using NUnit.Framework;
using RA.Exceptions;
// using RA.Tests.Data;

namespace RA.Tests
{
Expand Down Expand Up @@ -32,23 +31,21 @@ public MockResponseContextWithJson()
"{\"key\":\"AK\", \"value\":\"Alaska\"}" +
"]";

var header = new Dictionary<string, IEnumerable<string>>
var headers = new Dictionary<string, IEnumerable<string>>
{
{
"Content-Type",
new List<string> {"application/json"}
}
{"Content-Type", new List<string> {"application/json"}},
{"Date", new List<string> {"Fri, 02 Jul 2021 10:29:50 GMT"}}
};

var emptyHeader = new Dictionary<string, IEnumerable<string>>();


var loadResults = new List<LoadResponse> {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);
Expand Down Expand Up @@ -165,6 +162,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()
{
Expand Down
24 changes: 18 additions & 6 deletions src/RA/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ExecutionContext
private readonly SetupContext _setupContext;
private readonly HttpActionContext _httpActionContext;
private readonly HttpClient _httpClient;
private ConcurrentQueue<LoadResponse> _loadReponses = new ConcurrentQueue<LoadResponse>();
private ConcurrentQueue<LoadResponse> _loadResponses = new ConcurrentQueue<LoadResponse>();

public ExecutionContext(SetupContext setupContext, HttpActionContext httpActionContext)
{
Expand Down Expand Up @@ -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;
Expand All @@ -292,17 +292,29 @@ private async Task<HttpResponseMessageWrapper> 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()
);
_loadResponses.ToList());
}

private static Dictionary<string, IEnumerable<string>> 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;
}

/// <summary>
Expand Down