diff --git a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs index 82bb7a90fc..ff1a67d532 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs @@ -1020,14 +1020,8 @@ namespace Microsoft.AspNet.Authentication.Cookies { xml.Add(result.Properties.Select(extra => new XElement("extra", new XAttribute("type", extra.Key), new XAttribute("value", extra.Value)))); } - using (var memory = new MemoryStream()) - { - using (var writer = new XmlTextWriter(memory, Encoding.UTF8)) - { - xml.WriteTo(writer); - } - res.Body.Write(memory.ToArray(), 0, memory.ToArray().Length); - } + var xmlBytes = Encoding.UTF8.GetBytes(xml.ToString()); + res.Body.Write(xmlBytes, 0, xmlBytes.Length); } private static async Task SendAsync(TestServer server, string uri, string cookieHeader = null) diff --git a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs index ae7e6ce652..ae212e9c2a 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs @@ -176,7 +176,7 @@ namespace Microsoft.AspNet.Authentication.Facebook { Sender = req => { - if (req.RequestUri.GetLeftPart(UriPartial.Path) == FacebookDefaults.TokenEndpoint) + if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == FacebookDefaults.TokenEndpoint) { var res = new HttpResponseMessage(HttpStatusCode.OK); var tokenResponse = new Dictionary @@ -186,8 +186,8 @@ namespace Microsoft.AspNet.Authentication.Facebook res.Content = new FormUrlEncodedContent(tokenResponse); return res; } - if (req.RequestUri.GetLeftPart(UriPartial.Path) == - new Uri(customUserInfoEndpoint).GetLeftPart(UriPartial.Path)) + if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == + new Uri(customUserInfoEndpoint).GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped)) { finalUserInfoEndpoint = req.RequestUri.ToString(); var res = new HttpResponseMessage(HttpStatusCode.OK); diff --git a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs index 9a19a5635b..591e00cbd4 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs @@ -307,7 +307,7 @@ namespace Microsoft.AspNet.Authentication.Google token_type = "Bearer" }); } - else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://www.googleapis.com/plus/v1/people/me") + else if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == "https://www.googleapis.com/plus/v1/people/me") { return ReturnJsonResponse(new { @@ -497,7 +497,7 @@ namespace Microsoft.AspNet.Authentication.Google refresh_token = "Test Refresh Token" }); } - else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://www.googleapis.com/plus/v1/people/me") + else if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == "https://www.googleapis.com/plus/v1/people/me") { return ReturnJsonResponse(new { @@ -577,7 +577,7 @@ namespace Microsoft.AspNet.Authentication.Google refresh_token = "Test Refresh Token" }); } - else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://www.googleapis.com/plus/v1/people/me") + else if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == "https://www.googleapis.com/plus/v1/people/me") { return ReturnJsonResponse(new { @@ -667,7 +667,7 @@ namespace Microsoft.AspNet.Authentication.Google refresh_token = "Test Refresh Token" }); } - else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://www.googleapis.com/plus/v1/people/me") + else if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == "https://www.googleapis.com/plus/v1/people/me") { return ReturnJsonResponse(new { diff --git a/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs index f30474f522..2768a18c36 100644 --- a/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs @@ -126,7 +126,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount refresh_token = "Test Refresh Token" }); } - else if (req.RequestUri.GetLeftPart(UriPartial.Path) == "https://apis.live.net/v5.0/me") + else if (req.RequestUri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.UriEscaped) == "https://apis.live.net/v5.0/me") { return ReturnJsonResponse(new { diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs index 0e7cf68e16..4d7e42cb1e 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs @@ -19,7 +19,6 @@ using Microsoft.AspNet.TestHost; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.WebEncoders; using Microsoft.IdentityModel.Protocols.OpenIdConnect; -using Moq; using Xunit; namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect @@ -151,24 +150,43 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect private static void SetProtocolMessageOptions(OpenIdConnectOptions options) { - var mockOpenIdConnectMessage = new Mock(); - mockOpenIdConnectMessage.Setup(m => m.CreateAuthenticationRequestUrl()).Returns(ExpectedAuthorizeRequest); - mockOpenIdConnectMessage.Setup(m => m.CreateLogoutRequestUrl()).Returns(ExpectedLogoutRequest); + var fakeOpenIdRequestMessage = new FakeOpenIdConnectMessage(ExpectedAuthorizeRequest, ExpectedLogoutRequest); options.AutomaticChallenge = true; options.Events = new OpenIdConnectEvents() { OnRedirectToAuthenticationEndpoint = (context) => { - context.ProtocolMessage = mockOpenIdConnectMessage.Object; - return Task.FromResult(null); + context.ProtocolMessage = fakeOpenIdRequestMessage; + return Task.FromResult(0); }, OnRedirectToEndSessionEndpoint = (context) => { - context.ProtocolMessage = mockOpenIdConnectMessage.Object; - return Task.FromResult(null); + context.ProtocolMessage = fakeOpenIdRequestMessage; + return Task.FromResult(0); } }; } + private class FakeOpenIdConnectMessage : OpenIdConnectMessage + { + private readonly string _authorizeRequest; + private readonly string _logoutRequest; + + public FakeOpenIdConnectMessage(string authorizeRequest, string logoutRequest) + { + _authorizeRequest = authorizeRequest; + _logoutRequest = logoutRequest; + } + + public override string CreateAuthenticationRequestUrl() + { + return _authorizeRequest; + } + + public override string CreateLogoutRequestUrl() + { + return _logoutRequest; + } + } /// /// Tests for users who want to add 'state'. There are two ways to do it. diff --git a/test/Microsoft.AspNet.Authentication.Test/TestExtensions.cs b/test/Microsoft.AspNet.Authentication.Test/TestExtensions.cs index b406f5813f..8d3cdb7e29 100644 --- a/test/Microsoft.AspNet.Authentication.Test/TestExtensions.cs +++ b/test/Microsoft.AspNet.Authentication.Test/TestExtensions.cs @@ -60,14 +60,8 @@ namespace Microsoft.AspNet.Authentication new XAttribute("issuer", claim.Issuer)))); } } - using (var memory = new MemoryStream()) - { - using (var writer = new XmlTextWriter(memory, Encoding.UTF8)) - { - xml.WriteTo(writer); - } - res.Body.Write(memory.ToArray(), 0, memory.ToArray().Length); - } + var xmlBytes = Encoding.UTF8.GetBytes(xml.ToString()); + res.Body.Write(xmlBytes, 0, xmlBytes.Length); } } } diff --git a/test/Microsoft.AspNet.Authentication.Test/project.json b/test/Microsoft.AspNet.Authentication.Test/project.json index 7ec802b3ba..9b0c6a2375 100644 --- a/test/Microsoft.AspNet.Authentication.Test/project.json +++ b/test/Microsoft.AspNet.Authentication.Test/project.json @@ -13,14 +13,13 @@ "Microsoft.AspNet.DataProtection": "1.0.0-*", "Microsoft.AspNet.TestHost": "1.0.0-*", "Microsoft.AspNet.Testing": "1.0.0-*", - "Moq": "4.2.1312.1622", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "commands": { "test": "xunit.runner.aspnet" }, "frameworks": { - "dnx451": { - } + "dnx451": { }, + "dnxcore50": { } } } diff --git a/test/Microsoft.AspNet.CookiePolicy.Test/TestExtensions.cs b/test/Microsoft.AspNet.CookiePolicy.Test/TestExtensions.cs index 90b01af4b2..9cd07cb362 100644 --- a/test/Microsoft.AspNet.CookiePolicy.Test/TestExtensions.cs +++ b/test/Microsoft.AspNet.CookiePolicy.Test/TestExtensions.cs @@ -61,14 +61,8 @@ namespace Microsoft.AspNet.CookiePolicy new XAttribute("issuer", claim.Issuer)))); } } - using (var memory = new MemoryStream()) - { - using (var writer = new XmlTextWriter(memory, Encoding.UTF8)) - { - xml.WriteTo(writer); - } - res.Body.Write(memory.ToArray(), 0, memory.ToArray().Length); - } + var xmlBytes = Encoding.UTF8.GetBytes(xml.ToString()); + res.Body.Write(xmlBytes, 0, xmlBytes.Length); } } } diff --git a/test/Microsoft.AspNet.CookiePolicy.Test/project.json b/test/Microsoft.AspNet.CookiePolicy.Test/project.json index 6303a9f6ac..509e749160 100644 --- a/test/Microsoft.AspNet.CookiePolicy.Test/project.json +++ b/test/Microsoft.AspNet.CookiePolicy.Test/project.json @@ -1,17 +1,18 @@ { - "compilationOptions": { - "warningsAsErrors": true - }, - "dependencies": { - "Microsoft.AspNet.CookiePolicy": "1.0.0-*", - "Microsoft.AspNet.TestHost": "1.0.0-*", - "Microsoft.Extensions.DependencyInjection": "1.0.0-*", - "xunit.runner.aspnet": "2.0.0-aspnet-*" - }, - "commands": { - "test": "xunit.runner.aspnet" - }, - "frameworks": { - "dnx451": { } - } + "compilationOptions": { + "warningsAsErrors": true + }, + "dependencies": { + "Microsoft.AspNet.CookiePolicy": "1.0.0-*", + "Microsoft.AspNet.TestHost": "1.0.0-*", + "Microsoft.Extensions.DependencyInjection": "1.0.0-*", + "xunit.runner.aspnet": "2.0.0-aspnet-*" + }, + "commands": { + "test": "xunit.runner.aspnet" + }, + "frameworks": { + "dnx451": { }, + "dnxcore50": { } + } }