public void RouteKey_Exists_MatchSucceeds(string keyName, RouteDirection direction) { // Arrange var actionDescriptor = CreateActionDescriptor("testArea", "testController", "testAction"); actionDescriptor.RouteValues.Add("randomKey", "testRandom"); var descriptorCollectionProvider = CreateActionDescriptorCollectionProvider(actionDescriptor); var httpContext = GetHttpContext(); var route = Mock.Of <IRouter>(); var values = new RouteValueDictionary() { { "area", "testArea" }, { "controller", "testController" }, { "action", "testAction" }, { "randomKey", "testRandom" } }; var constraint = new KnownRouteValueConstraint(descriptorCollectionProvider); // Act var match = constraint.Match(httpContext, route, keyName, values, direction); // Assert Assert.True(match); }
public void ServiceInjected_RouteKey_Exists_UsesInvariantCulture(RouteDirection direction) { // Arrange var actionDescriptor = CreateActionDescriptor("testArea", "testController", "testAction"); actionDescriptor.RouteValues.Add("randomKey", "10/31/2018 07:37:38 -07:00"); var provider = CreateActionDescriptorCollectionProvider(actionDescriptor); var constraint = new KnownRouteValueConstraint(provider); var values = new RouteValueDictionary() { { "area", "testArea" }, { "controller", "testController" }, { "action", "testAction" }, { "randomKey", new DateTimeOffset(2018, 10, 31, 7, 37, 38, TimeSpan.FromHours(-7)) }, }; // Act var match = constraint.Match(httpContext: null, route: null, "randomKey", values, direction); // Assert Assert.True(match); }
public void ServiceInjected_RouteKey_Exists_MatchSucceeds(string keyName, RouteDirection direction) { // Arrange var actionDescriptor = CreateActionDescriptor("testArea", "testController", "testAction"); actionDescriptor.RouteValues.Add("randomKey", "testRandom"); var provider = CreateActionDescriptorCollectionProvider(actionDescriptor); var constraint = new KnownRouteValueConstraint(provider); var values = new RouteValueDictionary() { { "area", "testArea" }, { "controller", "testController" }, { "action", "testAction" }, { "randomKey", "testRandom" } }; // Act var match = constraint.Match(httpContext: null, route: null, keyName, values, direction); // Assert Assert.True(match); }
public void RouteKey_DoesNotExist_MatchFails(string keyName, RouteDirection direction) { // Arrange var values = new RouteValueDictionary(); var httpContext = GetHttpContext(); var route = Mock.Of <IRouter>(); var descriptorCollectionProvider = CreateActionDescriptorCollectionProvider(new ActionDescriptor()); var constraint = new KnownRouteValueConstraint(descriptorCollectionProvider); // Act var match = constraint.Match(httpContext, route, keyName, values, direction); // Assert Assert.False(match); }
public void RouteValue_IsNotAString_MatchFails(RouteDirection direction) { var actionDescriptor = CreateActionDescriptor("testArea", controller: null, action: null); var descriptorCollectionProvider = CreateActionDescriptorCollectionProvider(actionDescriptor); var httpContext = GetHttpContext(); var route = Mock.Of <IRouter>(); var values = new RouteValueDictionary() { { "area", 12 }, }; var constraint = new KnownRouteValueConstraint(descriptorCollectionProvider); // Act var match = constraint.Match(httpContext, route, "area", values, direction); // Assert Assert.False(match); }
public void ActionDescriptorCollection_SettingNullValue_Throws(RouteDirection direction) { // Arrange var actionDescriptorCollectionProvider = Mock.Of <IActionDescriptorCollectionProvider>(); var constraint = new KnownRouteValueConstraint(actionDescriptorCollectionProvider); // Act & Assert var ex = Assert.Throws <InvalidOperationException>( () => constraint.Match( GetHttpContext(), Mock.Of <IRouter>(), "area", new RouteValueDictionary { { "area", "area" } }, direction)); var providerName = actionDescriptorCollectionProvider.GetType().FullName; Assert.Equal( $"The 'ActionDescriptors' property of '{providerName}' must not be null.", ex.Message); }