public void ExecuteThrowsIfCalledTwice() { // Arrange EmptyControllerBase controller = new EmptyControllerBase(); RequestContext requestContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData()); // Act ((IController)controller).Execute(requestContext); // first call ExceptionHelper.ExpectInvalidOperationException( delegate { ((IController)controller).Execute(requestContext); // second call }, @"A single instance of controller 'System.Web.Mvc.Test.ControllerBaseTest+EmptyControllerBase' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request."); // Assert Assert.AreEqual(1, controller.NumTimesExecuteCoreCalled); }
public void ExecuteThrowsIfCalledTwice() { // Arrange EmptyControllerBase controller = new EmptyControllerBase(); RequestContext requestContext = new RequestContext(HttpContextHelpers.GetMockHttpContext().Object, new RouteData()); // Act ((IController)controller).Execute(requestContext); // first call ExceptionHelper.ExpectInvalidOperationException( delegate { ((IController)controller).Execute(requestContext); // second call }, @"A single instance of controller 'System.Web.Mvc.Test.ControllerBaseTest+EmptyControllerBase' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request."); // Assert Assert.AreEqual(1, controller.NumTimesExecuteCoreCalled); }