public void IntRouteConstraintTests(object parameterValue, bool expected)
        {
            var constraint = new IntRouteConstraint();
            var actual     = TestValue(constraint, parameterValue);

            Assert.Equal(expected, actual);
        }
    public void IntRouteConstraint_Match_AppliesConstraint(object parameterValue, bool expected)
    {
        // Arrange
        var constraint = new IntRouteConstraint();

        // Act
        var actual = ConstraintsTestHelper.TestConstraint(constraint, parameterValue);

        // Assert
        Assert.Equal(expected, actual);
    }
Example #3
0
        private static IHttpRouteConstraint ConstraintForTypename(string typename, bool isOptional)
        {
            /* List of all route constraints:
             * https://msdn.microsoft.com/en-us/library/system.web.http.routing.constraints(v=vs.118).aspx
             */

            IHttpRouteConstraint constraint = null;

            switch (typename)
            {
            case "bool":
            case "boolean":
                constraint = new BoolRouteConstraint();
                break;

            case "int":
                constraint = new IntRouteConstraint();
                break;

            case "long":
                constraint = new LongRouteConstraint();
                break;

            case "float":
                constraint = new FloatRouteConstraint();
                break;

            case "double":
                constraint = new DoubleRouteConstraint();
                break;

            case "string":
                constraint = new AlphaRouteConstraint();
                break;
            }

            return(isOptional ? new OptionalRouteConstraint(constraint) : constraint);
        }