public void HandlesRoutesWithNoConstraints()
		{
			var constraints = new RouteValueDictionary();
			var routeInfo = new RouteInfo { Constraints = new RouteValueDictionary() };

			var processor = new ConstraintsProcessor();
			processor.ProcessConstraints(constraints, routeInfo);
			Assert.AreEqual(0, routeInfo.Constraints.Count);
		}
		public void IncludesRegExpConstraints()
		{
			var constraints = new RouteValueDictionary {{"id", @"\d+"}};
			var routeInfo = new RouteInfo { Constraints = new RouteValueDictionary() };

			var processor = new ConstraintsProcessor();
			processor.ProcessConstraints(constraints, routeInfo);
			Assert.AreEqual(1, routeInfo.Constraints.Count);
			Assert.AreEqual(@"\d+", routeInfo.Constraints["id"]);
		}
        public void HandlesRoutesWithNoConstraints()
        {
            var constraints = new RouteValueDictionary();
            var routeInfo   = new RouteInfo {
                Constraints = new RouteValueDictionary()
            };

            var processor = new ConstraintsProcessor();

            processor.ProcessConstraints(constraints, routeInfo);
            Assert.AreEqual(0, routeInfo.Constraints.Count);
        }
		public void ExcludesCustomConstraints()
		{
			var customConstraint = new Mock<IRouteConstraint>();
			var constraints = new RouteValueDictionary {
				{ "id", @"\d+" },
				{ "awesome", customConstraint },
			};
			var routeInfo = new RouteInfo { Constraints = new RouteValueDictionary() };

			var processor = new ConstraintsProcessor();
			processor.ProcessConstraints(constraints, routeInfo);
			Assert.AreEqual(1, routeInfo.Constraints.Count);
		}
        public void IncludesRegExpConstraints()
        {
            var constraints = new RouteValueDictionary {
                { "id", @"\d+" }
            };
            var routeInfo = new RouteInfo {
                Constraints = new RouteValueDictionary()
            };

            var processor = new ConstraintsProcessor();

            processor.ProcessConstraints(constraints, routeInfo);
            Assert.AreEqual(1, routeInfo.Constraints.Count);
            Assert.AreEqual(@"\d+", routeInfo.Constraints["id"]);
        }
		public void HandlesRegexConstraints(string inlineConstraint, string expected)
		{
			var routeOptions = new Mock<IOptions<RouteOptions>>();
			routeOptions.Setup(x => x.Value).Returns(new RouteOptions());
			var constraintResolver = new DefaultInlineConstraintResolver(routeOptions.Object);
			var constraint = constraintResolver.ResolveConstraint(inlineConstraint);

			var constraintsProcessor = new ConstraintsProcessor();
			var result = constraintsProcessor.ProcessConstraints(new Dictionary<string, IRouteConstraint>
			{
				{"test", constraint}
			});

			Assert.Equal(1, result.Count);
			Assert.Equal(expected, result["test"]);
		}
        public void ExcludesCustomConstraints()
        {
            var customConstraint = new Mock <IRouteConstraint>();
            var constraints      = new RouteValueDictionary {
                { "id", @"\d+" },
                { "awesome", customConstraint },
            };
            var routeInfo = new RouteInfo {
                Constraints = new RouteValueDictionary()
            };

            var processor = new ConstraintsProcessor();

            processor.ProcessConstraints(constraints, routeInfo);
            Assert.AreEqual(1, routeInfo.Constraints.Count);
        }
Exemplo n.º 8
0
        public void HandlesRegexConstraints(string inlineConstraint, string expected)
        {
            var routeOptions = new Mock <IOptions <RouteOptions> >();

            routeOptions.Setup(x => x.Value).Returns(new RouteOptions());
            var constraintResolver = new DefaultInlineConstraintResolver(routeOptions.Object);
            var constraint         = constraintResolver.ResolveConstraint(inlineConstraint);

            var constraintsProcessor = new ConstraintsProcessor();
            var result = constraintsProcessor.ProcessConstraints(new Dictionary <string, IRouteConstraint>
            {
                { "test", constraint }
            });

            Assert.Equal(1, result.Count);
            Assert.Equal(expected, result["test"]);
        }