コード例 #1
0
        public void RegexConstraintIsCultureInsensitiveWhenConstructedWithString(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 RegexRouteConstraint("^([a-z]+)$");
            var values     = new RouteValueDictionary(new { controller = "\u0130" }); // Turkish upper-case dotted I

            using (new CultureReplacer(culture))
            {
                // Act
                var match = constraint.Match(
                    httpContext: new Mock <ProtoContext>().Object,
                    route: new Mock <IRouter>().Object,
                    routeKey: "controller",
                    values: values,
                    routeDirection: RouteDirection.IncomingRequest);

                // Assert
                Assert.False(match);
            }
        }
コード例 #2
0
 private bool Match(RegexRouteConstraint contraint, RouteValueDictionary values)
 {
     return(contraint.Match(
                new DefaultHttpContext(),
                route: new Mock <IRouter>().Object,
                routeKey: "controller",
                values: values,
                routeDirection: RouteDirection.IncomingRequest));
 }
コード例 #3
0
        public void RegexConstraintFailsIfKeyIsNotFoundInRouteValues()
        {
            // Arrange
            var constraint = new RegexRouteConstraint(new Regex("^abc$"));
            var values     = new RouteValueDictionary(new { action = "abc" });

            // Act
            var match = constraint.Match(
                new DefaultProtoContext(),
                route: new Mock <IRouter>().Object,
                routeKey: "controller",
                values: values,
                routeDirection: RouteDirection.IncomingRequest);

            // Assert
            Assert.False(match);
        }
コード例 #4
0
        public void RegexConstraintConstructedWithRegex_SimpleFailedMatch()
        {
            // Arrange
            var constraint = new RegexRouteConstraint(new Regex("^abc$"));
            var values     = new RouteValueDictionary(new { controller = "Abc" });

            // Act
            var match = constraint.Match(
                new DefaultProtoContext(),
                route: new Mock <IRouter>().Object,
                routeKey: "controller",
                values: values,
                routeDirection: RouteDirection.IncomingRequest);

            // Assert
            Assert.False(match);
        }
コード例 #5
0
        public void RegexConstraint_TakesRegexAsInput_SimpleMatch()
        {
            // Arrange
            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.True(match);
        }
コード例 #6
0
        [InlineData(@"*****@*****.**", @"^\w+[\w\.]*\@\w+((-\w+)|(\w*))\.[a-z]{2,3}$", true)] // email
        public void RegexConstraintBuildRegexVerbatimFromInput(
            string routeValue,
            string constraintValue,
            bool shouldMatch)
        {
            // Arrange
            var constraint = new RegexRouteConstraint(constraintValue);
            var values     = new RouteValueDictionary(new { controller = routeValue });

            // Act
            var match = constraint.Match(
                new DefaultProtoContext(),
                route: new Mock <IRouter>().Object,
                routeKey: "controller",
                values: values,
                routeDirection: RouteDirection.IncomingRequest);

            // Assert
            Assert.Equal(shouldMatch, match);
        }