예제 #1
0
        public void IsMatch_WithMismatchedVirtualPath_ReturnsFalse()
        {
            var route = new Route("tests/([a-z]+).html", typeof(TestAction));

            var result = route.IsMatch("tests/fa!l.html");

            Assert.False(result);
        }
예제 #2
0
        public void IsMatch_WithMatchingVirtualPath_ReturnsTrue()
        {
            var route = new Route("tests/([a-z]+).html", typeof(TestAction));

            var result = route.IsMatch("tests/success.html");

            Assert.True(result);
        }
예제 #3
0
        public void HandleRequest_ForPostRequest_CallsThePostMethodOnTheAction()
        {
            var route = new Route("tests/([a-z]+).html", typeof(TestAction));
            var action = new TestAction();

            var httpContext = Mocked.HttpContext()
                                    .WithRegisteredAction(action)
                                    .WithHttpMethod("POST")
                                    .WithUrl("http://localhost/tests/request.html")
                                    .Mock;

            route.HandleRequest(httpContext);

            Assert.Equal("Post", action.LastMethod);
        }
예제 #4
0
        public void HandleRequest_ForUnsupportedRequest_DoesNotCallTheAction()
        {
            var route = new Route("tests/([a-z]+).html", typeof(TestAction));
            var action = new TestAction();

            var httpContext = Mocked.HttpContext()
                                    .WithRegisteredAction(action)
                                    .WithHttpMethod("PUT")
                                    .WithUrl("http://localhost/tests/request.html")
                                    .Mock;

            route.HandleRequest(httpContext);

            Assert.Null(action.LastMethod);
        }
예제 #5
0
        public void HandleRequest_ForGetRequest_PassesCorrectDataToAction()
        {
            var route = new Route("tests/(?<pageName>[a-z]+).html", typeof(TestAction));
            var action = new TestAction();

            var httpContext = Mocked.HttpContext()
                                    .WithRegisteredAction(action)
                                    .WithHttpMethod("GET")
                                    .WithUrl("http://localhost/tests/myRequest.html")
                                    .Mock;

            route.HandleRequest(httpContext);

            Assert.Equal("myRequest", action.LastContext.RouteData["pageName"]);
            Assert.Same(httpContext, action.LastContext.HttpContext);
        }
예제 #6
0
        public void HandleRequest_WhenRequestWasHandled_ExecutesTheResult()
        {
            var route = new Route("tests/([a-z]+).html", typeof(TestAction));
            var action = new TestAction
            {
                GetResult = MockRepository.GenerateStub<IActionResult>()
            };

            var httpContext = Mocked.HttpContext()
                                    .WithRegisteredAction(action)
                                    .WithHttpMethod("GET")
                                    .WithUrl("http://localhost/tests/request.html")
                                    .Mock;

            route.HandleRequest(httpContext);

            action.GetResult.AssertWasCalled(x => x.Execute(Arg<IHttpContext>.Is.Anything));
        }
예제 #7
0
        public void HandleRequest_WhenRequestWasNotHandled_ReturnsFalse()
        {
            var route = new Route("tests/([a-z]+).html", typeof(TestAction));
            var action = new TestAction
            {
                GetResult = null
            };

            var httpContext = Mocked.HttpContext()
                                    .WithRegisteredAction(action)
                                    .WithHttpMethod("GET")
                                    .WithUrl("http://localhost/tests/request.html")
                                    .Mock;

            var result = route.HandleRequest(httpContext);

            Assert.False(result);
        }
예제 #8
0
        public void HandleRequest_WhenRequestWasHandled_ReturnsTrue()
        {
            var route = new Route("tests/([a-z]+).html", typeof(TestAction));
            var action = new TestAction
                         {
                             GetResult = MockRepository.GenerateStub<IActionResult>()
                         };

            var httpContext = Mocked.HttpContext()
                                    .WithRegisteredAction(action)
                                    .WithHttpMethod("GET")
                                    .WithUrl("http://localhost/tests/request.html")
                                    .Mock;

            var result = route.HandleRequest(httpContext);

            Assert.True(result);
        }