parent
c9c53a686d
commit
dcd921005c
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.Routing.Constraints;
|
using Microsoft.AspNet.Routing.Constraints;
|
||||||
|
using Microsoft.AspNet.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Routing.Tests
|
namespace Microsoft.AspNet.Routing.Tests
|
||||||
|
|
@ -48,41 +49,53 @@ namespace Microsoft.AspNet.Routing.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LengthRouteConstraint_SettingLengthLessThanZero_Throws()
|
public void LengthRouteConstraint_SettingLengthLessThanZero_Throws()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedMessage = "Value must be greater than or equal to 0.";
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new LengthRouteConstraint(-1));
|
ExceptionAssert.ThrowsArgumentOutOfRange(() => new LengthRouteConstraint(-1),
|
||||||
Assert.Equal("Value must be greater than or equal to 0.\r\nParameter name: length\r\n" +
|
"length",
|
||||||
"Actual value was -1.",
|
expectedMessage,
|
||||||
ex.Message);
|
-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LengthRouteConstraint_SettingMinLengthLessThanZero_Throws()
|
public void LengthRouteConstraint_SettingMinLengthLessThanZero_Throws()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedMessage = "Value must be greater than or equal to 0.";
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new LengthRouteConstraint(-1, 3));
|
ExceptionAssert.ThrowsArgumentOutOfRange(() => new LengthRouteConstraint(-1, 3),
|
||||||
Assert.Equal("Value must be greater than or equal to 0.\r\nParameter name: minLength\r\n"+
|
"minLength",
|
||||||
"Actual value was -1.",
|
expectedMessage,
|
||||||
ex.Message);
|
-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LengthRouteConstraint_SettingMaxLengthLessThanZero_Throws()
|
public void LengthRouteConstraint_SettingMaxLengthLessThanZero_Throws()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedMessage = "Value must be greater than or equal to 0.";
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new LengthRouteConstraint(0, -1));
|
ExceptionAssert.ThrowsArgumentOutOfRange(() => new LengthRouteConstraint(0, -1),
|
||||||
Assert.Equal("Value must be greater than or equal to 0.\r\nParameter name: maxLength\r\n" +
|
"maxLength",
|
||||||
"Actual value was -1.",
|
expectedMessage,
|
||||||
ex.Message);
|
-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LengthRouteConstraint_MinGreaterThanMax_Throws()
|
public void LengthRouteConstraint_MinGreaterThanMax_Throws()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedMessage = "The value for argument 'minLength' should be less than or equal to the " + "value for the argument 'maxLength'.";
|
||||||
|
|
||||||
// Arrange Act & Assert
|
// Arrange Act & Assert
|
||||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new LengthRouteConstraint(3, 2));
|
ExceptionAssert.ThrowsArgumentOutOfRange(() => new LengthRouteConstraint(3, 2),
|
||||||
Assert.Equal("The value for argument 'minLength' should be less than or equal to the "+
|
"minLength",
|
||||||
"value for the argument 'maxLength'.\r\nParameter name: minLength\r\nActual value was 3.",
|
expectedMessage,
|
||||||
ex.Message);
|
3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.Routing.Constraints;
|
using Microsoft.AspNet.Routing.Constraints;
|
||||||
|
using Microsoft.AspNet.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Routing.Tests
|
namespace Microsoft.AspNet.Routing.Tests
|
||||||
|
|
@ -31,11 +32,14 @@ namespace Microsoft.AspNet.Routing.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MaxLengthRouteConstraint_SettingMaxLengthLessThanZero_Throws()
|
public void MaxLengthRouteConstraint_SettingMaxLengthLessThanZero_Throws()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedMessage = "Value must be greater than or equal to 0.";
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(()=> new MaxLengthRouteConstraint(-1));
|
ExceptionAssert.ThrowsArgumentOutOfRange(() => new MaxLengthRouteConstraint(-1),
|
||||||
Assert.Equal("Value must be greater than or equal to 0.\r\nParameter name: maxLength\r\n" +
|
"maxLength",
|
||||||
"Actual value was -1.",
|
expectedMessage,
|
||||||
ex.Message);
|
-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.Routing.Constraints;
|
using Microsoft.AspNet.Routing.Constraints;
|
||||||
|
using Microsoft.AspNet.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Routing.Tests
|
namespace Microsoft.AspNet.Routing.Tests
|
||||||
|
|
@ -31,11 +32,14 @@ namespace Microsoft.AspNet.Routing.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MinLengthRouteConstraint_SettingMinLengthLessThanZero_Throws()
|
public void MinLengthRouteConstraint_SettingMinLengthLessThanZero_Throws()
|
||||||
{
|
{
|
||||||
|
// Arrange
|
||||||
|
var expectedMessage = "Value must be greater than or equal to 0.";
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new MinLengthRouteConstraint(-1));
|
ExceptionAssert.ThrowsArgumentOutOfRange(() => new MinLengthRouteConstraint(-1),
|
||||||
Assert.Equal("Value must be greater than or equal to 0.\r\nParameter name: minLength\r\n" +
|
"minLength",
|
||||||
"Actual value was -1.",
|
expectedMessage,
|
||||||
ex.Message);
|
-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNet.Routing.Constraints;
|
using Microsoft.AspNet.Routing.Constraints;
|
||||||
|
using Microsoft.AspNet.Testing;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.Routing.Tests
|
namespace Microsoft.AspNet.Routing.Tests
|
||||||
|
|
@ -35,11 +36,15 @@ namespace Microsoft.AspNet.Routing.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RangeRouteConstraint_MinGreaterThanMax_Throws()
|
public void RangeRouteConstraint_MinGreaterThanMax_Throws()
|
||||||
{
|
{
|
||||||
// Arrange Act & Assert
|
// Arrange
|
||||||
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new RangeRouteConstraint(3, 2));
|
var expectedMessage = "The value for argument 'min' should be less than or equal to the value for the " +
|
||||||
Assert.Equal("The value for argument 'min' should be less than or equal to the value for the argument "+
|
"argument 'max'.";
|
||||||
"'max'.\r\nParameter name: min\r\nActual value was 3.",
|
|
||||||
ex.Message);
|
// Act & Assert
|
||||||
|
ExceptionAssert.ThrowsArgumentOutOfRange(() => new RangeRouteConstraint(3, 2),
|
||||||
|
"min",
|
||||||
|
expectedMessage,
|
||||||
|
3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Globalization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Routing.Constraints;
|
using Microsoft.AspNet.Routing.Constraints;
|
||||||
|
using Microsoft.AspNet.Testing;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -47,6 +48,13 @@ namespace Microsoft.AspNet.Routing.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RegexInlineConstraint_IsCultureInsensitive()
|
public void RegexInlineConstraint_IsCultureInsensitive()
|
||||||
{
|
{
|
||||||
|
if (TestPlatformHelper.IsMono)
|
||||||
|
{
|
||||||
|
// The Regex in Mono returns true when matching the Turkish I for the a-z range which causes the test
|
||||||
|
// to fail. Tracked via #100.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
var constraint = new RegexInlineRouteConstraint("^([a-z]+)$");
|
var constraint = new RegexInlineRouteConstraint("^([a-z]+)$");
|
||||||
var values = new RouteValueDictionary(new { controller = "\u0130" }); // Turkish upper-case dotted I
|
var values = new RouteValueDictionary(new { controller = "\u0130" }); // Turkish upper-case dotted I
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Routing.Constraints;
|
using Microsoft.AspNet.Routing.Constraints;
|
||||||
|
using Microsoft.AspNet.Testing;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
|
@ -68,8 +69,15 @@ namespace Microsoft.AspNet.Routing.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RegexConstraintIsCultureInsensitiveWhenConstructredWithString()
|
public void RegexConstraintIsCultureInsensitiveWhenConstructedWithString()
|
||||||
{
|
{
|
||||||
|
if (TestPlatformHelper.IsMono)
|
||||||
|
{
|
||||||
|
// The Regex in Mono returns true when matching the Turkish I for the a-z range which causes the test
|
||||||
|
// to fail. Tracked via #100.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Arrange
|
// Arrange
|
||||||
var constraint = new RegexRouteConstraint("^([a-z]+)$");
|
var constraint = new RegexRouteConstraint("^([a-z]+)$");
|
||||||
var values = new RouteValueDictionary(new { controller = "\u0130" }); // Turkish upper-case dotted I
|
var values = new RouteValueDictionary(new { controller = "\u0130" }); // Turkish upper-case dotted I
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Routing.Tests
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
var ex = Assert.Throws<ArgumentNullException>(() => options.ConstraintMap = null);
|
var ex = Assert.Throws<ArgumentNullException>(() => options.ConstraintMap = null);
|
||||||
Assert.Equal("The 'ConstraintMap' property of 'Microsoft.AspNet.Routing.RouteOptions' must not be null." +
|
Assert.Equal("The 'ConstraintMap' property of 'Microsoft.AspNet.Routing.RouteOptions' must not be null." +
|
||||||
"\r\nParameter name: value", ex.Message);
|
Environment.NewLine + "Parameter name: value", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -159,14 +159,28 @@ namespace Microsoft.AspNet.Routing.Tests
|
||||||
public void CreateFromObject_MixedCaseThrows()
|
public void CreateFromObject_MixedCaseThrows()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
var expected = GetDuplicateKeyErrorMessage();
|
||||||
var obj = new { controller = "Home", Controller = "Home" };
|
var obj = new { controller = "Home", Controller = "Home" };
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
ExceptionAssert.Throws<ArgumentException>(
|
ExceptionAssert.Throws<ArgumentException>(
|
||||||
() => new RouteValueDictionary(obj),
|
() => new RouteValueDictionary(obj),
|
||||||
"An item with the same key has already been added.");
|
expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetDuplicateKeyErrorMessage()
|
||||||
|
{
|
||||||
|
// Gets the exception message when duplicate entries are
|
||||||
|
// added to a Dictionary in a platform independent way
|
||||||
|
var ex = Assert.Throws<ArgumentException>(
|
||||||
|
() => new Dictionary<string, string>()
|
||||||
|
{
|
||||||
|
{ "key", "value" },
|
||||||
|
{ "key", "value" }
|
||||||
|
});
|
||||||
|
|
||||||
|
return ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
private class RegularType
|
private class RegularType
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,8 @@ namespace Microsoft.AspNet.Routing.Tests
|
||||||
public void EmptyDefaultValue_WithOptionalParameter_Throws()
|
public void EmptyDefaultValue_WithOptionalParameter_Throws()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
var message = "An optional parameter cannot have default value." + Environment.NewLine +
|
||||||
|
"Parameter name: routeTemplate";
|
||||||
var routeBuilder = CreateRouteBuilder();
|
var routeBuilder = CreateRouteBuilder();
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
|
|
@ -69,7 +71,6 @@ namespace Microsoft.AspNet.Routing.Tests
|
||||||
defaults: new { id = 13 },
|
defaults: new { id = 13 },
|
||||||
constraints: null));
|
constraints: null));
|
||||||
|
|
||||||
var message = "An optional parameter cannot have default value.\r\nParameter name: routeTemplate";
|
|
||||||
Assert.Equal(message, ex.Message);
|
Assert.Equal(message, ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,6 +78,8 @@ namespace Microsoft.AspNet.Routing.Tests
|
||||||
public void NonEmptyDefaultValue_WithOptionalParameter_Throws()
|
public void NonEmptyDefaultValue_WithOptionalParameter_Throws()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
var message = "An optional parameter cannot have default value." + Environment.NewLine +
|
||||||
|
"Parameter name: routeTemplate";
|
||||||
var routeBuilder = CreateRouteBuilder();
|
var routeBuilder = CreateRouteBuilder();
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
|
|
@ -86,7 +89,6 @@ namespace Microsoft.AspNet.Routing.Tests
|
||||||
defaults: new { id = 13 },
|
defaults: new { id = 13 },
|
||||||
constraints: null));
|
constraints: null));
|
||||||
|
|
||||||
var message = "An optional parameter cannot have default value.\r\nParameter name: routeTemplate";
|
|
||||||
Assert.Equal(message, ex.Message);
|
Assert.Equal(message, ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue