Ejemplo n.º 1
0
        public void Should_not_match_when_value_is_not_in_correct_format()
        {
            var constraint = new GuidConstraint();

            var matched = constraint.Match(new Mock<HttpContextBase>().Object, new Route("{controller}/{action}", new Mock<IRouteHandler>().Object), "id", new RouteValueDictionary { { "id", "foobar" } }, RouteDirection.IncomingRequest);

            Assert.False(matched);
        }
Ejemplo n.º 2
0
        public void Should_match_when_parameter_is_optional()
        {
            var constraint = new GuidConstraint(true);

            var matched = constraint.Match(new Mock<HttpContextBase>().Object, new Route("{controller}/{action}", new Mock<IRouteHandler>().Object), "id", new RouteValueDictionary(), RouteDirection.IncomingRequest);

            Assert.True(matched);
        }
Ejemplo n.º 3
0
        public void Should_match_when_parameter_is_optional()
        {
            var constraint = new GuidConstraint(true);

            var matched = constraint.Match(new Mock <HttpContextBase>().Object, new Route("{controller}/{action}", new Mock <IRouteHandler>().Object), "id", new RouteValueDictionary(), RouteDirection.IncomingRequest);

            Assert.True(matched);
        }
Ejemplo n.º 4
0
        public void Setup()
        {
            _constraint = new GuidConstraint();

            _httpContextBase = A.Fake <HttpContextBase>();
            _parameterName   = "assessmentId";
            _route           = A.Fake <Route>();
        }
Ejemplo n.º 5
0
        private static bool Match(string parameterName, string parameterNameInCollection, object value)
        {
            var mockedContext = new Mock <HttpContextBase>();
            IRouteConstraint guidConstraint = new GuidConstraint();
            var routeValueDictionary        = new RouteValueDictionary(new Dictionary <string, object> {
                { parameterNameInCollection, value }
            });

            return(guidConstraint.Match(mockedContext.Object, new Route(null, null), parameterName, routeValueDictionary, RouteDirection.IncomingRequest));
        }
Ejemplo n.º 6
0
        public void Should_not_match_when_value_is_empty()
        {
            var constraint = new GuidConstraint();

            var matched = constraint.Match(new Mock <HttpContextBase>().Object, new Route("{controller}/{action}", new Mock <IRouteHandler>().Object), "id", new RouteValueDictionary {
                { "id", Guid.Empty }
            }, RouteDirection.IncomingRequest);

            Assert.False(matched);
        }