public async Task ExecuteResultAsync_WithValidContext_Passes() { // The ActionContext will hold the copy result var ac = new Microsoft.AspNetCore.Mvc.ActionContext { HttpContext = new DefaultHttpContext(), }; // Execute await httpResponseMessageResult.ExecuteResultAsync(ac); var res = ac.HttpContext.Response; Assert.AreEqual(200, res.StatusCode); var responseFeature = ac.HttpContext.Features.Get <IHttpResponseFeature>(); Assert.AreEqual(Reason, responseFeature.ReasonPhrase); res.Headers.TryGetValue("my-custom-header", out StringValues headerVal); Assert.AreEqual(httpResponseMessage.Headers.GetValues("my-custom-header"), headerVal); var val = httpResponseMessage.Content.Headers.GetValues("my-custom-content-header"); res.Headers.TryGetValue("my-custom-content-header", out StringValues contentHeaderVal); Assert.AreEqual(val, contentHeaderVal); }
public async Task ExecuteResultAsync_IgnoresTransferEncoding_Passes() { // The ActionContext will hold the copy result var ac = new Microsoft.AspNetCore.Mvc.ActionContext { HttpContext = new DefaultHttpContext(), }; // Set transfer encoding httpResponseMessage.Headers.TransferEncodingChunked = true; // recreate result object with updated message. httpResponseMessageResult = new HttpResponseMessageResult(httpResponseMessage); // Execute await httpResponseMessageResult.ExecuteResultAsync(ac); var res = ac.HttpContext.Response; Assert.AreEqual(200, res.StatusCode); var responseFeature = ac.HttpContext.Features.Get <IHttpResponseFeature>(); Assert.AreEqual(Reason, responseFeature.ReasonPhrase); res.Headers.TryGetValue("my-custom-header", out StringValues headerVal); Assert.AreEqual(httpResponseMessage.Headers.GetValues("my-custom-header"), headerVal); var val = httpResponseMessage.Content.Headers.GetValues("my-custom-content-header"); res.Headers.TryGetValue("my-custom-content-header", out StringValues contentHeaderVal); Assert.AreEqual(val, contentHeaderVal); // Verify transfer encoding was ignored res.Headers.TryGetValue("Transfer-Encoding", out StringValues transferEnc); Assert.IsTrue(transferEnc.Count == 0); }