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

47 lines
1.6 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 NET45
using System;
using Microsoft.AspNet.Routing.Constraints;
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 Act & Assert
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new RangeRouteConstraint(3, 2));
Assert.Equal("The value for argument 'min' should be less than or equal to the value for the argument "+
"'max'.\r\nParameter name: min\r\nActual value was 3.",
ex.Message);
}
}
}
#endif