public void HandleRequest_SendsRequestToFirstMatchingRoute()
        {
            var routes = new List <IRoute>
            {
                MockRepository.GenerateStub <IRoute>(),
                MockRepository.GenerateStub <IRoute>(),
                MockRepository.GenerateStub <IRoute>()
            };

            routes[0].Stub(x => x.IsMatch("/test.html")).Return(false);
            routes[1].Stub(x => x.IsMatch("/test.html")).Return(true);
            routes[2].Stub(x => x.IsMatch("/test.html")).Return(true);

            var context = Mocked.HttpContext()
                          .WithUrl("http://localhost/test.html")
                          .Mock;

            context.Stub(x => x.ServerInfo).Return(MockRepository.GenerateStub <IServerInfo>());
            context.ServerInfo.Stub(x => x.Routes).Return(routes);

            var handler = new RouteRequestHandler();

            handler.HandleRequest(context);

            routes[1].AssertWasCalled(x => x.HandleRequest(context));
        }
Exemplo 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
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);
        }
        public void HandleRequest_WithNoMatchingRoute_ReturnsFalse()
        {
            var routes = new List <IRoute> {
                MockRepository.GenerateStub <IRoute>()
            };

            var context = Mocked.HttpContext()
                          .WithUrl("http://localhost/test.html")
                          .Mock;

            context.Stub(x => x.ServerInfo).Return(MockRepository.GenerateStub <IServerInfo>());
            context.ServerInfo.Stub(x => x.Routes).Return(routes);

            var handler = new RouteRequestHandler();
            var result  = handler.HandleRequest(context);

            Assert.False(result);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }