本文整理汇总了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();
}
示例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.");
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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());
}
示例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();
}
示例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();
}