public void Match_FailsWhenValueIsAvailableAndInnerConstraintFails() { IHttpRouteConstraint innerConstraint = new AlphaHttpRouteConstraint(); OptionalHttpRouteConstraint constraint = new OptionalHttpRouteConstraint(innerConstraint); bool match = TestValue(constraint, "123"); Assert.False(match); }
public void Match_SucceedsWhenValueIsNotAvailable() { IHttpRouteConstraint innerConstraint = new AlphaHttpRouteConstraint(); OptionalHttpRouteConstraint constraint = new OptionalHttpRouteConstraint(innerConstraint); bool match = TestValue(constraint, RouteParameter.Optional); Assert.True(match); }
public void Match_SucceedsWhenValueIsAvailableAndInnerConstraintSucceeds() { IHttpRouteConstraint innerConstraint = new AlphaHttpRouteConstraint(); OptionalHttpRouteConstraint constraint = new OptionalHttpRouteConstraint(innerConstraint); bool match = TestValue(constraint, "abc"); Assert.True(match); }
public void Match_FailsWhenValueIsAvailableAndInnerConstraintFails() { IHttpRouteConstraint innerConstraint = new AlphaHttpRouteConstraint(); OptionalHttpRouteConstraint constraint = new OptionalHttpRouteConstraint(innerConstraint); bool match = TestValue(constraint, "123"); Assert.False(match); }
public void Match_SucceedsWhenValueIsNotAvailable() { IHttpRouteConstraint innerConstraint = new AlphaHttpRouteConstraint(); OptionalHttpRouteConstraint constraint = new OptionalHttpRouteConstraint(innerConstraint); bool match = TestValue(constraint, RouteParameter.Optional); Assert.True(match); }
public void Match_SucceedsWhenValueIsAvailableAndInnerConstraintSucceeds() { IHttpRouteConstraint innerConstraint = new AlphaHttpRouteConstraint(); OptionalHttpRouteConstraint constraint = new OptionalHttpRouteConstraint(innerConstraint); bool match = TestValue(constraint, "abc"); Assert.True(match); }
private IHttpRouteConstraint GetInlineConstraint(Group constraintGroup, bool isOptional) { List<IHttpRouteConstraint> parameterConstraints = new List<IHttpRouteConstraint>(); foreach (Capture constraintCapture in constraintGroup.Captures) { string inlineConstraint = constraintCapture.Value; IHttpRouteConstraint constraint = ConstraintResolver.ResolveConstraint(inlineConstraint); if (constraint == null) { throw Error.InvalidOperation(SRResources.HttpRouteBuilder_CouldNotResolveConstraint, ConstraintResolver.GetType().Name, inlineConstraint); } parameterConstraints.Add(constraint); } if (parameterConstraints.Count > 0) { IHttpRouteConstraint constraint = parameterConstraints.Count == 1 ? parameterConstraints[0] : new CompoundHttpRouteConstraint(parameterConstraints); if (isOptional) { // Constraints should match RouteParameter.Optional if the parameter is optional // This prevents contraining when there's no value specified constraint = new OptionalHttpRouteConstraint(constraint); } return constraint; } return null; }