diff --git a/src/Microsoft.AspNet.Routing/Constraints/RegexRouteConstraint.cs b/src/Microsoft.AspNet.Routing/Constraints/RegexRouteConstraint.cs index 034ec58faf..0ccd6f5eba 100644 --- a/src/Microsoft.AspNet.Routing/Constraints/RegexRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/Constraints/RegexRouteConstraint.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Routing.Constraints HttpContext httpContext, IRouter route, string routeKey, - IDictionary routeValues, + IDictionary values, RouteDirection routeDirection) { if (httpContext == null) @@ -60,14 +60,14 @@ namespace Microsoft.AspNet.Routing.Constraints throw new ArgumentNullException(nameof(routeKey)); } - if (routeValues == null) + if (values == null) { - throw new ArgumentNullException(nameof(routeValues)); + throw new ArgumentNullException(nameof(values)); } object routeValue; - if (routeValues.TryGetValue(routeKey, out routeValue) + if (values.TryGetValue(routeKey, out routeValue) && routeValue != null) { var parameterValueString = Convert.ToString(routeValue, CultureInfo.InvariantCulture); diff --git a/src/Microsoft.AspNet.Routing/IRouteConstraint.cs b/src/Microsoft.AspNet.Routing/IRouteConstraint.cs index 10664c21cc..392cf36d6b 100644 --- a/src/Microsoft.AspNet.Routing/IRouteConstraint.cs +++ b/src/Microsoft.AspNet.Routing/IRouteConstraint.cs @@ -20,10 +20,11 @@ namespace Microsoft.AspNet.Routing /// A dictionary that contains the parameters for the URL. /// An object that indicates whether the constraint check is being performed when an incoming request is being handled or when a URL is being generated. /// true if the URL parameter contains a valid value; otherwise, false. - bool Match(HttpContext httpContext, - IRouter route, - string routeKey, - IDictionary values, - RouteDirection routeDirection); + bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection); } } diff --git a/test/Microsoft.AspNet.Routing.Tests/AttributeRouting/TreeRouterTest.cs b/test/Microsoft.AspNet.Routing.Tests/AttributeRouting/TreeRouterTest.cs index 8d9847a1dc..38c82a4b69 100644 --- a/test/Microsoft.AspNet.Routing.Tests/AttributeRouting/TreeRouterTest.cs +++ b/test/Microsoft.AspNet.Routing.Tests/AttributeRouting/TreeRouterTest.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using System; using System.Collections.Generic; using System.Linq; @@ -2048,5 +2046,3 @@ namespace Microsoft.AspNet.Routing.Tree } } } - -#endif \ No newline at end of file diff --git a/test/Microsoft.AspNet.Routing.Tests/ConstraintMatcherTest.cs b/test/Microsoft.AspNet.Routing.Tests/ConstraintMatcherTest.cs index c7a5de7a34..72bab7bcba 100644 --- a/test/Microsoft.AspNet.Routing.Tests/ConstraintMatcherTest.cs +++ b/test/Microsoft.AspNet.Routing.Tests/ConstraintMatcherTest.cs @@ -3,18 +3,15 @@ using System.Collections.Generic; using Microsoft.AspNet.Http; -#if DNX451 using Microsoft.AspNet.Routing.Logging; using Microsoft.Extensions.Logging.Testing; using Moq; -#endif using Xunit; namespace Microsoft.AspNet.Routing { public class ConstraintMatcherTest { -#if DNX451 private const string _name = "name"; [Fact] @@ -213,7 +210,6 @@ namespace Microsoft.AspNet.Routing logger: logger); return sink; } -#endif private class PassConstraint : IRouteConstraint { diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/AlphaRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/AlphaRouteConstraintTests.cs index 94f13aebac..aa01c1dcc1 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/AlphaRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/AlphaRouteConstraintTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using Microsoft.AspNet.Routing.Constraints; using Xunit; @@ -32,5 +30,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/BoolRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/BoolRouteConstraintTests.cs index f0b2c2de2c..8ec74daec5 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/BoolRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/BoolRouteConstraintTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using System; using System.Collections.Generic; using System.Linq.Expressions; @@ -40,5 +38,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/CompositeRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/CompositeRouteConstraintTests.cs index 6bf377ee35..39e76d6446 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/CompositeRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/CompositeRouteConstraintTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using System; using System.Collections.Generic; using System.Linq.Expressions; @@ -19,9 +17,10 @@ namespace Microsoft.AspNet.Routing.Tests [InlineData(true, false, false)] [InlineData(false, true, false)] [InlineData(false, false, false)] - public void CompositeRouteConstraint_Match_CallsMatchOnInnerConstraints(bool inner1Result, - bool inner2Result, - bool expected) + public void CompositeRouteConstraint_Match_CallsMatchOnInnerConstraints( + bool inner1Result, + bool inner2Result, + bool expected) { // Arrange var inner1 = MockConstraintWithResult(inner1Result); @@ -36,11 +35,12 @@ namespace Microsoft.AspNet.Routing.Tests } static Expression> ConstraintMatchMethodExpression = - c => c.Match(It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny>(), - It.IsAny()); + c => c.Match( + It.IsAny(), + It.IsAny(), + It.IsAny(), + It.IsAny>(), + It.IsAny()); private static Mock MockConstraintWithResult(bool result) { @@ -52,5 +52,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/ConstraintsTestHelper.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/ConstraintsTestHelper.cs index 187b81a14a..c0c0e3c684 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/ConstraintsTestHelper.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/ConstraintsTestHelper.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using System; using System.Collections.Generic; using Microsoft.AspNet.Http; @@ -30,5 +28,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/DateTimeRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/DateTimeRouteConstraintTests.cs index 816dbfe0d0..fcb4b391ac 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/DateTimeRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/DateTimeRouteConstraintTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using System; using System.Collections.Generic; using Microsoft.AspNet.Routing.Constraints; @@ -54,5 +52,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/DecimalRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/DecimalRouteConstraintTests.cs index 963876f32a..3dc764288e 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/DecimalRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/DecimalRouteConstraintTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using System.Collections.Generic; using Microsoft.AspNet.Routing.Constraints; using Xunit; @@ -43,5 +41,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/DoubleRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/DoubleRouteConstraintTests.cs index 1324dabcc3..0a6c5c7f8b 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/DoubleRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/DoubleRouteConstraintTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using Microsoft.AspNet.Routing.Constraints; using Xunit; @@ -30,5 +28,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/FloatRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/FloatRouteConstraintTests.cs index 6da8173a63..ab52d3a8a8 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/FloatRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/FloatRouteConstraintTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using Microsoft.AspNet.Routing.Constraints; using Xunit; @@ -29,5 +27,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/GuidRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/GuidRouteConstraintTests.cs index 14eab0572d..3c7331b27d 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/GuidRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/GuidRouteConstraintTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using System; using System.Collections.Generic; using Microsoft.AspNet.Routing.Constraints; @@ -37,5 +35,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/IntRouteConstraintsTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/IntRouteConstraintsTests.cs index f71434fdd1..e5225ee097 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/IntRouteConstraintsTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/IntRouteConstraintsTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using Microsoft.AspNet.Routing.Constraints; using Xunit; @@ -29,5 +27,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/LengthRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/LengthRouteConstraintTests.cs index 803545e504..268ac9013f 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/LengthRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/LengthRouteConstraintTests.cs @@ -1,9 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - -using System; using Microsoft.AspNet.Routing.Constraints; using Microsoft.AspNet.Testing; using Xunit; @@ -53,10 +50,11 @@ namespace Microsoft.AspNet.Routing.Tests var expectedMessage = "Value must be greater than or equal to 0."; // Act & Assert - ExceptionAssert.ThrowsArgumentOutOfRange(() => new LengthRouteConstraint(-1), - "length", - expectedMessage, - -1); + ExceptionAssert.ThrowsArgumentOutOfRange( + () => new LengthRouteConstraint(-1), + "length", + expectedMessage, + -1); } [Fact] @@ -66,10 +64,11 @@ namespace Microsoft.AspNet.Routing.Tests var expectedMessage = "Value must be greater than or equal to 0."; // Act & Assert - ExceptionAssert.ThrowsArgumentOutOfRange(() => new LengthRouteConstraint(-1, 3), - "minLength", - expectedMessage, - -1); + ExceptionAssert.ThrowsArgumentOutOfRange( + () => new LengthRouteConstraint(-1, 3), + "minLength", + expectedMessage, + -1); } [Fact] @@ -79,25 +78,26 @@ namespace Microsoft.AspNet.Routing.Tests var expectedMessage = "Value must be greater than or equal to 0."; // Act & Assert - ExceptionAssert.ThrowsArgumentOutOfRange(() => new LengthRouteConstraint(0, -1), - "maxLength", - expectedMessage, - -1); + 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'."; + var expectedMessage = "The value for argument 'minLength' should be less than or equal to the " + + "value for the argument 'maxLength'."; // Arrange Act & Assert - ExceptionAssert.ThrowsArgumentOutOfRange(() => new LengthRouteConstraint(3, 2), - "minLength", - expectedMessage, - 3); + ExceptionAssert.ThrowsArgumentOutOfRange( + () => new LengthRouteConstraint(3, 2), + "minLength", + expectedMessage, + 3); } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/LongRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/LongRouteConstraintTests.cs index d7b30c3e1d..439eff07da 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/LongRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/LongRouteConstraintTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using Microsoft.AspNet.Routing.Constraints; using Xunit; @@ -31,5 +29,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/MaxLengthRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/MaxLengthRouteConstraintTests.cs index f081366938..281ad6b669 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/MaxLengthRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/MaxLengthRouteConstraintTests.cs @@ -1,9 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - -using System; using Microsoft.AspNet.Routing.Constraints; using Microsoft.AspNet.Testing; using Xunit; @@ -36,12 +33,11 @@ namespace Microsoft.AspNet.Routing.Tests var expectedMessage = "Value must be greater than or equal to 0."; // Act & Assert - ExceptionAssert.ThrowsArgumentOutOfRange(() => new MaxLengthRouteConstraint(-1), - "maxLength", - expectedMessage, - -1); + ExceptionAssert.ThrowsArgumentOutOfRange( + () => new MaxLengthRouteConstraint(-1), + "maxLength", + expectedMessage, + -1); } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/MaxRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/MaxRouteConstraintTests.cs index dee0a71397..32119487fa 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/MaxRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/MaxRouteConstraintTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using Microsoft.AspNet.Routing.Constraints; using Xunit; @@ -27,5 +25,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/MinLengthRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/MinLengthRouteConstraintTests.cs index 1161c56428..ffdc1e675c 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/MinLengthRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/MinLengthRouteConstraintTests.cs @@ -1,9 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - -using System; using Microsoft.AspNet.Routing.Constraints; using Microsoft.AspNet.Testing; using Xunit; @@ -36,12 +33,11 @@ namespace Microsoft.AspNet.Routing.Tests var expectedMessage = "Value must be greater than or equal to 0."; // Act & Assert - ExceptionAssert.ThrowsArgumentOutOfRange(() => new MinLengthRouteConstraint(-1), - "minLength", - expectedMessage, - -1); + ExceptionAssert.ThrowsArgumentOutOfRange( + () => new MinLengthRouteConstraint(-1), + "minLength", + expectedMessage, + -1); } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/MinRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/MinRouteConstraintTests.cs index 3ca70a8803..642599e4d6 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/MinRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/MinRouteConstraintTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using Microsoft.AspNet.Routing.Constraints; using Xunit; @@ -27,5 +25,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/RangeRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/RangeRouteConstraintTests.cs index b22a20557b..1f3ae2675c 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/RangeRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/RangeRouteConstraintTests.cs @@ -1,9 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - -using System; using Microsoft.AspNet.Routing.Constraints; using Microsoft.AspNet.Testing; using Xunit; @@ -41,12 +38,11 @@ namespace Microsoft.AspNet.Routing.Tests "argument 'max'."; // Act & Assert - ExceptionAssert.ThrowsArgumentOutOfRange(() => new RangeRouteConstraint(3, 2), - "min", - expectedMessage, - 3); + ExceptionAssert.ThrowsArgumentOutOfRange( + () => new RangeRouteConstraint(3, 2), + "min", + expectedMessage, + 3); } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexInlineRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexInlineRouteConstraintTests.cs index f9973e6c60..554ce53922 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexInlineRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexInlineRouteConstraintTests.cs @@ -1,10 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - -using System.Globalization; -using System.Threading; using Microsoft.AspNet.Http; using Microsoft.AspNet.Routing.Constraints; using Microsoft.AspNet.Testing; @@ -22,16 +18,25 @@ namespace Microsoft.AspNet.Routing.Tests [InlineData("Abcd", "abc", true)] // Extra char [InlineData("^Abcd", "abc", true)] // Extra special char [InlineData("Abc", " abc", false)] // Missing char - public void RegexInlineConstraintBuildRegexVerbatimFromInput(string routeValue, - string constraintValue, - bool shouldMatch) + public void RegexInlineConstraintBuildRegexVerbatimFromInput( + string routeValue, + string constraintValue, + bool shouldMatch) { // Arrange var constraint = new RegexInlineRouteConstraint(constraintValue); - var values = new RouteValueDictionary(new {controller = routeValue}); + var values = new RouteValueDictionary(new { controller = routeValue }); + + // Act + var match = constraint.Match( + httpContext: Mock.Of(), + route: new Mock().Object, + routeKey: "controller", + values: values, + routeDirection: RouteDirection.IncomingRequest); // Assert - Assert.Equal(shouldMatch, EasyMatch(constraint, "controller", values)); + Assert.Equal(shouldMatch, match); } [Fact] @@ -41,12 +46,22 @@ namespace Microsoft.AspNet.Routing.Tests var constraint = new RegexInlineRouteConstraint("^abc$"); var values = new RouteValueDictionary(new { action = "abc" }); + // Act + var match = constraint.Match( + httpContext: Mock.Of(), + route: new Mock().Object, + routeKey: "controller", + values: values, + routeDirection: RouteDirection.IncomingRequest); + // Assert - Assert.False(EasyMatch(constraint, "controller", values)); + Assert.False(match); } - [Fact] - public void RegexInlineConstraint_IsCultureInsensitive() + [Theory] + [InlineData("tr-TR")] + [InlineData("en-US")] + public void RegexInlineConstraint_IsCultureInsensitive(string culture) { if (TestPlatformHelper.IsMono) { @@ -59,41 +74,19 @@ namespace Microsoft.AspNet.Routing.Tests var constraint = new RegexInlineRouteConstraint("^([a-z]+)$"); var values = new RouteValueDictionary(new { controller = "\u0130" }); // Turkish upper-case dotted I - var currentThread = Thread.CurrentThread; - var backupCulture = currentThread.CurrentCulture; - - bool matchInTurkish; - bool matchInUsEnglish; - - // Act - try + using (new CultureReplacer(culture)) { - currentThread.CurrentCulture = new CultureInfo("tr-TR"); // Turkish culture - matchInTurkish = EasyMatch(constraint, "controller", values); + // Act + var match = constraint.Match( + httpContext: Mock.Of(), + route: new Mock().Object, + routeKey: "controller", + values: values, + routeDirection: RouteDirection.IncomingRequest); - currentThread.CurrentCulture = new CultureInfo("en-US"); - matchInUsEnglish = EasyMatch(constraint, "controller", values); + // Assert + Assert.False(match); } - finally - { - currentThread.CurrentCulture = backupCulture; - } - - // Assert - Assert.False(matchInUsEnglish); // this just verifies the test - Assert.False(matchInTurkish); - } - - private static bool EasyMatch(IRouteConstraint constraint, - string routeKey, - RouteValueDictionary values) - { - return constraint.Match(httpContext: new Mock().Object, - route: new Mock().Object, - routeKey: routeKey, - values: values, - routeDirection: RouteDirection.IncomingRequest); } } } -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexRouteConstraintTests.cs index 3526ebc3fc..913501605e 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/RegexRouteConstraintTests.cs @@ -1,11 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - -using System.Globalization; using System.Text.RegularExpressions; -using System.Threading; using Microsoft.AspNet.Http; using Microsoft.AspNet.Routing.Constraints; using Microsoft.AspNet.Testing; @@ -26,16 +22,25 @@ namespace Microsoft.AspNet.Routing.Tests [InlineData("123-456-2334", @"^\d{3}-\d{3}-\d{4}$", true)] // ssn [InlineData(@"12/4/2013", @"^\d{1,2}\/\d{1,2}\/\d{4}$", true)] // date [InlineData(@"abc@def.com", @"^\w+[\w\.]*\@\w+((-\w+)|(\w*))\.[a-z]{2,3}$", true)] // email - public void RegexConstraintBuildRegexVerbatimFromInput(string routeValue, - string constraintValue, - bool shouldMatch) + public void RegexConstraintBuildRegexVerbatimFromInput( + string routeValue, + string constraintValue, + bool shouldMatch) { // Arrange var constraint = new RegexRouteConstraint(constraintValue); - var values = new RouteValueDictionary(new {controller = routeValue}); + var values = new RouteValueDictionary(new { controller = routeValue }); + + // Act + var match = constraint.Match( + httpContext: Mock.Of(), + route: new Mock().Object, + routeKey: "controller", + values: values, + routeDirection: RouteDirection.IncomingRequest); // Assert - Assert.Equal(shouldMatch, EasyMatch(constraint, "controller", values)); + Assert.Equal(shouldMatch, match); } [Fact] @@ -43,10 +48,18 @@ namespace Microsoft.AspNet.Routing.Tests { // Arrange var constraint = new RegexRouteConstraint(new Regex("^abc$")); - var values = new RouteValueDictionary(new { controller = "abc"}); + var values = new RouteValueDictionary(new { controller = "abc" }); + + // Act + var match = constraint.Match( + httpContext: Mock.Of(), + route: new Mock().Object, + routeKey: "controller", + values: values, + routeDirection: RouteDirection.IncomingRequest); // Assert - Assert.True(EasyMatch(constraint, "controller", values)); + Assert.True(match); } [Fact] @@ -56,8 +69,16 @@ namespace Microsoft.AspNet.Routing.Tests var constraint = new RegexRouteConstraint(new Regex("^abc$")); var values = new RouteValueDictionary(new { controller = "Abc" }); + // Act + var match = constraint.Match( + httpContext: Mock.Of(), + route: new Mock().Object, + routeKey: "controller", + values: values, + routeDirection: RouteDirection.IncomingRequest); + // Assert - Assert.False(EasyMatch(constraint, "controller", values)); + Assert.False(match); } [Fact] @@ -67,12 +88,22 @@ namespace Microsoft.AspNet.Routing.Tests var constraint = new RegexRouteConstraint(new Regex("^abc$")); var values = new RouteValueDictionary(new { action = "abc" }); + // Act + var match = constraint.Match( + httpContext: Mock.Of(), + route: new Mock().Object, + routeKey: "controller", + values: values, + routeDirection: RouteDirection.IncomingRequest); + // Assert - Assert.False(EasyMatch(constraint, "controller", values)); + Assert.False(match); } - [Fact] - public void RegexConstraintIsCultureInsensitiveWhenConstructedWithString() + [Theory] + [InlineData("tr-TR")] + [InlineData("en-US")] + public void RegexConstraintIsCultureInsensitiveWhenConstructedWithString(string culture) { if (TestPlatformHelper.IsMono) { @@ -85,41 +116,19 @@ namespace Microsoft.AspNet.Routing.Tests var constraint = new RegexRouteConstraint("^([a-z]+)$"); var values = new RouteValueDictionary(new { controller = "\u0130" }); // Turkish upper-case dotted I - var currentThread = Thread.CurrentThread; - var backupCulture = currentThread.CurrentCulture; - - bool matchInTurkish; - bool matchInUsEnglish; - - // Act - try + using (new CultureReplacer(culture)) { - currentThread.CurrentCulture = new CultureInfo("tr-TR"); // Turkish culture - matchInTurkish = EasyMatch(constraint, "controller", values); + // Act + var match = constraint.Match( + httpContext: new Mock().Object, + route: new Mock().Object, + routeKey: "controller", + values: values, + routeDirection: RouteDirection.IncomingRequest); - currentThread.CurrentCulture = new CultureInfo("en-US"); - matchInUsEnglish = EasyMatch(constraint, "controller", values); + // Assert + Assert.False(match); } - finally - { - currentThread.CurrentCulture = backupCulture; - } - - // Assert - Assert.False(matchInUsEnglish); // this just verifies the test - Assert.False(matchInTurkish); - } - - private static bool EasyMatch(IRouteConstraint constraint, - string routeKey, - RouteValueDictionary values) - { - return constraint.Match(httpContext: new Mock().Object, - route: new Mock().Object, - routeKey: routeKey, - values: values, - routeDirection: RouteDirection.IncomingRequest); } } } -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Constraints/RequiredRouteConstraintTests.cs b/test/Microsoft.AspNet.Routing.Tests/Constraints/RequiredRouteConstraintTests.cs index 029fc0788c..0e5477f599 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Constraints/RequiredRouteConstraintTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Constraints/RequiredRouteConstraintTests.cs @@ -1,9 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - -using System; using Microsoft.AspNet.Http; using Microsoft.AspNet.Routing.Constraints; using Moq; @@ -94,5 +91,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/DefaultInlineConstraintResolverTest.cs b/test/Microsoft.AspNet.Routing.Tests/DefaultInlineConstraintResolverTest.cs index ed5930c73c..ce0a923424 100644 --- a/test/Microsoft.AspNet.Routing.Tests/DefaultInlineConstraintResolverTest.cs +++ b/test/Microsoft.AspNet.Routing.Tests/DefaultInlineConstraintResolverTest.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 using System; using System.Collections.Generic; using Microsoft.AspNet.Http; @@ -370,4 +369,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/InlineRouteParameterParserTests.cs b/test/Microsoft.AspNet.Routing.Tests/InlineRouteParameterParserTests.cs index 26068ce180..1c4b6801a6 100644 --- a/test/Microsoft.AspNet.Routing.Tests/InlineRouteParameterParserTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/InlineRouteParameterParserTests.cs @@ -3,12 +3,12 @@ using System; using System.Collections.Generic; +using System.Linq; using Microsoft.AspNet.Http; using Microsoft.AspNet.Routing.Template; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.OptionsModel; using Xunit; -using System.Linq; namespace Microsoft.AspNet.Routing.Tests { diff --git a/test/Microsoft.AspNet.Routing.Tests/RouteCollectionTest.cs b/test/Microsoft.AspNet.Routing.Tests/RouteCollectionTest.cs index 3e279de5b6..796e441857 100644 --- a/test/Microsoft.AspNet.Routing.Tests/RouteCollectionTest.cs +++ b/test/Microsoft.AspNet.Routing.Tests/RouteCollectionTest.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 using System; using System.Collections.Generic; using System.Linq; @@ -904,4 +903,3 @@ namespace Microsoft.AspNet.Routing } } } -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/RouteConstraintBuilderTest.cs b/test/Microsoft.AspNet.Routing.Tests/RouteConstraintBuilderTest.cs index badc78eeb0..3b9d97d56d 100644 --- a/test/Microsoft.AspNet.Routing.Tests/RouteConstraintBuilderTest.cs +++ b/test/Microsoft.AspNet.Routing.Tests/RouteConstraintBuilderTest.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 using System; using System.Linq; using Microsoft.AspNet.Http; @@ -189,4 +188,3 @@ namespace Microsoft.AspNet.Routing } } } -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/RouteOptionsTests.cs b/test/Microsoft.AspNet.Routing.Tests/RouteOptionsTests.cs index aa32a4e462..464f97d1c0 100644 --- a/test/Microsoft.AspNet.Routing.Tests/RouteOptionsTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/RouteOptionsTests.cs @@ -35,11 +35,12 @@ namespace Microsoft.AspNet.Routing.Tests } public string Pattern { get; private set; } - public bool Match(HttpContext httpContext, - IRouter route, - string routeKey, - IDictionary values, - RouteDirection routeDirection) + public bool Match( + HttpContext httpContext, + IRouter route, + string routeKey, + IDictionary values, + RouteDirection routeDirection) { throw new NotImplementedException(); } diff --git a/test/Microsoft.AspNet.Routing.Tests/Template/RoutePrecedenceTests.cs b/test/Microsoft.AspNet.Routing.Tests/Template/RoutePrecedenceTests.cs index 0a34b3c279..92ac597f91 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Template/RoutePrecedenceTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Template/RoutePrecedenceTests.cs @@ -1,9 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 using System; -using Microsoft.AspNet.Routing; using Microsoft.Extensions.OptionsModel; using Moq; using Xunit; @@ -121,4 +119,3 @@ namespace Microsoft.AspNet.Routing.Template } } } -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateBinderTests.cs b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateBinderTests.cs index e5a91b5946..0be677f6df 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateBinderTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateBinderTests.cs @@ -1,20 +1,18 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.OptionsModel; -using Moq; using Xunit; namespace Microsoft.AspNet.Routing.Template.Tests { public class TemplateBinderTests { - private static IInlineConstraintResolver _inlineConstraintResolver = GetInlineConstraintResolver(); + private readonly IInlineConstraintResolver _inlineConstraintResolver = GetInlineConstraintResolver(); public static IEnumerable EmptyAndNullDefaultValues { @@ -1212,4 +1210,3 @@ namespace Microsoft.AspNet.Routing.Template.Tests } } } -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateParserTests.cs b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateParserTests.cs index 405335f27c..1682c26f90 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateParserTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateParserTests.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 using System; using System.Collections.Generic; using System.Linq; @@ -916,4 +915,3 @@ namespace Microsoft.AspNet.Routing.Template.Tests } } } -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTest.cs b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTest.cs index e24107733a..f9a34e6d24 100644 --- a/test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTest.cs +++ b/test/Microsoft.AspNet.Routing.Tests/Template/TemplateRouteTest.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 using System; using System.Collections.Generic; using System.Linq; @@ -1972,4 +1971,3 @@ namespace Microsoft.AspNet.Routing.Template } } } -#endif \ No newline at end of file diff --git a/test/Microsoft.AspNet.Routing.Tests/TemplateParserDefaultValuesTests.cs b/test/Microsoft.AspNet.Routing.Tests/TemplateParserDefaultValuesTests.cs index 6eeae1e5f0..cbe6504429 100644 --- a/test/Microsoft.AspNet.Routing.Tests/TemplateParserDefaultValuesTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/TemplateParserDefaultValuesTests.cs @@ -1,8 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 - using System; using Microsoft.AspNet.Builder; using Microsoft.Extensions.DependencyInjection; @@ -130,5 +128,3 @@ namespace Microsoft.AspNet.Routing.Tests } } } - -#endif diff --git a/test/Microsoft.AspNet.Routing.Tests/VirtualPathDataTests.cs b/test/Microsoft.AspNet.Routing.Tests/VirtualPathDataTests.cs index 4d89070324..46f3726732 100644 --- a/test/Microsoft.AspNet.Routing.Tests/VirtualPathDataTests.cs +++ b/test/Microsoft.AspNet.Routing.Tests/VirtualPathDataTests.cs @@ -1,7 +1,6 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -#if DNX451 using Microsoft.AspNet.Http; using Moq; using Xunit; @@ -65,4 +64,3 @@ namespace Microsoft.AspNet.Routing } } } -#endif \ No newline at end of file diff --git a/test/Microsoft.AspNet.Routing.Tests/project.json b/test/Microsoft.AspNet.Routing.Tests/project.json index 69668e12db..f5c02dce72 100644 --- a/test/Microsoft.AspNet.Routing.Tests/project.json +++ b/test/Microsoft.AspNet.Routing.Tests/project.json @@ -1,24 +1,28 @@ { - "compilationOptions": { - "warningsAsErrors": true + "compilationOptions": { + "warningsAsErrors": true + }, + "dependencies": { + "Microsoft.AspNet.Http": "1.0.0-*", + "Microsoft.AspNet.Routing": "1.0.0-*", + "Microsoft.AspNet.Testing": "1.0.0-*", + "Microsoft.Extensions.DependencyInjection": "1.0.0-*", + "Microsoft.Extensions.Logging.Testing": "1.0.0-*", + "xunit.runner.aspnet": "2.0.0-aspnet-*" + }, + "frameworks": { + "dnxcore50": { + "dependencies": { + "moq.netcore": "4.4.0-beta8" + } }, - "dependencies": { - "Microsoft.AspNet.Http": "1.0.0-*", - "Microsoft.AspNet.Routing": "1.0.0-*", - "Microsoft.AspNet.Testing": "1.0.0-*", - "Microsoft.Extensions.DependencyInjection": "1.0.0-*", - "Microsoft.Extensions.Logging.Testing": "1.0.0-*", - "xunit.runner.aspnet": "2.0.0-aspnet-*" - }, - "frameworks": { - "dnxcore50": { }, - "dnx451": { - "dependencies": { - "Moq": "4.2.1312.1622" - } - } - }, - "commands": { - "test": "xunit.runner.aspnet" + "dnx451": { + "dependencies": { + "Moq": "4.2.1312.1622" + } } + }, + "commands": { + "test": "xunit.runner.aspnet" + } }