1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.AspNetCore.Routing.Constraints;
using Microsoft.AspNetCore.Testing;
using Xunit;
namespace Microsoft.AspNetCore.Routing.Tests
{
public class MinLengthRouteConstraintTests
{
[Theory]
[InlineData(3, "1234", true)]
[InlineData(3, "123", true)]
[InlineData(3, "12", false)]
[InlineData(3, "", false)]
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);
}
[Fact]
public void MinLengthRouteConstraint_SettingMinLengthLessThanZero_Throws()
{
// Arrange
var expectedMessage = "Value must be greater than or equal to 0.";
// Act & Assert
ExceptionAssert.ThrowsArgumentOutOfRange(
() => new MinLengthRouteConstraint(-1),
"minLength",
expectedMessage,
-1);
}
}
}
|