From adae42b66f82a782ee51a8b4c80403248ae871e4 Mon Sep 17 00:00:00 2001 From: Chris R Date: Mon, 31 Aug 2015 07:22:34 -0700 Subject: [PATCH] Use new HttpContext.Features API. --- .../Internal/HostingEngine.cs | 4 ++-- src/Microsoft.AspNet.TestHost/ClientHandler.cs | 13 +++++-------- .../HostingEngineTests.cs | 6 +++--- .../HttpContextFactoryFacts.cs | 5 +++-- .../ClientHandlerTests.cs | 2 +- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs index 90139ad93e..4af23ea665 100644 --- a/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs +++ b/src/Microsoft.AspNet.Hosting/Internal/HostingEngine.cs @@ -162,14 +162,14 @@ namespace Microsoft.AspNet.Hosting.Internal private string GetRequestIdentifier(HttpContext httpContext) { - var requestIdentifierFeature = httpContext.GetFeature(); + var requestIdentifierFeature = httpContext.Features.Get(); if (requestIdentifierFeature == null) { requestIdentifierFeature = new HttpRequestIdentifierFeature() { TraceIdentifier = Guid.NewGuid().ToString() }; - httpContext.SetFeature(requestIdentifierFeature); + httpContext.Features.Set(requestIdentifierFeature); } return requestIdentifierFeature.TraceIdentifier; diff --git a/src/Microsoft.AspNet.TestHost/ClientHandler.cs b/src/Microsoft.AspNet.TestHost/ClientHandler.cs index df72462e24..23308d5161 100644 --- a/src/Microsoft.AspNet.TestHost/ClientHandler.cs +++ b/src/Microsoft.AspNet.TestHost/ClientHandler.cs @@ -70,7 +70,7 @@ namespace Microsoft.AspNet.TestHost { try { - await _next(state.FeatureCollection); + await _next(state.HttpContext.Features); state.CompleteResponse(); } catch (Exception ex) @@ -108,11 +108,10 @@ namespace Microsoft.AspNet.TestHost request.Headers.Host = request.RequestUri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped); } - FeatureCollection = new FeatureCollection(); - HttpContext = new DefaultHttpContext(FeatureCollection); - HttpContext.SetFeature(new RequestFeature()); + HttpContext = new DefaultHttpContext(); + HttpContext.Features.Set(new RequestFeature()); _responseFeature = new ResponseFeature(); - HttpContext.SetFeature(_responseFeature); + HttpContext.Features.Set(_responseFeature); var serverRequest = HttpContext.Request; serverRequest.Protocol = "HTTP/" + request.Version.ToString(2); serverRequest.Scheme = request.RequestUri.Scheme; @@ -154,8 +153,6 @@ namespace Microsoft.AspNet.TestHost public HttpContext HttpContext { get; private set; } - public IFeatureCollection FeatureCollection { get; private set; } - public Task ResponseTask { get { return _responseTcs.Task; } @@ -180,7 +177,7 @@ namespace Microsoft.AspNet.TestHost var response = new HttpResponseMessage(); response.StatusCode = (HttpStatusCode)HttpContext.Response.StatusCode; - response.ReasonPhrase = HttpContext.GetFeature().ReasonPhrase; + response.ReasonPhrase = HttpContext.Features.Get().ReasonPhrase; response.RequestMessage = _request; // response.Version = owinResponse.Protocol; diff --git a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs index 1642ec7235..a33e7367aa 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HostingEngineTests.cs @@ -241,7 +241,7 @@ namespace Microsoft.AspNet.Hosting // Assert Assert.NotNull(httpContext); - Assert.IsType(httpContext.GetFeature()); + Assert.IsType(httpContext.Features.Get()); } [Fact] @@ -264,7 +264,7 @@ namespace Microsoft.AspNet.Hosting // Assert Assert.NotNull(httpContext); - Assert.IsType(httpContext.GetFeature()); + Assert.IsType(httpContext.Features.Get()); } [Fact] @@ -286,7 +286,7 @@ namespace Microsoft.AspNet.Hosting // Assert Assert.NotNull(httpContext); - Assert.Same(requestIdentifierFeature, httpContext.GetFeature()); + Assert.Same(requestIdentifierFeature, httpContext.Features.Get()); } [Fact] diff --git a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs index 2188bfbb7c..302da49712 100644 --- a/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs +++ b/test/Microsoft.AspNet.Hosting.Tests/HttpContextFactoryFacts.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Microsoft.AspNet.Hosting.Builder; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Owin; using Xunit; @@ -18,8 +19,8 @@ namespace Microsoft.AspNet.Hosting.Tests var context = contextFactory.CreateHttpContext(new OwinFeatureCollection(env)); // Setting a feature will throw if the above feature collection is not wrapped in a mutable feature collection. - context.SetFeature(new CustomFeature(100)); - Assert.Equal(100, context.GetFeature().Value); + context.Features.Set(new CustomFeature(100)); + Assert.Equal(100, context.Features.Get().Value); } private interface ICustomFeature diff --git a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs index c52b38dc28..d4092e5ea2 100644 --- a/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs +++ b/test/Microsoft.AspNet.TestHost.Tests/ClientHandlerTests.cs @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.TestHost Assert.NotNull(context.Response.Headers); Assert.NotNull(context.Response.Body); Assert.Equal(200, context.Response.StatusCode); - Assert.Null(context.GetFeature().ReasonPhrase); + Assert.Null(context.Features.Get().ReasonPhrase); Assert.Equal("example.com", context.Request.Host.Value); return Task.FromResult(0);