Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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));
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }