public void ResolveConstraint_SupportsCustomConstraints() { var resolver = new DefaultInlineConstraintResolver(); resolver.ConstraintMap.Add("custom", typeof(IntRouteConstraint)); var constraint = resolver.ResolveConstraint("custom"); Assert.IsType <IntRouteConstraint>(constraint); }
public void ResolveConstraint_CustomConstraintThatDoesNotImplementouteConstraintInterfact_Throws() { var resolver = new DefaultInlineConstraintResolver(); resolver.ConstraintMap.Add("custom", typeof(string)); Assert.Throws <InvalidOperationException>( () => resolver.ResolveConstraint("custom"), #if ASPNETWEBAPI "The constraint type 'String' which is mapped to constraint key 'custom' must implement the IHttpRouteConstraint interface."); #else "The constraint type 'String' which is mapped to constraint key 'custom' must implement the IRouteConstraint interface."); #endif }
public void HandlesRegexConstraints(string inlineConstraint, string expected) { var routeOptions = new Mock <IOptions <RouteOptions> >(); routeOptions.Setup(x => x.Value).Returns(new RouteOptions()); var constraintResolver = new DefaultInlineConstraintResolver(routeOptions.Object); var constraint = constraintResolver.ResolveConstraint(inlineConstraint); var constraintsProcessor = new ConstraintsProcessor(); var result = constraintsProcessor.ProcessConstraints(new Dictionary <string, IRouteConstraint> { { "test", constraint } }); Assert.Equal(1, result.Count); Assert.Equal(expected, result["test"]); }
public void ResolveConstraint_CustomConstraintThatDoesNotImplementouteConstraintInterfact_Throws() { var resolver = new DefaultInlineConstraintResolver(); resolver.ConstraintMap.Add("custom", typeof(string)); Assert.Throws<InvalidOperationException>( () => resolver.ResolveConstraint("custom"), #if ASPNETWEBAPI "The constraint type 'String' which is mapped to constraint key 'custom' must implement the IHttpRouteConstraint interface."); #else "The constraint type 'String' which is mapped to constraint key 'custom' must implement the IRouteConstraint interface."); #endif }
public void ResolveConstraint_SupportsCustomConstraints() { var resolver = new DefaultInlineConstraintResolver(); resolver.ConstraintMap.Add("custom", typeof(IntRouteConstraint)); var constraint = resolver.ResolveConstraint("custom"); Assert.IsType<IntRouteConstraint>(constraint); }