public async Task DeleteReturnsBadRequestResultWhenCannotFindTaskByTaskId() { var sut = new TaskApiController(null, Mock.Of <IMediator>(), null); var result = await sut.Delete(It.IsAny <int>()); Assert.IsType <BadRequestResult>(result); }
public async Task DeleteSendsTaskByTaskIdQueryWithCorrectTaskId() { const int taskId = 1; var mediator = new Mock <IMediator>(); var sut = new TaskApiController(null, mediator.Object, null); await sut.Delete(taskId); mediator.Verify(x => x.Send(It.Is <TaskByTaskIdQuery>(y => y.TaskId == taskId))); }
public async Task DeleteSendsTaskByTaskIdQueryWithCorrectTaskId() { const int volunteerTaskId = 1; var mediator = new Mock <IMediator>(); var sut = new TaskApiController(mediator.Object, null, null); await sut.Delete(volunteerTaskId); mediator.Verify(x => x.SendAsync(It.Is <VolunteerTaskByVolunteerTaskIdQuery>(y => y.VolunteerTaskId == volunteerTaskId))); }
public async Task DeleteReturnsHttpUnauthorizedResultWhenAUserDoesNotHavePermissionToEditTheTaskOrTheTaskIsNotEditable() { var mediator = new Mock <IMediator>(); 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(false); var sut = new TaskApiController(null, mediator.Object, determineIfATaskIsEditable.Object); var result = await sut.Delete(It.IsAny <int>()); Assert.IsType <HttpUnauthorizedResult>(result); }
public async Task DeleteSendsDeleteTaskCommandAsyncWithCorrectTaskId() { var allReadyTask = new AllReadyTask { Id = 1 }; var mediator = new Mock <IMediator>(); mediator.Setup(x => x.Send(It.IsAny <TaskByTaskIdQuery>())).Returns(allReadyTask); var determineIfATaskIsEditable = new Mock <IDetermineIfATaskIsEditable>(); determineIfATaskIsEditable.Setup(x => x.For(It.IsAny <ClaimsPrincipal>(), It.IsAny <AllReadyTask>())).Returns(true); var sut = new TaskApiController(null, mediator.Object, determineIfATaskIsEditable.Object); await sut.Delete(It.IsAny <int>()); mediator.Verify(x => x.SendAsync(It.Is <DeleteTaskCommandAsync>(y => y.TaskId == allReadyTask.Id))); }
public async Task DeleteSendsDeleteTaskCommandWithCorrectTaskId() { var volunteerTask = new VolunteerTask { Id = 1 }; var mediator = new Mock <IMediator>(); mediator.Setup(x => x.SendAsync(It.IsAny <VolunteerTaskByVolunteerTaskIdQuery>())).ReturnsAsync(volunteerTask); var determineIfATaskIsEditable = new Mock <IDetermineIfATaskIsEditable>(); determineIfATaskIsEditable.Setup(x => x.For(It.IsAny <ClaimsPrincipal>(), It.IsAny <VolunteerTask>(), null)).Returns(true); var sut = new TaskApiController(mediator.Object, determineIfATaskIsEditable.Object, null); await sut.Delete(It.IsAny <int>()); mediator.Verify(x => x.SendAsync(It.Is <DeleteVolunteerTaskCommand>(y => y.VolunteerTaskId == volunteerTask.Id))); }