diff --git a/src/Microsoft.AspNet.Authentication/HttpContextExtensions.cs b/src/Microsoft.AspNet.Authentication/HttpContextExtensions.cs index 4617b02f4e..d50b6055d3 100644 --- a/src/Microsoft.AspNet.Authentication/HttpContextExtensions.cs +++ b/src/Microsoft.AspNet.Authentication/HttpContextExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Authentication; using Microsoft.AspNet.Http.Features.Authentication.Internal; @@ -11,11 +12,11 @@ namespace Microsoft.AspNet.Authentication { internal static IHttpAuthenticationFeature GetAuthentication(this HttpContext context) { - var auth = context.GetFeature(); + var auth = context.Features.Get(); if (auth == null) { auth = new HttpAuthenticationFeature(); - context.SetFeature(auth); + context.Features.Set(auth); } return auth; } diff --git a/test/Microsoft.AspNet.Authentication.Test/AuthenticationHandlerFacts.cs b/test/Microsoft.AspNet.Authentication.Test/AuthenticationHandlerFacts.cs index 219b63edac..db1a7e3a24 100644 --- a/test/Microsoft.AspNet.Authentication.Test/AuthenticationHandlerFacts.cs +++ b/test/Microsoft.AspNet.Authentication.Test/AuthenticationHandlerFacts.cs @@ -2,11 +2,15 @@ // 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.Threading.Tasks; using Microsoft.AspNet.Http; +using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Authentication; using Microsoft.AspNet.Http.Internal; using Microsoft.Framework.Logging; +using Microsoft.Framework.Primitives; using Moq; using Xunit; @@ -92,10 +96,9 @@ namespace Microsoft.AspNet.Authentication public static async Task Create(string scheme) { var handler = new CountHandler(); - var context = new Mock(); - context.Setup(c => c.Request).Returns(new Mock().Object); - context.Setup(c => c.Response).Returns(new Mock().Object); - await handler.InitializeAsync(new CountOptions(), context.Object, new LoggerFactory().CreateLogger("CountHandler"), Framework.WebEncoders.UrlEncoder.Default); + var context = new DefaultHttpContext(); + context.Features.Set(new TestResponse()); + await handler.InitializeAsync(new CountOptions(), context, new LoggerFactory().CreateLogger("CountHandler"), Framework.WebEncoders.UrlEncoder.Default); handler.Options.AuthenticationScheme = scheme; handler.Options.AutomaticAuthentication = true; return handler; @@ -116,10 +119,9 @@ namespace Microsoft.AspNet.Authentication public static async Task Create(string scheme) { var handler = new TestHandler(); - var context = new Mock(); - context.Setup(c => c.Request).Returns(new Mock().Object); - context.Setup(c => c.Response).Returns(new Mock().Object); - await handler.InitializeAsync(new TestOptions(), context.Object, new LoggerFactory().CreateLogger("TestHandler"), Framework.WebEncoders.UrlEncoder.Default); + var context = new DefaultHttpContext(); + context.Features.Set(new TestResponse()); + await handler.InitializeAsync(new TestOptions(), context, new LoggerFactory().CreateLogger("TestHandler"), Framework.WebEncoders.UrlEncoder.Default); handler.Options.AuthenticationScheme = scheme; return handler; } @@ -147,10 +149,9 @@ namespace Microsoft.AspNet.Authentication public static async Task Create(string scheme, bool auto) { var handler = new TestAutoHandler(); - var context = new Mock(); - context.Setup(c => c.Request).Returns(new Mock().Object); - context.Setup(c => c.Response).Returns(new Mock().Object); - await handler.InitializeAsync(new TestAutoOptions(), context.Object, new LoggerFactory().CreateLogger("TestAutoHandler"), Framework.WebEncoders.UrlEncoder.Default); + var context = new DefaultHttpContext(); + context.Features.Set(new TestResponse()); + await handler.InitializeAsync(new TestAutoOptions(), context, new LoggerFactory().CreateLogger("TestAutoHandler"), Framework.WebEncoders.UrlEncoder.Default); handler.Options.AuthenticationScheme = scheme; handler.Options.AutomaticAuthentication = auto; return handler; @@ -161,5 +162,77 @@ namespace Microsoft.AspNet.Authentication return Task.FromResult(null); } } + + private class TestResponse : IHttpResponseFeature + { + public Stream Body + { + get + { + throw new NotImplementedException(); + } + + set + { + throw new NotImplementedException(); + } + } + + public bool HasStarted + { + get + { + throw new NotImplementedException(); + } + } + + public IDictionary Headers + { + get + { + throw new NotImplementedException(); + } + + set + { + throw new NotImplementedException(); + } + } + + public string ReasonPhrase + { + get + { + throw new NotImplementedException(); + } + + set + { + throw new NotImplementedException(); + } + } + + public int StatusCode + { + get + { + throw new NotImplementedException(); + } + + set + { + throw new NotImplementedException(); + } + } + + public void OnCompleted(Func callback, object state) + { + throw new NotImplementedException(); + } + + public void OnStarting(Func callback, object state) + { + } + } } }