本文整理汇总了C#中AllReady.Controllers.TaskApiController.Post方法的典型用法代码示例。如果您正苦于以下问题:C# TaskApiController.Post方法的具体用法?C# TaskApiController.Post怎么用?C# TaskApiController.Post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AllReady.Controllers.TaskApiController
的用法示例。
在下文中一共展示了TaskApiController.Post方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostReturnsBadRequestObjectResultWithCorrectErrorMessageWhenEventIsNull
public async Task PostReturnsBadRequestObjectResultWithCorrectErrorMessageWhenEventIsNull()
{
var determineIfATaskIsEditable = new Mock<IDetermineIfATaskIsEditable>();
determineIfATaskIsEditable.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>())).Returns(true);
var sut = new TaskApiController(Mock.Of<IMediator>(), determineIfATaskIsEditable.Object);
var result = await sut.Post(new TaskViewModel()) as BadRequestObjectResult;
Assert.IsType<BadRequestObjectResult>(result);
Assert.Equal(result.StatusCode, 400);
}
示例2: Event
public async Task PostReturnsHttpUnauthorizedWhenUserDoesNotHaveTheAuthorizationToEditTheTaskOrTheTaskIsNotInAnEditableState()
{
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event());
var determineIfATaskIsEditable = new Mock<IDetermineIfATaskIsEditable>();
determineIfATaskIsEditable.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>())).Returns(false);
var sut = new TaskApiController(mediator.Object, determineIfATaskIsEditable.Object);
var result = await sut.Post(new TaskViewModel { EventId = 1 });
Assert.IsType<HttpUnauthorizedResult>(result);
}
示例3: PostReturnsBadRequestResultWhenTaskAlreadyExists
public async Task PostReturnsBadRequestResultWhenTaskAlreadyExists()
{
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event());
mediator.Setup(x => x.Send(It.IsAny<TaskByTaskIdQuery>())).Returns(new AllReadyTask());
var determineIfATaskIsEditable = new Mock<IDetermineIfATaskIsEditable>();
determineIfATaskIsEditable.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>())).Returns(true);
var sut = new TaskApiController(mediator.Object, determineIfATaskIsEditable.Object);
var result = await sut.Post(new TaskViewModel { EventId = 1 });
Assert.IsType<BadRequestResult>(result);
}
示例4: PostSendsAddTaskCommandAsyncWithCorrectData
public async Task PostSendsAddTaskCommandAsyncWithCorrectData()
{
var model = new TaskViewModel { EventId = 1, Id = 1 };
var allReadyTask = new AllReadyTask();
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.SendAsync(It.IsAny<EventByEventIdQuery>())).ReturnsAsync(new Event());
mediator.SetupSequence(x => x.SendAsync(It.IsAny<TaskByTaskIdQuery>()))
.ReturnsAsync(allReadyTask).ReturnsAsync(null);
var determineIfATaskIsEditable = new Mock<IDetermineIfATaskIsEditable>();
determineIfATaskIsEditable.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>(), null)).Returns(true);
var sut = new TaskApiController(mediator.Object, determineIfATaskIsEditable.Object, null);
await sut.Post(model);
mediator.Verify(x => x.SendAsync(It.Is<AddTaskCommand>(y => y.AllReadyTask == allReadyTask)), Times.Once);
}
示例5: PostSendsTaskByTaskIdQueryWithCorrectTaskId
public async Task PostSendsTaskByTaskIdQueryWithCorrectTaskId()
{
var model = new TaskViewModel { EventId = 1, Id = 1 };
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event());
mediator.Setup(x => x.Send(It.IsAny<TaskByTaskIdQuery>())).Returns(new AllReadyTask());
var provider = new Mock<IDetermineIfATaskIsEditable>();
provider.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>())).Returns(true);
var sut = new TaskApiController(mediator.Object, provider.Object);
await sut.Post(model);
mediator.Verify(x => x.Send(It.Is<TaskByTaskIdQuery>(y => y.TaskId == model.Id)));
}
示例6: PostReturnsHttpStatusCodeResultOf201
public async Task PostReturnsHttpStatusCodeResultOf201()
{
var model = new TaskViewModel { EventId = 1, Id = 0 };
var mediator = new Mock<IMediator>();
mediator.Setup(x => x.Send(It.IsAny<EventByIdQuery>())).Returns(new Event());
var provider = new Mock<IDetermineIfATaskIsEditable>();
provider.Setup(x => x.For(It.IsAny<ClaimsPrincipal>(), It.IsAny<AllReadyTask>())).Returns(true);
var sut = new TaskApiController(mediator.Object, provider.Object);
var result = await sut.Post(model) as HttpStatusCodeResult;
Assert.IsType<HttpStatusCodeResult>(result);
Assert.Equal(result.StatusCode, 201);
}