From 2388cca5ac7e8ab83f4c7b46145c90e9966403a7 Mon Sep 17 00:00:00 2001 From: Kiran Challa Date: Thu, 20 Apr 2017 14:16:27 -0700 Subject: [PATCH] Workaround for issue https://github.com/aspnet/Routing/issues/390 --- Routing.sln | 2 ++ build/dependencies.props | 2 +- .../RegexInlineRouteConstraintTests.cs | 6 ++--- .../Constraints/RegexRouteConstraintTests.cs | 8 +++---- .../RequiredRouteConstraintTests.cs | 8 +++---- .../Constraints/StringRouteConstraintTest.cs | 14 +++++------ .../RouteTest.cs | 24 ++++++++++--------- 7 files changed, 34 insertions(+), 30 deletions(-) diff --git a/Routing.sln b/Routing.sln index b33d769cd7..45e1b47f05 100644 --- a/Routing.sln +++ b/Routing.sln @@ -31,7 +31,9 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{6DC6B416-C8C4-4BFA-8C1E-A55A6D7EFD08}" ProjectSection(SolutionItems) = preProject build\common.props = build\common.props + build\dependencies.props = build\dependencies.props build\Key.snk = build\Key.snk + build\repo.props = build\repo.props EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Routing.Performance", "test\Microsoft.AspNetCore.Routing.Performance\Microsoft.AspNetCore.Routing.Performance.csproj", "{F3D86714-4E64-41A6-9B36-A47B3683CF5D}" diff --git a/build/dependencies.props b/build/dependencies.props index 4f7bf7b77f..0ed9d08d06 100644 --- a/build/dependencies.props +++ b/build/dependencies.props @@ -4,7 +4,7 @@ 0.10.3 4.3.0 2.0.0-* - 4.6.36-alpha + 4.7.1 1.6.1 2.0.0-* 15.0.0 diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Constraints/RegexInlineRouteConstraintTests.cs b/test/Microsoft.AspNetCore.Routing.Tests/Constraints/RegexInlineRouteConstraintTests.cs index 2c430d17b1..a87f6519c7 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Constraints/RegexInlineRouteConstraintTests.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Constraints/RegexInlineRouteConstraintTests.cs @@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Act var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "controller", values: values, @@ -48,7 +48,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Act var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "controller", values: values, @@ -78,7 +78,7 @@ namespace Microsoft.AspNetCore.Routing.Tests { // Act var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "controller", values: values, diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Constraints/RegexRouteConstraintTests.cs b/test/Microsoft.AspNetCore.Routing.Tests/Constraints/RegexRouteConstraintTests.cs index e8dc1e34dc..7affd5c034 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Constraints/RegexRouteConstraintTests.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Constraints/RegexRouteConstraintTests.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Act var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "controller", values: values, @@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Act var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "controller", values: values, @@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Act var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "controller", values: values, @@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Act var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "controller", values: values, diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Constraints/RequiredRouteConstraintTests.cs b/test/Microsoft.AspNetCore.Routing.Tests/Constraints/RequiredRouteConstraintTests.cs index a437f77096..31ec2b2bf0 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Constraints/RequiredRouteConstraintTests.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Constraints/RequiredRouteConstraintTests.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Act var result = constraint.Match( - Mock.Of(), + new DefaultHttpContext(), Mock.Of(), "area", new RouteValueDictionary(new { controller = "Home", action = "Index" }), @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Act var result = constraint.Match( - Mock.Of(), + new DefaultHttpContext(), Mock.Of(), "area", new RouteValueDictionary(new { controller = "Home", action = "Index", area = (string)null }), @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Act var result = constraint.Match( - Mock.Of(), + new DefaultHttpContext(), Mock.Of(), "area", new RouteValueDictionary(new { controller = "Home", action = "Index", area = string.Empty}), @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Routing.Tests // Act var result = constraint.Match( - Mock.Of(), + new DefaultHttpContext(), Mock.Of(), "area", new RouteValueDictionary(new { controller = "Home", action = "Index", area = "Store" }), diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Constraints/StringRouteConstraintTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/Constraints/StringRouteConstraintTest.cs index 006ce0d382..9e9f178286 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Constraints/StringRouteConstraintTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Constraints/StringRouteConstraintTest.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints var values = new RouteValueDictionary(new { controller = "home" }); var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "controller", values: values, @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints var values = new RouteValueDictionary(new { controller = "home" }); var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "controller", values: values, @@ -60,7 +60,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints var values = new RouteValueDictionary(new { controller = "home" }); var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "controller", values: values, @@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints var values = new RouteValueDictionary(new { controller = "home" }); var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "controller", values: values, @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints var values = new RouteValueDictionary(new { controller = "admin" }); var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "action", values: values, @@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints var values = new RouteValueDictionary(new { controller = "admin" }); var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "action", values: values, @@ -144,7 +144,7 @@ namespace Microsoft.AspNetCore.Routing.Constraints var values = new RouteValueDictionary(new { controller = routeValue }); var match = constraint.Match( - httpContext: Mock.Of(), + new DefaultHttpContext(), route: new Mock().Object, routeKey: "controller", values: values, diff --git a/test/Microsoft.AspNetCore.Routing.Tests/RouteTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/RouteTest.cs index db2b01ddf8..2da6ba4957 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/RouteTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/RouteTest.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // 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 System.Threading.Tasks; @@ -14,6 +13,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.ObjectPool; +using Microsoft.Extensions.Options; using Moq; using Xunit; @@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Routing Assert.NotNull(exception.InnerException); expected = "The constraint entry 'p1' - 'regex(abc' on the route " + "'{controller}/{action}/ {p1:regex(abc} ' could not be resolved by the constraint resolver of type " + - "'IInlineConstraintResolverProxy'."; + $"'{nameof(DefaultInlineConstraintResolver)}'."; Assert.Equal(expected, exception.InnerException.Message); } @@ -1704,15 +1704,12 @@ namespace Microsoft.AspNetCore.Routing private static IInlineConstraintResolver GetInlineConstraintResolver() { - var resolverMock = new Mock(); - resolverMock.Setup(o => o.ResolveConstraint("int")).Returns(new IntRouteConstraint()); - resolverMock.Setup(o => o.ResolveConstraint("range(1,20)")).Returns(new RangeRouteConstraint(1, 20)); - resolverMock.Setup(o => o.ResolveConstraint("alpha")).Returns(new AlphaRouteConstraint()); - resolverMock.Setup(o => o.ResolveConstraint(@"regex(^\d{3}-\d{3}-\d{4}$)")).Returns( - new RegexInlineRouteConstraint(@"^\d{3}-\d{3}-\d{4}$")); - resolverMock.Setup(o => o.ResolveConstraint(@"regex(^\d{1,2}\/\d{1,2}\/\d{4}$)")).Returns( - new RegexInlineRouteConstraint(@"^\d{1,2}\/\d{1,2}\/\d{4}$")); - return resolverMock.Object; + var routeOptions = new Mock>(); + routeOptions + .SetupGet(o => o.Value) + .Returns(new RouteOptions()); + + return new DefaultInlineConstraintResolver(routeOptions.Object); } private class CapturingConstraint : IRouteConstraint @@ -1730,5 +1727,10 @@ namespace Microsoft.AspNetCore.Routing return true; } } + + private class TestRouteOptions : IOptions + { + public RouteOptions Value => new RouteOptions(); + } } }