Updating tests to run on Mono

Fixes #95
This commit is contained in:
Pranav K 2014-09-22 07:17:40 -07:00
parent c9c53a686d
commit dcd921005c
9 changed files with 92 additions and 34 deletions

View File

@ -5,6 +5,7 @@
using System;
using Microsoft.AspNet.Routing.Constraints;
using Microsoft.AspNet.Testing;
using Xunit;
namespace Microsoft.AspNet.Routing.Tests
@ -48,41 +49,53 @@ namespace Microsoft.AspNet.Routing.Tests
[Fact]
public void LengthRouteConstraint_SettingLengthLessThanZero_Throws()
{
// Arrange
var expectedMessage = "Value must be greater than or equal to 0.";
// Act & Assert
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new LengthRouteConstraint(-1));
Assert.Equal("Value must be greater than or equal to 0.\r\nParameter name: length\r\n" +
"Actual value was -1.",
ex.Message);
ExceptionAssert.ThrowsArgumentOutOfRange(() => new LengthRouteConstraint(-1),
"length",
expectedMessage,
-1);
}
[Fact]
public void LengthRouteConstraint_SettingMinLengthLessThanZero_Throws()
{
// Arrange
var expectedMessage = "Value must be greater than or equal to 0.";
// Act & Assert
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new LengthRouteConstraint(-1, 3));
Assert.Equal("Value must be greater than or equal to 0.\r\nParameter name: minLength\r\n"+
"Actual value was -1.",
ex.Message);
ExceptionAssert.ThrowsArgumentOutOfRange(() => new LengthRouteConstraint(-1, 3),
"minLength",
expectedMessage,
-1);
}
[Fact]
public void LengthRouteConstraint_SettingMaxLengthLessThanZero_Throws()
{
// Arrange
var expectedMessage = "Value must be greater than or equal to 0.";
// Act & Assert
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new LengthRouteConstraint(0, -1));
Assert.Equal("Value must be greater than or equal to 0.\r\nParameter name: maxLength\r\n" +
"Actual value was -1.",
ex.Message);
ExceptionAssert.ThrowsArgumentOutOfRange(() => new LengthRouteConstraint(0, -1),
"maxLength",
expectedMessage,
-1);
}
[Fact]
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
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new LengthRouteConstraint(3, 2));
Assert.Equal("The value for argument 'minLength' should be less than or equal to the "+
"value for the argument 'maxLength'.\r\nParameter name: minLength\r\nActual value was 3.",
ex.Message);
ExceptionAssert.ThrowsArgumentOutOfRange(() => new LengthRouteConstraint(3, 2),
"minLength",
expectedMessage,
3);
}
}
}

View File

@ -5,6 +5,7 @@
using System;
using Microsoft.AspNet.Routing.Constraints;
using Microsoft.AspNet.Testing;
using Xunit;
namespace Microsoft.AspNet.Routing.Tests
@ -31,11 +32,14 @@ namespace Microsoft.AspNet.Routing.Tests
[Fact]
public void MaxLengthRouteConstraint_SettingMaxLengthLessThanZero_Throws()
{
// Arrange
var expectedMessage = "Value must be greater than or equal to 0.";
// Act & Assert
var ex = Assert.Throws<ArgumentOutOfRangeException>(()=> new MaxLengthRouteConstraint(-1));
Assert.Equal("Value must be greater than or equal to 0.\r\nParameter name: maxLength\r\n" +
"Actual value was -1.",
ex.Message);
ExceptionAssert.ThrowsArgumentOutOfRange(() => new MaxLengthRouteConstraint(-1),
"maxLength",
expectedMessage,
-1);
}
}
}

View File

@ -5,6 +5,7 @@
using System;
using Microsoft.AspNet.Routing.Constraints;
using Microsoft.AspNet.Testing;
using Xunit;
namespace Microsoft.AspNet.Routing.Tests
@ -31,11 +32,14 @@ namespace Microsoft.AspNet.Routing.Tests
[Fact]
public void MinLengthRouteConstraint_SettingMinLengthLessThanZero_Throws()
{
// Arrange
var expectedMessage = "Value must be greater than or equal to 0.";
// Act & Assert
var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new MinLengthRouteConstraint(-1));
Assert.Equal("Value must be greater than or equal to 0.\r\nParameter name: minLength\r\n" +
"Actual value was -1.",
ex.Message);
ExceptionAssert.ThrowsArgumentOutOfRange(() => new MinLengthRouteConstraint(-1),
"minLength",
expectedMessage,
-1);
}
}
}

View File

@ -5,6 +5,7 @@
using System;
using Microsoft.AspNet.Routing.Constraints;
using Microsoft.AspNet.Testing;
using Xunit;
namespace Microsoft.AspNet.Routing.Tests
@ -35,11 +36,15 @@ namespace Microsoft.AspNet.Routing.Tests
[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);
// 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);
}
}
}

View File

@ -7,6 +7,7 @@ using System.Globalization;
using System.Threading;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing.Constraints;
using Microsoft.AspNet.Testing;
using Moq;
using Xunit;
@ -47,6 +48,13 @@ namespace Microsoft.AspNet.Routing.Tests
[Fact]
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
var constraint = new RegexInlineRouteConstraint("^([a-z]+)$");
var values = new RouteValueDictionary(new { controller = "\u0130" }); // Turkish upper-case dotted I

View File

@ -8,6 +8,7 @@ using System.Text.RegularExpressions;
using System.Threading;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Routing.Constraints;
using Microsoft.AspNet.Testing;
using Moq;
using Xunit;
@ -68,8 +69,15 @@ namespace Microsoft.AspNet.Routing.Tests
}
[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
var constraint = new RegexRouteConstraint("^([a-z]+)$");
var values = new RouteValueDictionary(new { controller = "\u0130" }); // Turkish upper-case dotted I

View File

@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Routing.Tests
// Act & Assert
var ex = Assert.Throws<ArgumentNullException>(() => options.ConstraintMap = 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);
}
}
}

View File

@ -159,14 +159,28 @@ namespace Microsoft.AspNet.Routing.Tests
public void CreateFromObject_MixedCaseThrows()
{
// Arrange
var expected = GetDuplicateKeyErrorMessage();
var obj = new { controller = "Home", Controller = "Home" };
// Act & Assert
ExceptionAssert.Throws<ArgumentException>(
() => 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
{

View File

@ -60,6 +60,8 @@ namespace Microsoft.AspNet.Routing.Tests
public void EmptyDefaultValue_WithOptionalParameter_Throws()
{
// Arrange
var message = "An optional parameter cannot have default value." + Environment.NewLine +
"Parameter name: routeTemplate";
var routeBuilder = CreateRouteBuilder();
// Act & Assert
@ -69,7 +71,6 @@ namespace Microsoft.AspNet.Routing.Tests
defaults: new { id = 13 },
constraints: null));
var message = "An optional parameter cannot have default value.\r\nParameter name: routeTemplate";
Assert.Equal(message, ex.Message);
}
@ -77,6 +78,8 @@ namespace Microsoft.AspNet.Routing.Tests
public void NonEmptyDefaultValue_WithOptionalParameter_Throws()
{
// Arrange
var message = "An optional parameter cannot have default value." + Environment.NewLine +
"Parameter name: routeTemplate";
var routeBuilder = CreateRouteBuilder();
// Act & Assert
@ -86,7 +89,6 @@ namespace Microsoft.AspNet.Routing.Tests
defaults: new { id = 13 },
constraints: null));
var message = "An optional parameter cannot have default value.\r\nParameter name: routeTemplate";
Assert.Equal(message, ex.Message);
}