diff --git a/test/Microsoft.AspNetCore.Routing.Tests/Constraints/ConstraintsTestHelper.cs b/test/Microsoft.AspNetCore.Routing.Tests/Constraints/ConstraintsTestHelper.cs index a86c7f4910..6e0d7e7e0d 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/Constraints/ConstraintsTestHelper.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/Constraints/ConstraintsTestHelper.cs @@ -10,21 +10,12 @@ namespace Microsoft.AspNetCore.Routing.Tests { public class ConstraintsTestHelper { - public static bool TestConstraint(IRouteConstraint constraint, object value, Action routeConfig = null) + public static bool TestConstraint(IRouteConstraint constraint, object value) { - var context = new Mock(); - - var route = new RouteCollection(); - - if (routeConfig != null) - { - routeConfig(route); - } - var parameterName = "fake"; var values = new RouteValueDictionary() { { parameterName, value } }; var routeDirection = RouteDirection.IncomingRequest; - return constraint.Match(context.Object, route, parameterName, values, routeDirection); + return constraint.Match(httpContext: null, route: null, parameterName, values, routeDirection); } } } diff --git a/test/Microsoft.AspNetCore.Routing.Tests/DefaultLinkGeneratorTest.cs b/test/Microsoft.AspNetCore.Routing.Tests/DefaultLinkGeneratorTest.cs index 2d82c439ee..42008ca6eb 100644 --- a/test/Microsoft.AspNetCore.Routing.Tests/DefaultLinkGeneratorTest.cs +++ b/test/Microsoft.AspNetCore.Routing.Tests/DefaultLinkGeneratorTest.cs @@ -691,8 +691,10 @@ namespace Microsoft.AspNetCore.Routing Assert.Equal(expectedValues.OrderBy(kvp => kvp.Key), constraint.Values.OrderBy(kvp => kvp.Key)); } - [Fact] - public void GetLink_InlineConstraints_Success() + [Theory] + [InlineData(true)] + [InlineData(false)] + public void GetLink_InlineConstraints_Success(bool hasHttpContext) { // Arrange var endpoint = EndpointFactory.CreateRouteEndpoint( @@ -700,7 +702,7 @@ namespace Microsoft.AspNetCore.Routing defaults: new { controller = "Home", action = "Index" }, constraints: new { }); var linkGenerator = CreateLinkGenerator(endpoint); - var httpContext = CreateHttpContext(new { }); + var httpContext = hasHttpContext ? CreateHttpContext(new { }) : null; // Act var link = linkGenerator.GetLink( @@ -732,8 +734,10 @@ namespace Microsoft.AspNetCore.Routing Assert.False(canGenerateLink); } - [Fact] - public void GetLink_InlineConstraints_OptionalParameter_ValuePresent() + [Theory] + [InlineData(true)] + [InlineData(false)] + public void GetLink_InlineConstraints_OptionalParameter_ValuePresent(bool hasHttpContext) { // Arrange var endpoint = EndpointFactory.CreateRouteEndpoint( @@ -741,7 +745,7 @@ namespace Microsoft.AspNetCore.Routing defaults: new { controller = "Home", action = "Index" }, constraints: new { }); var linkGenerator = CreateLinkGenerator(endpoint); - var httpContext = CreateHttpContext(ambientValues: new { }); + var httpContext = hasHttpContext ? CreateHttpContext(new { }) : null; // Act var link = linkGenerator.GetLink(httpContext, new { action = "Index", controller = "Home", id = 98 }); @@ -789,8 +793,10 @@ namespace Microsoft.AspNetCore.Routing Assert.False(canGenerateLink); } - [Fact] - public void GetLink_InlineConstraints_MultipleInlineConstraints() + [Theory] + [InlineData(true)] + [InlineData(false)] + public void GetLink_InlineConstraints_MultipleInlineConstraints(bool hasHttpContext) { // Arrange var endpoint = EndpointFactory.CreateRouteEndpoint( @@ -798,7 +804,7 @@ namespace Microsoft.AspNetCore.Routing defaults: new { controller = "Home", action = "Index" }, constraints: new { }); var linkGenerator = CreateLinkGenerator(endpoint); - var httpContext = CreateHttpContext(ambientValues: new { }); + var httpContext = hasHttpContext ? CreateHttpContext(new { }) : null; // Act var link = linkGenerator.GetLink( @@ -809,8 +815,10 @@ namespace Microsoft.AspNetCore.Routing Assert.Equal("/Home/Index/14", link); } - [Fact] - public void GetLink_InlineConstraints_CompositeInlineConstraint_Fails() + [Theory] + [InlineData(true)] + [InlineData(false)] + public void GetLink_InlineConstraints_CompositeInlineConstraint_Fails(bool hasHttpContext) { // Arrange var endpoint = EndpointFactory.CreateRouteEndpoint( @@ -818,7 +826,7 @@ namespace Microsoft.AspNetCore.Routing defaults: new { controller = "Home", action = "Index" }, constraints: new { }); var linkGenerator = CreateLinkGenerator(endpoint); - var httpContext = CreateHttpContext(ambientValues: new { }); + var httpContext = hasHttpContext ? CreateHttpContext(new { }) : null; // Act var canGenerateLink = linkGenerator.TryGetLink(