public void Match_GivenEmptyValue_FalseShouldBeReturned() { var routeValues = new RouteValueDictionary { { _parameterName, "" } }; var result = _constraint.Match(_httpContextBase, _route, _parameterName, routeValues, RouteDirection.IncomingRequest); result.Should().BeFalse(); }
public void Should_not_match_when_value_is_not_in_correct_format() { var constraint = new GuidConstraint(); var matched = constraint.Match(new Mock<HttpContextBase>().Object, new Route("{controller}/{action}", new Mock<IRouteHandler>().Object), "id", new RouteValueDictionary { { "id", "foobar" } }, RouteDirection.IncomingRequest); Assert.False(matched); }
public void Should_match_when_parameter_is_optional() { var constraint = new GuidConstraint(true); var matched = constraint.Match(new Mock<HttpContextBase>().Object, new Route("{controller}/{action}", new Mock<IRouteHandler>().Object), "id", new RouteValueDictionary(), RouteDirection.IncomingRequest); Assert.True(matched); }
public void Should_match_when_parameter_is_optional() { var constraint = new GuidConstraint(true); var matched = constraint.Match(new Mock <HttpContextBase>().Object, new Route("{controller}/{action}", new Mock <IRouteHandler>().Object), "id", new RouteValueDictionary(), RouteDirection.IncomingRequest); Assert.True(matched); }
private static bool Match(string parameterName, string parameterNameInCollection, object value) { var mockedContext = new Mock <HttpContextBase>(); IRouteConstraint guidConstraint = new GuidConstraint(); var routeValueDictionary = new RouteValueDictionary(new Dictionary <string, object> { { parameterNameInCollection, value } }); return(guidConstraint.Match(mockedContext.Object, new Route(null, null), parameterName, routeValueDictionary, RouteDirection.IncomingRequest)); }
public void Should_not_match_when_value_is_empty() { var constraint = new GuidConstraint(); var matched = constraint.Match(new Mock <HttpContextBase>().Object, new Route("{controller}/{action}", new Mock <IRouteHandler>().Object), "id", new RouteValueDictionary { { "id", Guid.Empty } }, RouteDirection.IncomingRequest); Assert.False(matched); }