public async Task PutReturnsBadRequestResultWhenCannotFindTaskByTaskId() { var sut = new TaskApiController(Mock.Of <IMediator>(), null, null); var result = await sut.Put(It.IsAny <int>(), It.IsAny <TaskViewModel>()); Assert.IsType <BadRequestResult>(result); }
public async Task PutSendsTaskByTaskIdQueryWithCorrectTaskId() { const int taskId = 1; var mediator = new Mock <IMediator>(); var sut = new TaskApiController(null, mediator.Object, null); await sut.Put(taskId, It.IsAny <TaskViewModel>()); mediator.Verify(x => x.Send(It.Is <TaskByTaskIdQuery>(y => y.TaskId == taskId))); }
public async Task PutSendsTaskByTaskIdQueryWithCorrectTaskId() { const int volunteerTaskId = 1; var mediator = new Mock <IMediator>(); var sut = new TaskApiController(mediator.Object, null, null); await sut.Put(volunteerTaskId, It.IsAny <VolunteerTaskViewModel>()); mediator.Verify(x => x.SendAsync(It.Is <VolunteerTaskByVolunteerTaskIdQuery>(y => y.VolunteerTaskId == volunteerTaskId))); }
public async Task PutReturnsHttpUnauthorizedResultWhenAUserDoesNotHavePermissionToEditTheTaskOrTheTaskIsNotEditable() { const int taskId = 1; 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.Put(taskId, It.IsAny <TaskViewModel>()); Assert.IsType <HttpUnauthorizedResult>(result); }
public async Task PutSendsUpdateTaskCommandAsyncWithCorrectAllReadyTask() { var allReadyTask = new AllReadyTask(); var model = new TaskViewModel { Name = "name", Description = "description", StartDateTime = DateTime.UtcNow, EndDateTime = DateTime.UtcNow }; 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.Put(It.IsAny <int>(), model); mediator.Verify(x => x.SendAsync(It.Is <UpdateTaskCommandAsync>(y => y.AllReadyTask == allReadyTask)), Times.Once); }
public async Task PutReturnsHttpStatusCodeResultOf204() { var allReadyTask = new AllReadyTask(); var model = new TaskViewModel { Name = "name", Description = "description", StartDateTime = DateTime.UtcNow, EndDateTime = DateTime.UtcNow }; 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); var result = await sut.Put(It.IsAny <int>(), model) as HttpStatusCodeResult; Assert.IsType <HttpStatusCodeResult>(result); Assert.Equal(result.StatusCode, 204); }