public void ProcessRequestWithNormalControlFlowForSynchronousController() { // Arrange Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>(); mockHttpContext.ExpectMvcVersionResponseHeader().Verifiable(); RequestContext requestContext = new RequestContext(mockHttpContext.Object, GetRouteData()); MvcAsyncHandler handler = new MvcAsyncHandler(requestContext); Mock<IController> mockController = new Mock<IController>(); mockController.Expect(c => c.Execute(requestContext)).Verifiable(); mockController.As<IDisposable>().Expect(c => c.Dispose()).AtMostOnce().Verifiable(); ControllerBuilder builder = new ControllerBuilder(); builder.SetControllerFactory(new SimpleControllerFactory(mockController.Object)); handler.ControllerBuilder = builder; // Act IAsyncResult asyncResult = handler.BeginProcessRequest(mockHttpContext.Object, null, null); handler.EndProcessRequest(asyncResult); mockHttpContext.Verify(); mockController.Verify(); }
public void ProcessRequestWithNormalControlFlowForAsynchronousController() { // Arrange Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>(); mockHttpContext.Expect(c => c.Response.AppendHeader(MvcHandler.MvcVersionHeaderName, "1.0")).Verifiable(); RequestContext requestContext = new RequestContext(mockHttpContext.Object, GetRouteData()); MvcAsyncHandler handler = new MvcAsyncHandler(requestContext); MockAsyncResult asyncResult = new MockAsyncResult(); Mock<IAsyncController> mockController = new Mock<IAsyncController>(); mockController.Expect(c => c.BeginExecute(requestContext, It.IsAny<AsyncCallback>(), It.IsAny<object>())).Returns(asyncResult).Verifiable(); mockController.Expect(c => c.EndExecute(asyncResult)).Verifiable(); mockController.As<IDisposable>().Expect(c => c.Dispose()).AtMostOnce().Verifiable(); ControllerBuilder builder = new ControllerBuilder(); builder.SetControllerFactory(new SimpleControllerFactory(mockController.Object)); handler.ControllerBuilder = builder; // Act IAsyncResult returnedAsyncResult = handler.BeginProcessRequest(mockHttpContext.Object, null, null); handler.EndProcessRequest(returnedAsyncResult); mockHttpContext.Verify(); mockController.Verify(); }