Updating Microsoft.AspNet.Mvc.Core.Test to work on Mono
This commit is contained in:
parent
1c8582d77a
commit
38e82c0aa5
|
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Core.Test
|
||||
|
|
@ -94,13 +95,12 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
var actionParameters = new Dictionary<string, object> { { "i", inputParam1 }, { "s", inputParam2 } };
|
||||
|
||||
var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskActionWithException);
|
||||
await AssertThrowsAsync<NotImplementedException>(
|
||||
async () =>
|
||||
await ReflectedActionExecutor.ExecuteAsync(
|
||||
methodWithTaskOfIntReturnType.GetMethodInfo(),
|
||||
_controller,
|
||||
actionParameters),
|
||||
"Not Implemented Exception");
|
||||
|
||||
// Act and Assert
|
||||
await Assert.ThrowsAsync<NotImplementedException>(
|
||||
() => ReflectedActionExecutor.ExecuteAsync(methodWithTaskOfIntReturnType.GetMethodInfo(),
|
||||
_controller,
|
||||
actionParameters));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -111,13 +111,10 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
var actionParameters = new Dictionary<string, object> { { "i", inputParam1 }, { "s", inputParam2 } };
|
||||
|
||||
var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskActionWithExceptionWithoutAsync);
|
||||
await AssertThrowsAsync<NotImplementedException>(
|
||||
async () =>
|
||||
await ReflectedActionExecutor.ExecuteAsync(
|
||||
methodWithTaskOfIntReturnType.GetMethodInfo(),
|
||||
_controller,
|
||||
actionParameters),
|
||||
"Not Implemented Exception");
|
||||
await Assert.ThrowsAsync<NotImplementedException>(
|
||||
() => ReflectedActionExecutor.ExecuteAsync(methodWithTaskOfIntReturnType.GetMethodInfo(),
|
||||
_controller,
|
||||
actionParameters));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -249,6 +246,8 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
_controller,
|
||||
actionParameters),
|
||||
expectedException);
|
||||
|
||||
Assert.Equal(expectedException, ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -275,9 +274,11 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
|
||||
var actionParameters = new Dictionary<string, object> { { "i", "Some Invalid Value" }, { "s", inputParam2 } };
|
||||
var methodWithTaskOfIntReturnType = new MethodWithTaskOfIntReturnType(_controller.TaskValueTypeAction);
|
||||
var message = TestPlatformHelper.IsMono ? "Object type {0} cannot be converted to target type: {1}" :
|
||||
"Object of type '{0}' cannot be converted to type '{1}'.";
|
||||
var expectedException = string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
"Object of type '{0}' cannot be converted to type '{1}'.",
|
||||
message,
|
||||
typeof (string),
|
||||
typeof (int));
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
// Act & Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => options.CookieName = null);
|
||||
Assert.Equal("The 'CookieName' property of 'Microsoft.AspNet.Mvc.AntiForgeryOptions' must not be null." +
|
||||
"\r\nParameter name: value", ex.Message);
|
||||
Environment.NewLine + "Parameter name: value", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -29,7 +29,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
// Act & Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => options.FormFieldName = null);
|
||||
Assert.Equal("The 'FormFieldName' property of 'Microsoft.AspNet.Mvc.AntiForgeryOptions' must not be null." +
|
||||
"\r\nParameter name: value", ex.Message);
|
||||
Environment.NewLine + "Parameter name: value", ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
|
@ -392,12 +391,10 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
|
||||
private Mock<HttpContext> GetHttpContext(bool setupResponse = true)
|
||||
{
|
||||
var identity = new GenericIdentity("some-user");
|
||||
var identity = new ClaimsIdentity("some-auth");
|
||||
var mockHttpContext = new Mock<HttpContext>();
|
||||
|
||||
mockHttpContext.Setup(o => o.User)
|
||||
.Returns(new GenericPrincipal(identity, new string[0]));
|
||||
|
||||
.Returns(new ClaimsPrincipal(identity));
|
||||
|
||||
if (setupResponse)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -62,11 +62,11 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
[Fact]
|
||||
public void DefaultUniqueClaimTypes_NotPresent_SerializesAllClaimTypes()
|
||||
{
|
||||
var identity = new MockClaimsIdentity();
|
||||
identity.AddClaim(ClaimTypes.Email, "someone@antifrogery.com");
|
||||
identity.AddClaim(ClaimTypes.GivenName, "some");
|
||||
identity.AddClaim(ClaimTypes.Surname, "one");
|
||||
identity.AddClaim(ClaimTypes.NameIdentifier, String.Empty);
|
||||
var identity = new ClaimsIdentity();
|
||||
identity.AddClaim(new Claim(ClaimTypes.Email, "someone@antifrogery.com"));
|
||||
identity.AddClaim(new Claim(ClaimTypes.GivenName, "some"));
|
||||
identity.AddClaim(new Claim(ClaimTypes.Surname, "one"));
|
||||
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, String.Empty));
|
||||
|
||||
// Arrange
|
||||
var claimsIdentity = (ClaimsIdentity)identity;
|
||||
|
|
@ -90,9 +90,9 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public void DefaultUniqueClaimTypes_Present()
|
||||
{
|
||||
// Arrange
|
||||
var identity = new MockClaimsIdentity();
|
||||
identity.AddClaim("fooClaim", "fooClaimValue");
|
||||
identity.AddClaim(ClaimTypes.NameIdentifier, "nameIdentifierValue");
|
||||
var identity = new ClaimsIdentity();
|
||||
identity.AddClaim(new Claim("fooClaim", "fooClaimValue"));
|
||||
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "nameIdentifierValue"));
|
||||
|
||||
// Act
|
||||
var uniqueIdentifierParameters = DefaultClaimUidExtractor.GetUniqueIdentifierParameters(identity);
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
// 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.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Core.Test
|
||||
{
|
||||
// Convenient class for mocking a ClaimsIdentity instance given some
|
||||
// prefabricated Claim instances.
|
||||
internal sealed class MockClaimsIdentity : ClaimsIdentity
|
||||
{
|
||||
private readonly List<Claim> _claims = new List<Claim>();
|
||||
|
||||
public void AddClaim(string claimType, string value)
|
||||
{
|
||||
_claims.Add(new Claim(claimType, value));
|
||||
}
|
||||
|
||||
public override IEnumerable<Claim> Claims
|
||||
{
|
||||
get { return _claims; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,8 +3,10 @@
|
|||
|
||||
using System;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Principal;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.PipelineCore;
|
||||
using Microsoft.AspNet.Security.DataProtection;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
|
@ -135,7 +137,10 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
var config = new AntiForgeryOptions();
|
||||
|
||||
byte[] data = new byte[256 / 8];
|
||||
CryptRand.FillBuffer(new ArraySegment<byte>(data));
|
||||
using (var rng = RandomNumberGenerator.Create())
|
||||
{
|
||||
rng.GetBytes(data);
|
||||
}
|
||||
var base64ClaimUId = Convert.ToBase64String(data);
|
||||
var expectedClaimUid = new BinaryBlob(256, data);
|
||||
|
||||
|
|
@ -370,7 +375,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
{
|
||||
// Arrange
|
||||
var httpContext = new Mock<HttpContext>().Object;
|
||||
ClaimsIdentity identity = new GenericIdentity(identityUsername);
|
||||
var identity = GetAuthenticatedIdentity(identityUsername);
|
||||
var sessionToken = new AntiForgeryToken() { IsSessionToken = true };
|
||||
var fieldtoken = new AntiForgeryToken()
|
||||
{
|
||||
|
|
@ -402,7 +407,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
{
|
||||
// Arrange
|
||||
var httpContext = new Mock<HttpContext>().Object;
|
||||
ClaimsIdentity identity = new GenericIdentity("the-user");
|
||||
var identity = GetAuthenticatedIdentity("the-user");
|
||||
var sessionToken = new AntiForgeryToken() { IsSessionToken = true };
|
||||
var fieldtoken = new AntiForgeryToken()
|
||||
{
|
||||
|
|
@ -435,7 +440,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
{
|
||||
// Arrange
|
||||
var httpContext = new Mock<HttpContext>().Object;
|
||||
ClaimsIdentity identity = new GenericIdentity(String.Empty);
|
||||
var identity = new ClaimsIdentity();
|
||||
var sessionToken = new AntiForgeryToken() { IsSessionToken = true };
|
||||
var fieldtoken = new AntiForgeryToken()
|
||||
{
|
||||
|
|
@ -467,7 +472,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
{
|
||||
// Arrange
|
||||
var httpContext = new Mock<HttpContext>().Object;
|
||||
ClaimsIdentity identity = new GenericIdentity(String.Empty);
|
||||
var identity = new ClaimsIdentity();
|
||||
var sessionToken = new AntiForgeryToken() { IsSessionToken = true };
|
||||
var fieldtoken = new AntiForgeryToken()
|
||||
{
|
||||
|
|
@ -499,7 +504,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
{
|
||||
// Arrange
|
||||
var httpContext = new Mock<HttpContext>().Object;
|
||||
ClaimsIdentity identity = new GenericIdentity("the-user");
|
||||
var identity = GetAuthenticatedIdentity("the-user");
|
||||
var sessionToken = new AntiForgeryToken() { IsSessionToken = true };
|
||||
var fieldtoken = new AntiForgeryToken()
|
||||
{
|
||||
|
|
@ -531,7 +536,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
{
|
||||
// Arrange
|
||||
var httpContext = new Mock<HttpContext>().Object;
|
||||
ClaimsIdentity identity = new GenericIdentity("the-user");
|
||||
var identity = GetAuthenticatedIdentity("the-user");
|
||||
var sessionToken = new AntiForgeryToken() { IsSessionToken = true };
|
||||
var fieldtoken = new AntiForgeryToken()
|
||||
{
|
||||
|
|
@ -558,6 +563,12 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
// Nothing to assert - if we got this far, success!
|
||||
}
|
||||
|
||||
private static ClaimsIdentity GetAuthenticatedIdentity(string identityUsername)
|
||||
{
|
||||
var claim = new Claim(ClaimsIdentity.DefaultNameClaimType, identityUsername);
|
||||
return new ClaimsIdentity(new[] { claim }, "Some-Authentication");
|
||||
}
|
||||
|
||||
private sealed class MyAuthenticatedIdentityWithoutUsername : ClaimsIdentity
|
||||
{
|
||||
public override bool IsAuthenticated
|
||||
|
|
|
|||
|
|
@ -181,7 +181,9 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToAction_WithParameterActionControllerRouteValues_SetsResultProperties(object routeValues)
|
||||
public void RedirectToAction_WithParameterActionControllerRouteValues_SetsResultProperties(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -194,13 +196,14 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal("SampleAction", resultTemporary.ActionName);
|
||||
Assert.Equal("SampleController", resultTemporary.ControllerName);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultTemporary.RouteValues);
|
||||
Assert.Equal(expected, resultTemporary.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToActionPermanent_WithParameterActionControllerRouteValues_SetsResultProperties(
|
||||
object routeValues)
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -216,12 +219,14 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal("SampleAction", resultPermanent.ActionName);
|
||||
Assert.Equal("SampleController", resultPermanent.ControllerName);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultPermanent.RouteValues);
|
||||
Assert.Equal(expected, resultPermanent.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToAction_WithParameterActionAndRouteValues_SetsResultProperties(object routeValues)
|
||||
public void RedirectToAction_WithParameterActionAndRouteValues_SetsResultProperties(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -233,13 +238,14 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Null(resultTemporary.ActionName);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultTemporary.RouteValues);
|
||||
Assert.Equal(expected, resultTemporary.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToActionPermanent_WithParameterActionAndRouteValues_SetsResultProperties(
|
||||
object routeValues)
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -251,12 +257,14 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Null(resultPermanent.ActionName);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultPermanent.RouteValues);
|
||||
Assert.Equal(expected, resultPermanent.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToRoute_WithParameterRouteValues_SetsResultEqualRouteValues(object routeValues)
|
||||
public void RedirectToRoute_WithParameterRouteValues_SetsResultEqualRouteValues(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -267,13 +275,14 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultTemporary.RouteValues);
|
||||
Assert.Equal(expected, resultTemporary.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToRoutePermanent_WithParameterRouteValues_SetsResultEqualRouteValuesAndPermanent(
|
||||
object routeValues)
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -284,7 +293,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultPermanent.RouteValues);
|
||||
Assert.Equal(expected, resultPermanent.RouteValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -322,7 +331,8 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToRoute_WithParameterRouteNameAndRouteValues_SetsResultSameRouteNameAndRouteValues(
|
||||
object routeValues)
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -335,13 +345,14 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
Assert.IsType<RedirectToRouteResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Same(routeName, resultTemporary.RouteName);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultTemporary.RouteValues);
|
||||
Assert.Equal(expected, resultTemporary.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToRoutePermanent_WithParameterRouteNameAndRouteValues_SetsResultProperties(
|
||||
object routeValues)
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -354,7 +365,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
Assert.IsType<RedirectToRouteResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Same(routeName, resultPermanent.RouteName);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultPermanent.RouteValues);
|
||||
Assert.Equal(expected, resultPermanent.RouteValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -524,19 +535,29 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
{
|
||||
get
|
||||
{
|
||||
yield return new object[] { null };
|
||||
yield return new object[]
|
||||
{
|
||||
new Dictionary<string, string>() { { "hello", "world" } },
|
||||
};
|
||||
{
|
||||
null,
|
||||
Enumerable.Empty<KeyValuePair<string, object>>()
|
||||
};
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
new RouteValueDictionary(new Dictionary<string, string>()
|
||||
{
|
||||
{ "test", "case" },
|
||||
{ "sample", "route" },
|
||||
}),
|
||||
};
|
||||
{
|
||||
new Dictionary<string, object> { { "hello", "world" } },
|
||||
new[] { new KeyValuePair<string, object>("hello", "world") }
|
||||
};
|
||||
|
||||
var expected2 = new Dictionary<string, object>
|
||||
{
|
||||
{ "test", "case" },
|
||||
{ "sample", "route" },
|
||||
};
|
||||
|
||||
yield return new object[]
|
||||
{
|
||||
new RouteValueDictionary(expected2),
|
||||
expected2
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var action = Assert.Single(actionInfos);
|
||||
Assert.Equal("Details", action.ActionName);
|
||||
Assert.True(action.RequireActionNameMatch);
|
||||
Assert.Equal(new[] { "POST", "GET" }, action.HttpMethods);
|
||||
Assert.Equal(new[] { "GET", "POST" }, action.HttpMethods.OrderBy(m => m, StringComparer.Ordinal));
|
||||
Assert.Null(action.AttributeRoute);
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +242,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var action = Assert.Single(actionInfos);
|
||||
Assert.Equal("List", action.ActionName);
|
||||
Assert.True(action.RequireActionNameMatch);
|
||||
Assert.Equal(new[] { "GET", "PUT", "POST" }, action.HttpMethods);
|
||||
Assert.Equal(new[] { "GET", "POST", "PUT"}, action.HttpMethods.OrderBy(m => m, StringComparer.Ordinal));
|
||||
Assert.Null(action.AttributeRoute);
|
||||
}
|
||||
|
||||
|
|
@ -310,7 +310,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
Assert.Equal("List", action.ActionName);
|
||||
Assert.True(action.RequireActionNameMatch);
|
||||
|
||||
Assert.Equal(new[] { "GET", "HEAD" }, action.HttpMethods);
|
||||
Assert.Equal(new[] { "GET", "HEAD" }, action.HttpMethods.OrderBy(m => m, StringComparer.Ordinal));
|
||||
|
||||
Assert.NotNull(action.AttributeRoute);
|
||||
Assert.Equal("ListAll", action.AttributeRoute.Template);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ using System.Threading.Tasks;
|
|||
using System.Xml;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -181,6 +182,12 @@ namespace Microsoft.AspNet.Mvc
|
|||
[Fact]
|
||||
public async Task XmlDataContractSerializerFormatterThrowsOnExceededMaxDepth()
|
||||
{
|
||||
if (TestPlatformHelper.IsMono)
|
||||
{
|
||||
// ReaderQuotas are not honored on Mono
|
||||
return;
|
||||
}
|
||||
|
||||
// Arrange
|
||||
var input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<TestLevelTwo><SampleString>test</SampleString>" +
|
||||
|
|
@ -198,6 +205,12 @@ namespace Microsoft.AspNet.Mvc
|
|||
[Fact]
|
||||
public async Task XmlDataContractSerializerFormatterThrowsWhenReaderQuotasAreChanged()
|
||||
{
|
||||
if (TestPlatformHelper.IsMono)
|
||||
{
|
||||
// ReaderQuotas are not honored on Mono
|
||||
return;
|
||||
}
|
||||
|
||||
// Arrange
|
||||
var input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<TestLevelTwo><SampleString>test</SampleString>" +
|
||||
|
|
@ -244,6 +257,11 @@ namespace Microsoft.AspNet.Mvc
|
|||
public async Task XmlDataContractSerializerFormatterThrowsOnInvalidCharacters()
|
||||
{
|
||||
// Arrange
|
||||
var expectedException = TestPlatformHelper.IsMono ? typeof(SerializationException) :
|
||||
typeof(XmlException);
|
||||
var expectedMessage = TestPlatformHelper.IsMono ?
|
||||
"Expected element 'TestLevelTwo' in namespace '', but found Element node 'DummyClass' in namespace ''" :
|
||||
"The encoding in the declaration 'UTF-8' does not match the encoding of the document 'utf-16LE'.";
|
||||
var inpStart = Encodings.UTF16EncodingLittleEndian.GetBytes("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<DummyClass><SampleInt>");
|
||||
byte[] inp = { 192, 193 };
|
||||
|
|
@ -258,7 +276,8 @@ namespace Microsoft.AspNet.Mvc
|
|||
var context = GetInputFormatterContext(contentBytes, typeof(TestLevelTwo));
|
||||
|
||||
// Act
|
||||
await Assert.ThrowsAsync(typeof(XmlException), async () => await formatter.ReadAsync(context));
|
||||
var ex = await Assert.ThrowsAsync(expectedException, () => formatter.ReadAsync(context));
|
||||
Assert.Equal(expectedMessage, ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ namespace Microsoft.AspNet.Mvc.Core
|
|||
"<DummyClass xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
|
||||
"<SampleInt>10</SampleInt></DummyClass>" };
|
||||
yield return new object[] { new Dictionary<string, string>() { { "Hello", "World" } },
|
||||
"<ArrayOfKeyValueOfstringstring xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" " +
|
||||
"xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\"><KeyValueOfstringstring>" +
|
||||
"<ArrayOfKeyValueOfstringstring xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" " +
|
||||
"xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\"><KeyValueOfstringstring>" +
|
||||
"<Key>Hello</Key><Value>World</Value></KeyValueOfstringstring></ArrayOfKeyValueOfstringstring>" };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ using System.Threading.Tasks;
|
|||
using System.Xml;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -180,6 +181,12 @@ namespace Microsoft.AspNet.Mvc
|
|||
[Fact]
|
||||
public async Task XmlSerializerFormatterThrowsOnExceededMaxDepth()
|
||||
{
|
||||
if (TestPlatformHelper.IsMono)
|
||||
{
|
||||
// ReaderQuotas are not honored on Mono
|
||||
return;
|
||||
}
|
||||
|
||||
// Arrange
|
||||
var input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<TestLevelTwo><SampleString>test</SampleString>" +
|
||||
|
|
@ -193,12 +200,18 @@ namespace Microsoft.AspNet.Mvc
|
|||
var context = GetInputFormatterContext(contentBytes, typeof(TestLevelTwo));
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync(typeof(InvalidOperationException), async () => await formatter.ReadAsync(context));
|
||||
await Assert.ThrowsAsync(typeof(InvalidOperationException), () => formatter.ReadAsync(context));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task XmlSerializerFormatterThrowsWhenReaderQuotasAreChanged()
|
||||
{
|
||||
if (TestPlatformHelper.IsMono)
|
||||
{
|
||||
// ReaderQuotas are not honored on Mono
|
||||
return;
|
||||
}
|
||||
|
||||
// Arrange
|
||||
var input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<TestLevelTwo><SampleString>test</SampleString>" +
|
||||
|
|
@ -212,7 +225,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var context = GetInputFormatterContext(contentBytes, typeof(TestLevelTwo));
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync(typeof(InvalidOperationException), async () => await formatter.ReadAsync(context));
|
||||
await Assert.ThrowsAsync(typeof(InvalidOperationException), () => formatter.ReadAsync(context));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -247,6 +260,12 @@ namespace Microsoft.AspNet.Mvc
|
|||
public async Task XmlSerializerFormatterThrowsOnInvalidCharacters()
|
||||
{
|
||||
// Arrange
|
||||
var expectedException = TestPlatformHelper.IsMono ? typeof(InvalidOperationException) :
|
||||
typeof(XmlException);
|
||||
var expectedMessage = TestPlatformHelper.IsMono ?
|
||||
"There is an error in XML document." :
|
||||
"The encoding in the declaration 'UTF-8' does not match the encoding of the document 'utf-16LE'.";
|
||||
|
||||
var inpStart = Encodings.UTF16EncodingLittleEndian.GetBytes("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
|
||||
"<DummyClass><SampleInt>");
|
||||
byte[] inp = { 192, 193 };
|
||||
|
|
@ -260,8 +279,9 @@ namespace Microsoft.AspNet.Mvc
|
|||
var formatter = new XmlSerializerInputFormatter();
|
||||
var context = GetInputFormatterContext(contentBytes, typeof(TestLevelTwo));
|
||||
|
||||
// Act
|
||||
await Assert.ThrowsAsync(typeof(XmlException), async () => await formatter.ReadAsync(context));
|
||||
// Act and Assert
|
||||
var ex = await Assert.ThrowsAsync(expectedException, () => formatter.ReadAsync(context));
|
||||
Assert.Equal(expectedMessage, ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
// Act & Assert
|
||||
var ex = Assert.Throws<ArgumentNullException>(() => options.AntiForgeryOptions = null);
|
||||
Assert.Equal("The 'AntiForgeryOptions' property of 'Microsoft.AspNet.Mvc.MvcOptions' must not be null." +
|
||||
"\r\nParameter name: value", ex.Message);
|
||||
Environment.NewLine + "Parameter name: value", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using System.ComponentModel.DataAnnotations;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -50,6 +51,8 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
public async Task TryUpdateModel_ReturnsFalse_IfModelValidationFails()
|
||||
{
|
||||
// Arrange
|
||||
var expectedMessage = TestPlatformHelper.IsMono ? "The field MyProperty is invalid." :
|
||||
"The MyProperty field is required.";
|
||||
var binders = new IModelBinder[]
|
||||
{
|
||||
new TypeConverterModelBinder(),
|
||||
|
|
@ -79,8 +82,8 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
Assert.Equal("The MyProperty field is required.",
|
||||
modelStateDictionary["MyProperty"].Errors[0].ErrorMessage);
|
||||
var error = Assert.Single(modelStateDictionary["MyProperty"].Errors);
|
||||
Assert.Equal(expectedMessage, error.ErrorMessage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
() => provider.GetDescriptors());
|
||||
|
||||
// Act
|
||||
Assert.Equal(expectedExceptionMessage, ex.Message);
|
||||
VerifyMultiLineError(expectedExceptionMessage, ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -601,7 +601,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
var ex = Assert.Throws<InvalidOperationException>(() => { provider.GetDescriptors(); });
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedMessage, ex.Message);
|
||||
VerifyMultiLineError(expectedMessage, ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -806,7 +806,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
var exception = Assert.Throws<InvalidOperationException>(() => provider.GetDescriptors());
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedMessage, exception.Message);
|
||||
VerifyMultiLineError(expectedMessage, exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -1190,6 +1190,16 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
return provider.GetDescriptors();
|
||||
}
|
||||
|
||||
private static void VerifyMultiLineError(string expectedMessage, string actualMessage)
|
||||
{
|
||||
// The error message depends on the order of attributes returned by reflection which is not consistent across
|
||||
// platforms. We'll compare them individually instead.
|
||||
Assert.Equal(expectedMessage.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
|
||||
.OrderBy(m => m, StringComparer.Ordinal),
|
||||
actualMessage.Split(new[] { Environment.NewLine }, StringSplitOptions.None)
|
||||
.OrderBy(m => m, StringComparer.Ordinal));
|
||||
}
|
||||
|
||||
private class HttpMethodController
|
||||
{
|
||||
[HttpPost]
|
||||
|
|
|
|||
|
|
@ -125,11 +125,28 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
Assert.Equal(expected, memoryStream.ToArray());
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ExecuteResultAsync_DoesNotWriteToResponse_OnceExceptionIsThrownData
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new object[] { 30, 0 };
|
||||
|
||||
if (PlatformHelper.IsMono)
|
||||
{
|
||||
// The StreamWriter in Mono buffers 2x the buffer size before flushing.
|
||||
yield return new object[] { ViewResultStreamWriterBufferSize * 2 + 30, ViewResultStreamWriterBufferSize };
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return new object[] { ViewResultStreamWriterBufferSize + 30, ViewResultStreamWriterBufferSize };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The StreamWriter used by ViewResult an internal buffer and consequently anything written to this buffer
|
||||
// prior to it filling up will not be written to the underlying stream once an exception is thrown.
|
||||
[Theory]
|
||||
[InlineData(30, 0)]
|
||||
[InlineData(ViewResultStreamWriterBufferSize + 30, ViewResultStreamWriterBufferSize)]
|
||||
[MemberData(nameof(ExecuteResultAsync_DoesNotWriteToResponse_OnceExceptionIsThrownData))]
|
||||
public async Task ExecuteResultAsync_DoesNotWriteToResponse_OnceExceptionIsThrown(int writtenLength, int expectedLength)
|
||||
{
|
||||
// Arrange
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"compilationOptions": {
|
||||
"warningsAsErrors": true
|
||||
"warningsAsErrors": "true"
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Http": "1.0.0-*",
|
||||
|
|
|
|||
Loading…
Reference in New Issue