diff --git a/test/Microsoft.AspNet.Http.Tests/Fakes.cs b/src/Microsoft.AspNet.PipelineCore/DeafultHttpRequestFeature.cs similarity index 51% rename from test/Microsoft.AspNet.Http.Tests/Fakes.cs rename to src/Microsoft.AspNet.PipelineCore/DeafultHttpRequestFeature.cs index d33efeaa..bfbdf518 100644 --- a/test/Microsoft.AspNet.Http.Tests/Fakes.cs +++ b/src/Microsoft.AspNet.PipelineCore/DeafultHttpRequestFeature.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -6,10 +6,22 @@ using System.IO; using Microsoft.AspNet.HttpFeature; -namespace Microsoft.AspNet.Builder.Extensions +namespace Microsoft.AspNet.PipelineCore { - public class FakeHttpRequestFeature : IHttpRequestFeature + public class DeafultHttpRequestFeature : IHttpRequestFeature { + public DeafultHttpRequestFeature() + { + Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); + Body = Stream.Null; + Protocol = string.Empty; + Scheme = string.Empty; + Method = string.Empty; + PathBase = string.Empty; + Path = string.Empty; + QueryString = string.Empty; + } + public string Protocol { get; set; } public string Scheme { get; set; } public string Method { get; set; } @@ -19,16 +31,4 @@ public class FakeHttpRequestFeature : IHttpRequestFeature public IDictionary Headers { get; set; } public Stream Body { get; set; } } - - public class FakeHttpResponseFeature : IHttpResponseFeature - { - public int StatusCode { get; set; } - public string ReasonPhrase { get; set; } - public IDictionary Headers { get; set; } - public Stream Body { get; set; } - public void OnSendingHeaders(Action callback, object state) - { - throw new NotImplementedException(); - } - } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs b/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs index 9afbc436..af1f15e7 100644 --- a/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs +++ b/src/Microsoft.AspNet.PipelineCore/DefaultHttpContext.cs @@ -33,6 +33,13 @@ public class DefaultHttpContext : HttpContext private FeatureReference _webSockets; private IFeatureCollection _features; + public DefaultHttpContext() + : this(new FeatureCollection()) + { + SetFeature(new DeafultHttpRequestFeature()); + SetFeature(new DefaultHttpResponseFeature()); + } + public DefaultHttpContext(IFeatureCollection features) { _features = features; diff --git a/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponseFeature.cs b/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponseFeature.cs new file mode 100644 index 00000000..819ff174 --- /dev/null +++ b/src/Microsoft.AspNet.PipelineCore/DefaultHttpResponseFeature.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.IO; +using Microsoft.AspNet.HttpFeature; + +namespace Microsoft.AspNet.PipelineCore +{ + public class DefaultHttpResponseFeature : IHttpResponseFeature + { + public DefaultHttpResponseFeature() + { + StatusCode = 200; + Headers = new Dictionary(StringComparer.OrdinalIgnoreCase); + Body = Stream.Null; + } + + public int StatusCode { get; set; } + + public string ReasonPhrase { get; set; } + + public IDictionary Headers { get; set; } + + public Stream Body { get; set; } + + public void OnSendingHeaders(Action callback, object state) + { + throw new NotSupportedException(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.kproj b/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.kproj index 05dd7de5..054abcaa 100644 --- a/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.kproj +++ b/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.kproj @@ -27,6 +27,8 @@ + + diff --git a/test/Microsoft.AspNet.Http.Tests/MapPathMiddlewareTests.cs b/test/Microsoft.AspNet.Http.Tests/MapPathMiddlewareTests.cs index 3bca69be..4a9d68dd 100644 --- a/test/Microsoft.AspNet.Http.Tests/MapPathMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Http.Tests/MapPathMiddlewareTests.cs @@ -187,9 +187,7 @@ public void ChainedRoutes_Success() private HttpContext CreateRequest(string basePath, string requestPath) { - HttpContext context = new DefaultHttpContext(new FeatureModel.FeatureCollection()); - context.SetFeature(new FakeHttpRequestFeature()); - context.SetFeature(new FakeHttpResponseFeature()); + HttpContext context = new DefaultHttpContext(); context.Request.PathBase = new PathString(basePath); context.Request.Path = new PathString(requestPath); return context; diff --git a/test/Microsoft.AspNet.Http.Tests/MapPredicateMiddlewareTests.cs b/test/Microsoft.AspNet.Http.Tests/MapPredicateMiddlewareTests.cs index 17cce7c7..eb8ee8be 100644 --- a/test/Microsoft.AspNet.Http.Tests/MapPredicateMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Http.Tests/MapPredicateMiddlewareTests.cs @@ -176,9 +176,7 @@ public void ChainedPredicatesAsync_Success() private HttpContext CreateRequest() { - HttpContext context = new DefaultHttpContext(new FeatureModel.FeatureCollection()); - context.SetFeature(new FakeHttpRequestFeature()); - context.SetFeature(new FakeHttpResponseFeature()); + HttpContext context = new DefaultHttpContext(); return context; } } diff --git a/test/Microsoft.AspNet.Http.Tests/Microsoft.AspNet.Http.Tests.kproj b/test/Microsoft.AspNet.Http.Tests/Microsoft.AspNet.Http.Tests.kproj index 883a9d89..f8e3963d 100644 --- a/test/Microsoft.AspNet.Http.Tests/Microsoft.AspNet.Http.Tests.kproj +++ b/test/Microsoft.AspNet.Http.Tests/Microsoft.AspNet.Http.Tests.kproj @@ -21,10 +21,9 @@ - - + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Owin.Tests/OwinEnvironmentTests.cs b/test/Microsoft.AspNet.Owin.Tests/OwinEnvironmentTests.cs index d7ce8ae5..cdc5eb68 100644 --- a/test/Microsoft.AspNet.Owin.Tests/OwinEnvironmentTests.cs +++ b/test/Microsoft.AspNet.Owin.Tests/OwinEnvironmentTests.cs @@ -1,16 +1,11 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Claims; -using System.Threading; -using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Http; -using Microsoft.AspNet.HttpFeature; -using Microsoft.AspNet.HttpFeature.Security; using Microsoft.AspNet.PipelineCore; using Xunit; @@ -101,66 +96,8 @@ public void OwinEnvironmentCanBeModified() private HttpContext CreateContext() { - var features = new FeatureCollection(); - features.Add(typeof(IHttpRequestFeature), new MoqHttpRequestFeature()); - features.Add(typeof(IHttpResponseFeature), new MoqHttpResponseFeature()); - features.Add(typeof(IHttpRequestLifetimeFeature), new MoqHttpRequestLifetimeFeature()); - return new DefaultHttpContext(features); - } - - private class MoqHttpRequestFeature : IHttpRequestFeature - { - public MoqHttpRequestFeature() - { - Headers = new Dictionary(); - } - - public string Method { get; set; } - - public string Scheme { get; set; } - - public string Protocol { get; set; } - - public Stream Body { get; set; } - - public string PathBase { get; set; } - - public string Path { get; set; } - - public string QueryString { get; set; } - - public IDictionary Headers { get; set; } - } - - private class MoqHttpResponseFeature : IHttpResponseFeature - { - public MoqHttpResponseFeature() - { - Headers = new Dictionary(); - } - - public Stream Body { get; set; } - - public int StatusCode { get; set; } - - public string ReasonPhrase { get; set; } - - public IDictionary Headers { get; set; } - - public void OnSendingHeaders(Action callback, object state) - { - throw new NotImplementedException(); - } - } - - private class MoqHttpRequestLifetimeFeature : IHttpRequestLifetimeFeature - { - public CancellationToken RequestAborted { get; private set; } - - public void Abort() - { - throw new NotImplementedException(); - } + var context = new DefaultHttpContext(); + return context; } } } diff --git a/test/Microsoft.AspNet.PipelineCore.Tests/DefaultHttpContextTests.cs b/test/Microsoft.AspNet.PipelineCore.Tests/DefaultHttpContextTests.cs index 6ece4245..723811a9 100644 --- a/test/Microsoft.AspNet.PipelineCore.Tests/DefaultHttpContextTests.cs +++ b/test/Microsoft.AspNet.PipelineCore.Tests/DefaultHttpContextTests.cs @@ -80,25 +80,8 @@ public void SignOutWithNoAuthMiddlewareMayThrow() private HttpContext CreateContext() { - var context = new DefaultHttpContext(new FeatureCollection()); - context.SetFeature(new FakeHttpResponse()); + var context = new DefaultHttpContext(); return context; } - - private class FakeHttpResponse : IHttpResponseFeature - { - public int StatusCode { get; set; } - - public string ReasonPhrase { get; set; } - - public IDictionary Headers { get; set; } - - public Stream Body { get; set; } - - public void OnSendingHeaders(Action callback, object state) - { - throw new NotImplementedException(); - } - } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.PipelineCore.Tests/DefaultHttpRequestTests.cs b/test/Microsoft.AspNet.PipelineCore.Tests/DefaultHttpRequestTests.cs index 93d816e8..baa1c6c4 100644 --- a/test/Microsoft.AspNet.PipelineCore.Tests/DefaultHttpRequestTests.cs +++ b/test/Microsoft.AspNet.PipelineCore.Tests/DefaultHttpRequestTests.cs @@ -5,9 +5,7 @@ using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Http; -using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.HttpFeature; -using Moq; using Xunit; namespace Microsoft.AspNet.PipelineCore.Tests @@ -57,9 +55,9 @@ public void Host_GetsHostFromHeaders() // Arrange const string expected = "localhost:9001"; - var headers = new Dictionary(StringComparer.Ordinal) + var headers = new Dictionary(StringComparer.OrdinalIgnoreCase) { - { "Host", new string[]{ expected } }, + { "Host", new string[] { expected } }, }; var request = CreateRequest(headers); @@ -77,7 +75,7 @@ public void Host_DecodesPunyCode() // Arrange const string expected = "löcalhöst"; - var headers = new Dictionary(StringComparer.Ordinal) + var headers = new Dictionary(StringComparer.OrdinalIgnoreCase) { { "Host", new string[]{ "xn--lcalhst-90ae" } }, }; @@ -97,7 +95,7 @@ public void Host_EncodesPunyCode() // Arrange const string expected = "xn--lcalhst-90ae"; - var headers = new Dictionary(StringComparer.Ordinal); + var headers = new Dictionary(StringComparer.OrdinalIgnoreCase); var request = CreateRequest(headers); @@ -108,25 +106,19 @@ public void Host_EncodesPunyCode() Assert.Equal(expected, headers["Host"][0]); } - private static DefaultHttpRequest CreateRequest(IDictionary headers) + private static HttpRequest CreateRequest(IDictionary headers) { - var requestInfo = new Mock(); - requestInfo.SetupGet(r => r.Headers).Returns(headers); - - var features = new FeatureCollection(); - features.Add(typeof(IHttpRequestFeature), requestInfo.Object); - - var context = new DefaultHttpContext(features); - return new DefaultHttpRequest(context, features); + var context = new DefaultHttpContext(); + context.GetFeature().Headers = headers; + return context.Request; } - private static DefaultHttpRequest GetRequestWithContentLength(string contentLength = null) + private static HttpRequest GetRequestWithContentLength(string contentLength = null) { - var headers = new Dictionary(StringComparer.Ordinal); + var headers = new Dictionary(StringComparer.OrdinalIgnoreCase); if (contentLength != null) { headers.Add("Content-Length", new[] { contentLength }); - } return CreateRequest(headers);