예제 #1
0
        public void GetRouteDataWithConstraintsThatIsNotStringOrCustomConstraint_Throws()
        {
            // Arrange
            var dictionary = new RouteValueDictionary(new { controller = new RouteValueDictionary() });

            ExceptionAssert.Throws <InvalidOperationException>(
                () => RouteConstraintBuilder.BuildConstraints(dictionary),
                "The constraint entry 'controller' must have a string value or be of a type which implements '" +
                typeof(IRouteConstraint) + "'.");
        }
예제 #2
0
        public void GetRouteDataWithConstraintsThatIsAStringCreatesARegex()
        {
            // Arrange
            var dictionary           = new RouteValueDictionary(new { controller = "abc" });
            var constraintDictionary = RouteConstraintBuilder.BuildConstraints(dictionary);

            // Assert
            Assert.Equal(1, constraintDictionary.Count);
            Assert.Equal("controller", constraintDictionary.First().Key);

            var constraint = constraintDictionary["controller"];

            Assert.IsType <RegexRouteConstraint>(constraint);
        }
예제 #3
0
        public void GetRouteDataWithConstraintsThatIsCustomConstraint_IsPassThrough()
        {
            // Arrange
            var originalConstraint = new Mock <IRouteConstraint>().Object;

            var dictionary           = new RouteValueDictionary(new { controller = originalConstraint });
            var constraintDictionary = RouteConstraintBuilder.BuildConstraints(dictionary);

            // Assert
            Assert.Equal(1, constraintDictionary.Count);
            Assert.Equal("controller", constraintDictionary.First().Key);

            var constraint = constraintDictionary["controller"];

            Assert.Equal(originalConstraint, constraint);
        }
예제 #4
0
        [InlineData("Abc", " abc", false)]    // Matches whole (less one char)
        public void StringConstraintsMatchingScenarios(string routeValue,
                                                       string constraintValue,
                                                       bool shouldMatch)
        {
            // Arrange
            var dictionary = new RouteValueDictionary(new { controller = routeValue });

            var constraintDictionary = RouteConstraintBuilder.BuildConstraints(
                new RouteValueDictionary(new { controller = constraintValue }));
            var constraint = constraintDictionary["controller"];

            Assert.Equal(shouldMatch,
                         constraint.Match(
                             httpContext: new Mock <HttpContext>().Object,
                             route: new Mock <IRouter>().Object,
                             routeKey: "controller",
                             values: dictionary,
                             routeDirection: RouteDirection.IncomingRequest));
        }
예제 #5
0
        public TemplateRoute([NotNull] IRouter target,
                             string routeName,
                             string routeTemplate,
                             IDictionary <string, object> defaults,
                             IDictionary <string, object> constraints,
                             IDictionary <string, object> dataTokens,
                             IInlineConstraintResolver inlineConstraintResolver)
        {
            _target        = target;
            _routeTemplate = routeTemplate ?? string.Empty;
            Name           = routeName;
            _defaults      = defaults ?? new RouteValueDictionary();
            _constraints   = RouteConstraintBuilder.BuildConstraints(constraints, _routeTemplate) ??
                             new Dictionary <string, IRouteConstraint>();
            _dataTokens = dataTokens ?? new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

            // The parser will throw for invalid routes.
            _parsedTemplate = TemplateParser.Parse(RouteTemplate, inlineConstraintResolver);
            UpdateInlineDefaultValuesAndConstraints();

            _matcher = new TemplateMatcher(_parsedTemplate);
            _binder  = new TemplateBinder(_parsedTemplate, _defaults);
        }
예제 #6
0
        public void ConstraintBuilderWithTemplateReturnsNull_OnNullOrEmptyInput(IDictionary <string, object> input)
        {
            var result = RouteConstraintBuilder.BuildConstraints(input, "{controller}");

            Assert.Null(result);
        }
예제 #7
0
        public void ConstraintBuilderReturnsNull_OnNullOrEmptyInput(IDictionary <string, object> input)
        {
            var result = RouteConstraintBuilder.BuildConstraints(input);

            Assert.Null(result);
        }