Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RangeRouteConstraintTests.cs « Constraints « UnitTests « test « Routing « Http « src - github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7d0f13f07d971b2ad7f11255dcb5702377508cca (plain)
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
44
45
46
47
// 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 RangeRouteConstraintTests
{
    [Theory]
    [InlineData(long.MinValue, long.MaxValue, 2, true)]
    [InlineData(3, 5, 3, true)]
    [InlineData(3, 5, 4, true)]
    [InlineData(3, 5, 5, true)]
    [InlineData(3, 5, 6, false)]
    [InlineData(3, 5, 2, false)]
    [InlineData(3, 3, 2, false)]
    [InlineData(3, 3, 3, true)]
    public void RangeRouteConstraintTest_ValidValue_ApplyConstraint(long min, long max, int parameterValue, bool expected)
    {
        // Arrange
        var constraint = new RangeRouteConstraint(min, max);

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

        // Assert
        Assert.Equal(expected, actual);
    }

    [Fact]
    public void RangeRouteConstraint_MinGreaterThanMax_Throws()
    {
        // Arrange
        var expectedMessage = "The value for argument 'min' should be less than or equal to the value for the " +
                              "argument 'max'.";

        // Act & Assert
        ExceptionAssert.ThrowsArgumentOutOfRange(
            () => new RangeRouteConstraint(3, 2),
            "min",
            expectedMessage,
            3L);
    }
}