From dcd921005c476dbdc80f57dbab41920d4871cdae Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 22 Sep 2014 07:17:40 -0700 Subject: [PATCH] Updating tests to run on Mono Fixes #95 --- .../Constraints/LengthRouteConstraintTests.cs | 45 ++++++++++++------- .../MaxLengthRouteConstraintTests.cs | 12 +++-- .../MinLengthRouteConstraintTests.cs | 12 +++-- .../Constraints/RangeRouteConstraintTests.cs | 15 ++++--- .../RegexInlineRouteConstraintTests.cs | 8 ++++ .../Constraints/RegexRouteConstraintTests.cs | 10 ++++- .../RouteOptionsTests.cs | 2 +- .../RouteValueDictionaryTests.cs | 16 ++++++- .../TemplateParserDefaultValuesTests.cs | 6 ++- 9 files changed, 92 insertions(+), 34 deletions(-) diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/LengthRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/LengthRouteConstraintTests.cs index 9ab134c6e4..7db3d54806 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/LengthRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/LengthRouteConstraintTests.cs @@ -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(() => 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(() => 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(() => 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(() => 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); } } } diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/MaxLengthRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/MaxLengthRouteConstraintTests.cs index 4b18f8479e..05fbde111e 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/MaxLengthRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/MaxLengthRouteConstraintTests.cs @@ -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(()=> 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); } } } diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/MinLengthRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/MinLengthRouteConstraintTests.cs index 01c2faf761..c4644ffaf5 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/MinLengthRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/MinLengthRouteConstraintTests.cs @@ -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(() => 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); } } } diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/RangeRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/RangeRouteConstraintTests.cs index c78b2191a6..4106be1114 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/RangeRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/RangeRouteConstraintTests.cs @@ -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(() => 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); } } } diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexInlineRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexInlineRouteConstraintTests.cs index d1ef0f2eb4..f8ae357bdd 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexInlineRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexInlineRouteConstraintTests.cs @@ -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 diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexRouteConstraintTests.cs index e4a909ab74..f761e2d838 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexRouteConstraintTests.cs @@ -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 diff --git a/test/Microsoft.AspNet.Routing.Tests/RouteOptionsTests.cs b/test/Microsoft.AspNet.Routing.Tests/RouteOptionsTests.cs index 37cdb3ca99..e40efc734f 100644 --- a/test/Microsoft.AspNet.Routing.Tests/RouteOptionsTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/RouteOptionsTests.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Routing.Tests // Act & Assert var ex = Assert.Throws(() => 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); } } } diff --git a/test/Microsoft.AspNet.Routing.Tests/RouteValueDictionaryTests.cs b/test/Microsoft.AspNet.Routing.Tests/RouteValueDictionaryTests.cs index e1aed06b4f..edce6573a9 100644 --- a/test/Microsoft.AspNet.Routing.Tests/RouteValueDictionaryTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/RouteValueDictionaryTests.cs @@ -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( () => 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( + () => new Dictionary() + { + { "key", "value" }, + { "key", "value" } + }); + + return ex.Message; + } private class RegularType { diff --git a/test/Microsoft.AspNet.Routing.Tests/TemplateParserDefaultValuesTests.cs b/test/Microsoft.AspNet.Routing.Tests/TemplateParserDefaultValuesTests.cs index 00e82e4f5a..2cd24f08e6 100644 --- a/test/Microsoft.AspNet.Routing.Tests/TemplateParserDefaultValuesTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/TemplateParserDefaultValuesTests.cs @@ -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); }