aspnetcore/test/Microsoft.AspNet.Routing.Tests/Constraints/RangeRouteConstraintTests.cs

53 lines
1.7 KiB
C#

// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if ASPNET50
using System;
using Microsoft.AspNet.Routing.Constraints;
using Microsoft.AspNet.Testing;
using Xunit;
namespace Microsoft.AspNet.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,
3);
}
}
}
#endif