Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/Http/Routing/test/UnitTests/Constraints/RegexInlineRouteConstraintTests.cs')
-rw-r--r--src/Http/Routing/test/UnitTests/Constraints/RegexInlineRouteConstraintTests.cs125
1 files changed, 62 insertions, 63 deletions
diff --git a/src/Http/Routing/test/UnitTests/Constraints/RegexInlineRouteConstraintTests.cs b/src/Http/Routing/test/UnitTests/Constraints/RegexInlineRouteConstraintTests.cs
index 9eca3f91c4..c5c50f55eb 100644
--- a/src/Http/Routing/test/UnitTests/Constraints/RegexInlineRouteConstraintTests.cs
+++ b/src/Http/Routing/test/UnitTests/Constraints/RegexInlineRouteConstraintTests.cs
@@ -7,45 +7,75 @@ using Microsoft.AspNetCore.Testing;
using Moq;
using Xunit;
-namespace Microsoft.AspNetCore.Routing.Tests
+namespace Microsoft.AspNetCore.Routing.Tests;
+
+public class RegexInlineRouteConstraintTests
{
- public class RegexInlineRouteConstraintTests
+ [Theory]
+ [InlineData("abc", "abc", true)] // simple match
+ [InlineData("Abc", "abc", true)] // case insensitive match
+ [InlineData("Abc ", "abc", true)] // Extra space on input match (because we don't add ^({0})$
+ [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)
{
- [Theory]
- [InlineData("abc", "abc", true)] // simple match
- [InlineData("Abc", "abc", true)] // case insensitive match
- [InlineData("Abc ", "abc", true)] // Extra space on input match (because we don't add ^({0})$
- [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)
- {
- // Arrange
- var constraint = new RegexInlineRouteConstraint(constraintValue);
- var values = new RouteValueDictionary(new { controller = routeValue });
+ // Arrange
+ var constraint = new RegexInlineRouteConstraint(constraintValue);
+ var values = new RouteValueDictionary(new { controller = routeValue });
- // Act
- var match = constraint.Match(
- new DefaultHttpContext(),
- route: new Mock<IRouter>().Object,
- routeKey: "controller",
- values: values,
- routeDirection: RouteDirection.IncomingRequest);
+ // Act
+ var match = constraint.Match(
+ new DefaultHttpContext(),
+ route: new Mock<IRouter>().Object,
+ routeKey: "controller",
+ values: values,
+ routeDirection: RouteDirection.IncomingRequest);
- // Assert
- Assert.Equal(shouldMatch, match);
- }
+ // Assert
+ Assert.Equal(shouldMatch, match);
+ }
+
+ [Fact]
+ public void RegexInlineConstraint_FailsIfKeyIsNotFoundInRouteValues()
+ {
+ // Arrange
+ var constraint = new RegexInlineRouteConstraint("^abc$");
+ var values = new RouteValueDictionary(new { action = "abc" });
- [Fact]
- public void RegexInlineConstraint_FailsIfKeyIsNotFoundInRouteValues()
+ // Act
+ var match = constraint.Match(
+ new DefaultHttpContext(),
+ route: new Mock<IRouter>().Object,
+ routeKey: "controller",
+ values: values,
+ routeDirection: RouteDirection.IncomingRequest);
+
+ // Assert
+ Assert.False(match);
+ }
+
+ [Theory]
+ [InlineData("tr-TR")]
+ [InlineData("en-US")]
+ public void RegexInlineConstraint_IsCultureInsensitive(string culture)
+ {
+ if (TestPlatformHelper.IsMono)
{
- // Arrange
- var constraint = new RegexInlineRouteConstraint("^abc$");
- var values = new RouteValueDictionary(new { action = "abc" });
+ // 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
+ using (new CultureReplacer(culture))
+ {
// Act
var match = constraint.Match(
new DefaultHttpContext(),
@@ -57,36 +87,5 @@ namespace Microsoft.AspNetCore.Routing.Tests
// Assert
Assert.False(match);
}
-
- [Theory]
- [InlineData("tr-TR")]
- [InlineData("en-US")]
- public void RegexInlineConstraint_IsCultureInsensitive(string culture)
- {
- 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
-
- using (new CultureReplacer(culture))
- {
- // Act
- var match = constraint.Match(
- new DefaultHttpContext(),
- route: new Mock<IRouter>().Object,
- routeKey: "controller",
- values: values,
- routeDirection: RouteDirection.IncomingRequest);
-
- // Assert
- Assert.False(match);
- }
- }
}
}