Updating tests to use moq.netcore
This commit is contained in:
parent
825f82d7e0
commit
cad81fa608
|
|
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Routing.Constraints
|
|||
HttpContext httpContext,
|
||||
IRouter route,
|
||||
string routeKey,
|
||||
IDictionary<string, object> routeValues,
|
||||
IDictionary<string, object> 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);
|
||||
|
|
|
|||
|
|
@ -20,10 +20,11 @@ namespace Microsoft.AspNet.Routing
|
|||
/// <param name="values">A dictionary that contains the parameters for the URL.</param>
|
||||
/// <param name="routeDirection">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.</param>
|
||||
/// <returns><c>true</c> if the URL parameter contains a valid value; otherwise, <c>false</c>.</returns>
|
||||
bool Match(HttpContext httpContext,
|
||||
IRouter route,
|
||||
string routeKey,
|
||||
IDictionary<string, object> values,
|
||||
RouteDirection routeDirection);
|
||||
bool Match(
|
||||
HttpContext httpContext,
|
||||
IRouter route,
|
||||
string routeKey,
|
||||
IDictionary<string, object> values,
|
||||
RouteDirection routeDirection);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<Func<IRouteConstraint, bool>> ConstraintMatchMethodExpression =
|
||||
c => c.Match(It.IsAny<HttpContext>(),
|
||||
It.IsAny<IRouter>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<Dictionary<string, object>>(),
|
||||
It.IsAny<RouteDirection>());
|
||||
c => c.Match(
|
||||
It.IsAny<HttpContext>(),
|
||||
It.IsAny<IRouter>(),
|
||||
It.IsAny<string>(),
|
||||
It.IsAny<Dictionary<string, object>>(),
|
||||
It.IsAny<RouteDirection>());
|
||||
|
||||
private static Mock<IRouteConstraint> MockConstraintWithResult(bool result)
|
||||
{
|
||||
|
|
@ -52,5 +52,3 @@ namespace Microsoft.AspNet.Routing.Tests
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<HttpContext>(),
|
||||
route: new Mock<IRouter>().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<HttpContext>(),
|
||||
route: new Mock<IRouter>().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<HttpContext>(),
|
||||
route: new Mock<IRouter>().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<HttpContext>().Object,
|
||||
route: new Mock<IRouter>().Object,
|
||||
routeKey: routeKey,
|
||||
values: values,
|
||||
routeDirection: RouteDirection.IncomingRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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<HttpContext>(),
|
||||
route: new Mock<IRouter>().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<HttpContext>(),
|
||||
route: new Mock<IRouter>().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<HttpContext>(),
|
||||
route: new Mock<IRouter>().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<HttpContext>(),
|
||||
route: new Mock<IRouter>().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<HttpContext>().Object,
|
||||
route: new Mock<IRouter>().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<HttpContext>().Object,
|
||||
route: new Mock<IRouter>().Object,
|
||||
routeKey: routeKey,
|
||||
values: values,
|
||||
routeDirection: RouteDirection.IncomingRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<string, object> values,
|
||||
RouteDirection routeDirection)
|
||||
public bool Match(
|
||||
HttpContext httpContext,
|
||||
IRouter route,
|
||||
string routeKey,
|
||||
IDictionary<string, object> values,
|
||||
RouteDirection routeDirection)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<object[]> EmptyAndNullDefaultValues
|
||||
{
|
||||
|
|
@ -1212,4 +1210,3 @@ namespace Microsoft.AspNet.Routing.Template.Tests
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue