public void MinLengthRouteConstraintTests(int min, string parameterValue, bool expected)
        {
            var constraint = new MinLengthRouteConstraint(min);
            var actual     = TestValue(constraint, parameterValue);

            Assert.Equal(expected, actual);
        }
Example #2
0
        public void MinLengthRouteConstraint_ApplyConstraint(int min, string parameterValue, bool expected)
        {
            // Arrange
            var constraint = new MinLengthRouteConstraint(min);

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

            // Assert
            Assert.Equal(expected, actual);
        }
 private static void ApplyMinLengthRouteConstraint(OpenApiSchema schema, MinLengthRouteConstraint minLengthRouteConstraint)
 {
     if (schema.Type == "array")
     {
         schema.MinItems = minLengthRouteConstraint.MinLength;
     }
     else
     {
         schema.MinLength = minLengthRouteConstraint.MinLength;
     }
 }
    public void AddResolvedConstraint_And_AddConstraint_ForOptionalParameter()
    {
        var builder = CreateBuilder("{controller}/{action}/{name}");
        builder.SetOptional("name");
        builder.AddResolvedConstraint("name", "alpha");
        var minLenConstraint = new MinLengthRouteConstraint(10);
        builder.AddConstraint("name", minLenConstraint);

        var result = builder.Build();
        Assert.Equal(1, result.Count);
        Assert.Equal("name", result.First().Key);
        Assert.IsType<OptionalRouteConstraint>(Assert.Single(result).Value);
        var optionalConstraint = (OptionalRouteConstraint)result.First().Value;
        var compositeConstraint = Assert.IsType<CompositeRouteConstraint>(optionalConstraint.InnerConstraint); ;
        Assert.Equal(2, compositeConstraint.Constraints.Count());

        Assert.Single(compositeConstraint.Constraints, c => c is MinLengthRouteConstraint);
        Assert.Single(compositeConstraint.Constraints, c => c is AlphaRouteConstraint);
    }