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, HttpContext httpContext,
IRouter route, IRouter route,
string routeKey, string routeKey,
IDictionary<string, object> values, RouteValueDictionary values,
RouteDirection routeDirection) RouteDirection routeDirection)
{ {
object value; object value;

View File

@ -17,7 +17,7 @@ namespace InlineConstraintSample.Web.Constraints
HttpContext httpContext, HttpContext httpContext,
IRouter route, IRouter route,
string routeKey, string routeKey,
IDictionary<string, object> values, RouteValueDictionary values,
RouteDirection routeDirection) RouteDirection routeDirection)
{ {
object value; 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
@ -20,7 +19,7 @@ namespace Microsoft.AspNet.Mvc.Routing
HttpContext httpContext, HttpContext httpContext,
IRouter route, IRouter route,
string routeKey, string routeKey,
IDictionary<string, object> values, RouteValueDictionary values,
RouteDirection routeDirection) RouteDirection routeDirection)
{ {
if (httpContext == null) if (httpContext == null)
@ -43,20 +42,20 @@ namespace Microsoft.AspNet.Mvc.Routing
throw new ArgumentNullException(nameof(values)); throw new ArgumentNullException(nameof(values));
} }
object value; object obj;
if (values.TryGetValue(routeKey, out value)) if (values.TryGetValue(routeKey, out obj))
{ {
var valueAsString = value as string; var value = obj as string;
if (value != null)
if (valueAsString != null)
{ {
var allValues = GetAndCacheAllMatchingValues(routeKey, httpContext); var allValues = GetAndCacheAllMatchingValues(routeKey, httpContext);
var match = allValues.Any(existingRouteValue => foreach (var existingValue in allValues)
existingRouteValue.Equals( {
valueAsString, if (string.Equals(value, existingValue, StringComparison.OrdinalIgnoreCase))
StringComparison.OrdinalIgnoreCase)); {
return true;
return match; }
}
} }
} }

View File

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

View File

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