Esempio n. 1
0
        public void Should_match_when_parameter_is_optional()
        {
            var constraint = new EnumConstraint <ResponseFormat>(true);

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

            Assert.True(matched);
        }
Esempio n. 2
0
        public void Should_not_match_when_value_does_not_match_with_enum_name()
        {
            var constraint = new EnumConstraint<ResponseFormat>();

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

            Assert.False(matched);
        }
Esempio n. 3
0
        public void Should_match_when_parameter_is_optional()
        {
            var constraint = new EnumConstraint<ResponseFormat>(true);

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

            Assert.True(matched);
        }
Esempio n. 4
0
        public void Should_not_match_for_enum_value()
        {
            var constraint = new EnumConstraint <ResponseFormat>();

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

            Assert.False(matched);
        }
        public void ShouldMatch_IfParameterValue_InTheEnumMembers([Values("foo", "notfoo")] string input)
        {
            var constraint = new EnumConstraint("Climax.Web.Http.Tests.TestEnum, Climax.Web.Http.Tests");

            var result = constraint.Match(new HttpRequestMessage(), new Mock<IHttpRoute>().Object, "test",
                new HttpRouteValueDictionary
                {
                    {"test", input}
                }, HttpRouteDirection.UriResolution);

            if (input == "foo")
            {
                result.ShouldBeTrue();
            }
            else
            {
                result.ShouldBeFalse();
            }
        }