React to breaking in IRouteConstraint

This commit is contained in:
Ryan Nowak 2015-12-14 10:08:09 -08:00
parent ee6ef3f25f
commit ad3c460500
5 changed files with 36 additions and 37 deletions

View File

@ -22,7 +22,7 @@ namespace InlineConstraintSample.Web.Constraints
HttpContext httpContext,
IRouter route,
string routeKey,
IDictionary<string, object> values,
RouteValueDictionary values,
RouteDirection routeDirection)
{
object value;

View File

@ -17,7 +17,7 @@ namespace InlineConstraintSample.Web.Constraints
HttpContext httpContext,
IRouter route,
string routeKey,
IDictionary<string, object> values,
RouteValueDictionary values,
RouteDirection routeDirection)
{
object value;

View File

@ -2,7 +2,6 @@
// 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.Linq;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core;
@ -20,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.Routing
HttpContext httpContext,
IRouter route,
string routeKey,
IDictionary<string, object> values,
RouteValueDictionary values,
RouteDirection routeDirection)
{
if (httpContext == null)
@ -43,20 +42,20 @@ namespace Microsoft.AspNet.Mvc.Routing
throw new ArgumentNullException(nameof(values));
}
object value;
if (values.TryGetValue(routeKey, out value))
object obj;
if (values.TryGetValue(routeKey, out obj))
{
var valueAsString = value as string;
if (valueAsString != null)
var value = obj as string;
if (value != null)
{
var allValues = GetAndCacheAllMatchingValues(routeKey, httpContext);
var match = allValues.Any(existingRouteValue =>
existingRouteValue.Equals(
valueAsString,
StringComparison.OrdinalIgnoreCase));
return match;
foreach (var existingValue in allValues)
{
if (string.Equals(value, existingValue, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
}
}

View File

@ -104,8 +104,8 @@ namespace Microsoft.AspNet.Mvc.Description
var action = CreateActionDescriptor();
action.ActionConstraints = new List<IActionConstraintMetadata>()
{
new HttpMethodConstraint(new string[] { "PUT", "POST" }),
new HttpMethodConstraint(new string[] { "GET" }),
new ActionConstraints.HttpMethodConstraint(new string[] { "PUT", "POST" }),
new ActionConstraints.HttpMethodConstraint(new string[] { "GET" }),
};
// Act

View File

@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Mvc.Routing
public void RouteKey_DoesNotExist_MatchFails(string keyName, RouteDirection direction)
{
// Arrange
var values = new Dictionary<string, object>();
var values = new RouteValueDictionary();
var httpContext = GetHttpContext(new ActionDescriptor());
var route = Mock.Of<IRouter>();
@ -57,13 +57,13 @@ namespace Microsoft.AspNet.Mvc.Routing
actionDescriptor.RouteConstraints.Add(new RouteDataActionConstraint("randomKey", "testRandom"));
var httpContext = GetHttpContext(actionDescriptor);
var route = Mock.Of<IRouter>();
var values = new Dictionary<string, object>()
{
{ "area", "testArea" },
{ "controller", "testController" },
{ "action", "testAction" },
{ "randomKey", "testRandom" }
};
var values = new RouteValueDictionary()
{
{ "area", "testArea" },
{ "controller", "testController" },
{ "action", "testAction" },
{ "randomKey", "testRandom" }
};
// Act
var match = _constraint.Match(httpContext, route, keyName, values, direction);
@ -90,13 +90,13 @@ namespace Microsoft.AspNet.Mvc.Routing
actionDescriptor.RouteConstraints.Add(new RouteDataActionConstraint("randomKey", "testRandom"));
var httpContext = GetHttpContext(actionDescriptor);
var route = Mock.Of<IRouter>();
var values = new Dictionary<string, object>()
{
{ "area", "invalidTestArea" },
{ "controller", "invalidTestController" },
{ "action", "invalidTestAction" },
{ "randomKey", "invalidTestRandom" }
};
var values = new RouteValueDictionary()
{
{ "area", "invalidTestArea" },
{ "controller", "invalidTestController" },
{ "action", "invalidTestAction" },
{ "randomKey", "invalidTestRandom" }
};
// Act
var match = _constraint.Match(httpContext, route, keyName, values, direction);
@ -115,10 +115,10 @@ namespace Microsoft.AspNet.Mvc.Routing
action: null);
var httpContext = GetHttpContext(actionDescriptor);
var route = Mock.Of<IRouter>();
var values = new Dictionary<string, object>()
{
{ "area", 12 },
};
var values = new RouteValueDictionary()
{
{ "area", 12 },
};
// Act
var match = _constraint.Match(httpContext, route, "area", values, direction);
@ -145,7 +145,7 @@ namespace Microsoft.AspNet.Mvc.Routing
httpContext.Object,
Mock.Of<IRouter>(),
"area",
new Dictionary<string, object> { { "area", "area" } },
new RouteValueDictionary { { "area", "area" } },
direction));
var providerName = actionDescriptorCollectionProvider.GetType().FullName;
Assert.Equal(