Skip to content

Assert response headers#56

Open
m0d7 wants to merge 3 commits intolamchakchan:masterfrom
m0d7:assert-response-headers
Open

Assert response headers#56
m0d7 wants to merge 3 commits intolamchakchan:masterfrom
m0d7:assert-response-headers

Conversation

@m0d7
Copy link

@m0d7 m0d7 commented Jul 2, 2021

/// <summary>
/// Setup a test against the response headers.
/// </summary>
/// <param name="ruleName"></param>
/// <param name="key"></param>
/// <param name="func"></param>
/// <returns></returns>
public ResponseContext TestHeader(string ruleName, string key, Func<string, bool> func)
{
return TestWrapper(ruleName, () => func.Invoke(HeaderValue(key.Trim())));
}

TestHeader method states that Setup a test against response headers., however, the assert is not being done against Response.Headers, but Response.Content.Headers:
private ResponseContext BuildFromResponse(HttpResponseMessageWrapper result)
{
// var content = AsyncContext.Run(async () => await result.Response.Content.ReadAsStringAsync());
var content = result.Response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
return new ResponseContext(
result.Response.StatusCode,
content,
result.Response.Content.Headers.ToDictionary(x => x.Key.Trim(), x => x.Value),
result.ElaspedExecution,
_loadReponses.ToList()
);
}

As far as I know, currently there is no possibility to assert Response.Headers. So this PR fixes this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments