当前位置: 首页>>代码示例>>C#>>正文


C# Mock.ExpectMvcVersionResponseHeader方法代码示例

本文整理汇总了C#中Mock.ExpectMvcVersionResponseHeader方法的典型用法代码示例。如果您正苦于以下问题:C# Mock.ExpectMvcVersionResponseHeader方法的具体用法?C# Mock.ExpectMvcVersionResponseHeader怎么用?C# Mock.ExpectMvcVersionResponseHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mock的用法示例。


在下文中一共展示了Mock.ExpectMvcVersionResponseHeader方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRequestAddsServerHeaderCallsExecute

        public void ProcessRequestAddsServerHeaderCallsExecute() {
            // Arrange
            Mock<HttpContextBase> contextMock = new Mock<HttpContextBase>();
            contextMock.ExpectMvcVersionResponseHeader().Verifiable();

            RouteData rd = new RouteData();
            rd.Values.Add("controller", "foo");
            RequestContext requestContext = new RequestContext(contextMock.Object, rd);
            MvcHandler mvcHandler = new MvcHandler(requestContext);

            Mock<ControllerBase> controllerMock = new Mock<ControllerBase>();
            controllerMock.Protected().Setup("Execute", requestContext).Verifiable();

            ControllerBuilder cb = new ControllerBuilder();
            Mock<IControllerFactory> controllerFactoryMock = new Mock<IControllerFactory>();
            controllerFactoryMock.Setup(o => o.CreateController(requestContext, "foo")).Returns(controllerMock.Object);
            controllerFactoryMock.Setup(o => o.ReleaseController(controllerMock.Object));
            cb.SetControllerFactory(controllerFactoryMock.Object);
            mvcHandler.ControllerBuilder = cb;

            // Act
            mvcHandler.ProcessRequest(contextMock.Object);

            // Assert
            contextMock.Verify();
            controllerMock.Verify();
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:27,代码来源:MvcHandlerTest.cs

示例2: ProcessRequestRemovesOptionalParametersFromRouteValueDictionary

        public void ProcessRequestRemovesOptionalParametersFromRouteValueDictionary() {
            // Arrange
            Mock<HttpContextBase> contextMock = new Mock<HttpContextBase>();
            contextMock.ExpectMvcVersionResponseHeader();

            RouteData rd = new RouteData();
            rd.Values.Add("controller", "foo");
            rd.Values.Add("optional", UrlParameter.Optional);
            RequestContext requestContext = new RequestContext(contextMock.Object, rd);
            MvcHandler mvcHandler = new MvcHandler(requestContext);

            Mock<ControllerBase> controllerMock = new Mock<ControllerBase>();
            controllerMock.Protected().Setup("Execute", requestContext).Verifiable();

            ControllerBuilder cb = new ControllerBuilder();
            Mock<IControllerFactory> controllerFactoryMock = new Mock<IControllerFactory>();
            controllerFactoryMock.Setup(o => o.CreateController(requestContext, "foo")).Returns(controllerMock.Object);
            controllerFactoryMock.Setup(o => o.ReleaseController(controllerMock.Object));
            cb.SetControllerFactory(controllerFactoryMock.Object);
            mvcHandler.ControllerBuilder = cb;

            // Act
            mvcHandler.ProcessRequest(contextMock.Object);

            // Assert
            controllerMock.Verify();
            Assert.IsFalse(rd.Values.ContainsKey("optional"), "Optional value should have been removed.");
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:28,代码来源:MvcHandlerTest.cs

示例3: ProcessRequestWithNormalControlFlowForAsynchronousController

        public void ProcessRequestWithNormalControlFlowForAsynchronousController() {
            // Arrange
            Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>();
            mockHttpContext.ExpectMvcVersionResponseHeader().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();
        }
开发者ID:Marceli,项目名称:JQueryGridTest,代码行数:25,代码来源:MvcAsyncHandlerTest.cs

示例4: ProcessRequestWhereControllerBeginExecuteThrows

        public void ProcessRequestWhereControllerBeginExecuteThrows() {
            // Arrange
            Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>();
            mockHttpContext.ExpectMvcVersionResponseHeader().Verifiable();

            RequestContext requestContext = new RequestContext(mockHttpContext.Object, GetRouteData());
            MvcAsyncHandler handler = new MvcAsyncHandler(requestContext);

            Mock<IAsyncController> mockController = new Mock<IAsyncController>();
            mockController.Expect(c => c.BeginExecute(requestContext, It.IsAny<AsyncCallback>(), It.IsAny<object>())).Throws(new InvalidOperationException("Some exception text.")).Verifiable();
            mockController.As<IDisposable>().Expect(c => c.Dispose()).AtMostOnce().Verifiable();

            ControllerBuilder builder = new ControllerBuilder();
            builder.SetControllerFactory(new SimpleControllerFactory(mockController.Object));
            handler.ControllerBuilder = builder;

            // Act
            ExceptionHelper.ExpectInvalidOperationException(
                delegate {
                    handler.BeginProcessRequest(mockHttpContext.Object, null, null);
                },
                @"Some exception text.");

            mockHttpContext.Verify();
            mockController.Verify();
        }
开发者ID:Marceli,项目名称:JQueryGridTest,代码行数:26,代码来源:MvcAsyncHandlerTest.cs

示例5: ProcessRequestWithRouteWithoutControllerThrows

        public void ProcessRequestWithRouteWithoutControllerThrows()
        {
            // Arrange
            Mock<HttpContextBase> contextMock = new Mock<HttpContextBase>();
            contextMock.ExpectMvcVersionResponseHeader().Verifiable();
            RouteData rd = new RouteData();
            MvcHandler mvcHandler = new MvcHandler(new RequestContext(contextMock.Object, rd));

            // Act
            Assert.Throws<InvalidOperationException>(
                delegate { mvcHandler.ProcessRequest(contextMock.Object); },
                "The RouteData must contain an item named 'controller' with a non-empty string value.");

            // Assert
            contextMock.Verify();
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:16,代码来源:MvcHandlerTest.cs

示例6: ProcessRequestThrowsIfControllerNotFound

        public void ProcessRequestThrowsIfControllerNotFound() {
            // Arrange
            Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>();
            mockHttpContext.ExpectMvcVersionResponseHeader().Verifiable();

            RequestContext requestContext = new RequestContext(mockHttpContext.Object, GetRouteData());
            MvcAsyncHandler handler = new MvcAsyncHandler(requestContext);

            ControllerBuilder builder = new ControllerBuilder();
            builder.SetControllerFactory(new SimpleControllerFactory(null));
            handler.ControllerBuilder = builder;

            // Act & assert
            ExceptionHelper.ExpectInvalidOperationException(
                delegate {
                    handler.BeginProcessRequest(mockHttpContext.Object, null, null);
                },
                @"The IControllerFactory 'Microsoft.Web.Mvc.Test.MvcAsyncHandlerTest+SimpleControllerFactory' did not return a controller for a controller named 'Foo'.");

            mockHttpContext.Verify();
        }
开发者ID:Marceli,项目名称:JQueryGridTest,代码行数:21,代码来源:MvcAsyncHandlerTest.cs

示例7: ProcessRequestDisposesControllerIfExecuteThrowsException

        public void ProcessRequestDisposesControllerIfExecuteThrowsException() {
            // Arrange
            Mock<ControllerBase> mockController = new Mock<ControllerBase>(MockBehavior.Strict);
            mockController.As<IDisposable>().Setup(d => d.Dispose()); // so that Verify can be called on Dispose later
            mockController.Protected().Setup("Execute", ItExpr.IsAny<RequestContext>()).Throws(new Exception("some exception"));

            ControllerBuilder builder = new ControllerBuilder();
            builder.SetControllerFactory(new SimpleControllerFactory(mockController.Object));

            Mock<HttpContextBase> contextMock = new Mock<HttpContextBase>();
            contextMock.ExpectMvcVersionResponseHeader().Verifiable();
            RequestContext requestContext = new RequestContext(contextMock.Object, new RouteData());
            requestContext.RouteData.Values["controller"] = "fooController";
            MvcHandler handler = new MvcHandler(requestContext) {
                ControllerBuilder = builder
            };

            // Act
            ExceptionHelper.ExpectException<Exception>(
                delegate {
                    handler.ProcessRequest(requestContext.HttpContext);
                },
                "some exception");

            // Assert
            mockController.Verify();
            contextMock.Verify();
            mockController.As<IDisposable>().Verify(d => d.Dispose(), Times.AtMostOnce());
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:29,代码来源:MvcHandlerTest.cs

示例8: ProcessRequestDisposesControllerIfExecuteDoesNotThrowException

        public void ProcessRequestDisposesControllerIfExecuteDoesNotThrowException() {
            // Arrange
            Mock<ControllerBase> mockController = new Mock<ControllerBase>();
            mockController.Protected().Expect("Execute", ItExpr.IsAny<RequestContext>()).Verifiable();
            mockController.As<IDisposable>().Expect(d => d.Dispose()).AtMostOnce().Verifiable();

            ControllerBuilder builder = new ControllerBuilder();
            builder.SetControllerFactory(new SimpleControllerFactory(mockController.Object));

            Mock<HttpContextBase> contextMock = new Mock<HttpContextBase>();
            contextMock.ExpectMvcVersionResponseHeader().Verifiable();
            RequestContext requestContext = new RequestContext(contextMock.Object, new RouteData());
            requestContext.RouteData.Values["controller"] = "fooController";
            MvcHandler handler = new MvcHandler(requestContext) {
                ControllerBuilder = builder
            };

            // Act
            handler.ProcessRequest(requestContext.HttpContext);

            // Assert
            mockController.Verify();
            contextMock.Verify();
        }
开发者ID:consumentor,项目名称:Server,代码行数:24,代码来源:MvcHandlerTest.cs

示例9: ProcessRequestWithRouteWithoutControllerThrows

        public void ProcessRequestWithRouteWithoutControllerThrows() {
            // Arrange
            Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>();
            mockHttpContext.ExpectMvcVersionResponseHeader().Verifiable();

            RequestContext requestContext = new RequestContext(mockHttpContext.Object, new RouteData());
            MvcAsyncHandler handler = new MvcAsyncHandler(requestContext);

            // Act & assert
            ExceptionHelper.ExpectInvalidOperationException(
                delegate {
                    handler.BeginProcessRequest(mockHttpContext.Object, null, null);
                },
                @"The RouteData must contain an item named 'controller' with a non-empty string value.");

            mockHttpContext.Verify();
        }
开发者ID:Marceli,项目名称:JQueryGridTest,代码行数:17,代码来源:MvcAsyncHandlerTest.cs


注:本文中的Mock.ExpectMvcVersionResponseHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。