public async Task GetHttpRequest_HasAllHeadersMethodAndBody() { string requestUri = "http://localhost"; HttpRequest testRequest = HttpWorkerTestUtilities.GetTestHttpRequest(); Uri expectedUri = new Uri(QueryHelpers.AddQueryString(requestUri, testRequest.GetQueryCollectionAsDictionary())); HttpRequestMessage clonedRequest = testRequest.ToHttpRequestMessage(requestUri); Assert.Equal(testRequest.Headers.Count, clonedRequest.Headers.Count() + 1); // Content-Length would go to content header foreach (var header in testRequest.Headers) { IEnumerable <string> actualHeaderValue = header.Value.AsEnumerable(); IEnumerable <string> clonedHeaderValue; if (!header.Key.Equals("Content-Type", StringComparison.OrdinalIgnoreCase) && !header.Key.Equals("Content-Length", StringComparison.OrdinalIgnoreCase)) { clonedHeaderValue = clonedRequest.Headers.GetValues(header.Key); } else { clonedHeaderValue = clonedRequest.Content.Headers.GetValues(header.Key); } var count = actualHeaderValue.Except(clonedHeaderValue).Count(); Assert.Equal(count, 0); } Assert.Equal(testRequest.Method, clonedRequest.Method.ToString()); Assert.Equal(clonedRequest.RequestUri.ToString(), expectedUri.ToString()); Assert.Equal(await clonedRequest.Content.ReadAsStringAsync(), "\"hello world\""); }
public void GetQueryCollectionAsJObject_Expected() { var testHttpRequest = HttpWorkerTestUtilities.GetTestHttpRequest(); var query = testHttpRequest.GetQueryCollectionAsJObject(); Assert.Equal("Ink And Toner", query["name"]); }