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