本文整理汇总了C#中EmptyController类的典型用法代码示例。如果您正苦于以下问题:C# EmptyController类的具体用法?C# EmptyController怎么用?C# EmptyController使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EmptyController类属于命名空间,在下文中一共展示了EmptyController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteCoreWithAsynchronousInvokerAndActionCompletesSuccessfully
public void ExecuteCoreWithAsynchronousInvokerAndActionCompletesSuccessfully() {
// Arrange
ControllerContext controllerContext = GetControllerContext();
MockAsyncResult asyncResult = new MockAsyncResult();
Mock<ITempDataProvider> mockTempDataProvider = new Mock<ITempDataProvider>();
mockTempDataProvider.Expect(p => p.LoadTempData(controllerContext)).Returns(new Dictionary<string, object>()).Verifiable();
mockTempDataProvider.Expect(p => p.SaveTempData(controllerContext, It.IsAny<IDictionary<string, object>>())).AtMostOnce().Verifiable();
Mock<IAsyncActionInvoker> mockInvoker = new Mock<IAsyncActionInvoker>();
mockInvoker.Expect(i => i.BeginInvokeAction(controllerContext, "SomeAction", It.IsAny<AsyncCallback>(), It.IsAny<object>())).Returns(asyncResult).Verifiable();
mockInvoker.Expect(i => i.EndInvokeAction(asyncResult)).Returns(true).Verifiable();
EmptyController controller = new EmptyController() {
ControllerContext = controllerContext,
TempDataProvider = mockTempDataProvider.Object,
ActionInvoker = mockInvoker.Object
};
// Act
IAsyncResult returnedAsyncResult = controller.BeginExecuteCore(null, null);
controller.TempData["key"] = "value";
controller.EndExecuteCore(returnedAsyncResult);
// Assert
mockInvoker.Verify();
mockTempDataProvider.Verify();
}
示例2: ActionInvokerProperty
public void ActionInvokerProperty() {
// Arrange
Controller controller = new EmptyController();
// Act & Assert
MemberHelper.TestPropertyWithDefaultInstance(controller, "ActionInvoker", new ControllerActionInvoker());
}
示例3: Execute_ThrowsIfRequestContextIsNull
public void Execute_ThrowsIfRequestContextIsNull()
{
// Arrange
IAsyncController controller = new EmptyController();
// Act & assert
Assert.ThrowsArgumentNull(
delegate { controller.BeginExecute(null, null, null); }, "requestContext");
}
示例4: ActionInvokerIsAsyncInvokerByDefault
public void ActionInvokerIsAsyncInvokerByDefault() {
// Arrange
EmptyController controller = new EmptyController();
// Act
IActionInvoker invoker = controller.ActionInvoker;
// Assert
Assert.IsInstanceOfType(invoker, typeof(AsyncControllerActionInvoker));
}
示例5: Execute_ThrowsIfRequestContextIsNull
public void Execute_ThrowsIfRequestContextIsNull() {
// Arrange
IAsyncController controller = new EmptyController();
// Act & assert
ExceptionHelper.ExpectArgumentNullException(
delegate {
controller.BeginExecute(null, null, null);
}, "requestContext");
}
示例6: AsyncManagerProperty
public void AsyncManagerProperty() {
// Arrange
EmptyController controller = new EmptyController();
// Act
AsyncManager asyncManager = controller.AsyncManager;
// Assert
Assert.IsNotNull(asyncManager);
}
示例7: ActionInvokerProperty
public void ActionInvokerProperty() {
// Arrange
EmptyController controller = new EmptyController();
// Act
IActionInvoker invoker = controller.ActionInvoker;
// Assert
Assert.AreEqual(typeof(AsyncControllerActionInvoker), invoker.GetType());
}
示例8: ActionInvokerProperty
public void ActionInvokerProperty()
{
// Arrange
EmptyController controller = new EmptyController();
// Act
IActionInvoker invoker = controller.ActionInvoker;
// Assert
Assert.IsType<AsyncControllerActionInvoker>(invoker);
}
示例9: ContentWithContentString
public void ContentWithContentString() {
// Arrange
Controller controller = new EmptyController();
string content = "Some content";
// Act
ContentResult result = controller.Content(content);
// Assert
Assert.AreEqual(content, result.Content);
}
示例10: Execute_ThrowsIfCalledMoreThanOnce
public void Execute_ThrowsIfCalledMoreThanOnce()
{
// Arrange
IAsyncController controller = new EmptyController();
RequestContext requestContext = GetRequestContext("SomeAction");
// Act & assert
controller.BeginExecute(requestContext, null, null);
Assert.Throws<InvalidOperationException>(
delegate { controller.BeginExecute(requestContext, null, null); },
@"A single instance of controller 'System.Web.Mvc.Test.AsyncControllerTest+EmptyController' 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.");
}
示例11: OnAuthorizationSetsControllerValidateRequestToTrue
public void OnAuthorizationSetsControllerValidateRequestToTrue() {
// Arrange
Controller controller = new EmptyController() { ValidateRequest = false };
ValidateInputAttribute attr = new ValidateInputAttribute(enableValidation: true);
AuthorizationContext authContext = GetAuthorizationContext(controller);
// Act
attr.OnAuthorization(authContext);
// Assert
Assert.IsTrue(controller.ValidateRequest);
}
示例12: HttpContextProperty
public void HttpContextProperty() {
var c = new EmptyController();
Assert.IsNull(c.HttpContext, "Property should be null before Context is set");
Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>();
Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>();
mockControllerContext.Setup(cc => cc.Controller).Returns(c);
mockControllerContext.Setup(cc => cc.HttpContext).Returns(mockHttpContext.Object);
c.ControllerContext = mockControllerContext.Object;
Assert.AreEqual<HttpContextBase>(mockHttpContext.Object, c.HttpContext, "Property should equal the value on the Context.");
}
示例13: ContentWithContentStringAndContentType
public void ContentWithContentStringAndContentType()
{
// Arrange
Controller controller = new EmptyController();
string content = "Some content";
string contentType = "Some content type";
// Act
ContentResult result = controller.Content(content, contentType);
// Assert
Assert.Equal(content, result.Content);
Assert.Equal(contentType, result.ContentType);
}
示例14: ContentWithContentStringAndContentTypeAndEncoding
public void ContentWithContentStringAndContentTypeAndEncoding() {
// Arrange
Controller controller = new EmptyController();
string content = "Some content";
string contentType = "Some content type";
Encoding contentEncoding = Encoding.UTF8;
// Act
ContentResult result = controller.Content(content, contentType, contentEncoding);
// Assert
Assert.AreEqual(content, result.Content);
Assert.AreEqual(contentType, result.ContentType);
Assert.AreSame(contentEncoding, result.ContentEncoding);
}
示例15: CreateCachedController_UnderlyingFactoryReturnsController
public void CreateCachedController_UnderlyingFactoryReturnsController() {
// Arrange
RequestContext requestContext = GetRequestContext();
EmptyController controller = new EmptyController();
Mock<IControllerFactory> mockUnderlyingFactory = new Mock<IControllerFactory>();
mockUnderlyingFactory.Expect(o => o.CreateController(requestContext, "home")).Returns(controller).AtMostOnce();
MvcDynamicSessionControllerFactory factory = new MvcDynamicSessionControllerFactory(mockUnderlyingFactory.Object);
// Act
IController controller1 = factory.CreateCachedController(requestContext, "home");
IController controller2 = factory.CreateController(requestContext, "home");
// Assert
Assert.AreEqual(controller, controller1);
Assert.AreSame(controller1, controller2);
mockUnderlyingFactory.Verify();
}