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); }
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); }
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_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)); }
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); }
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); }