public async Task PostReturnsBadRequestObjectResultWithCorrectErrorMessageWhenEventIsNull() { var determineIfATaskIsEditable = new Mock <IDetermineIfATaskIsEditable>(); determineIfATaskIsEditable.Setup(x => x.For(It.IsAny <ClaimsPrincipal>(), It.IsAny <VolunteerTask>(), null)).Returns(true); var sut = new TaskApiController(Mock.Of <IMediator>(), determineIfATaskIsEditable.Object, null); var result = await sut.Post(new VolunteerTaskViewModel()) as BadRequestObjectResult; Assert.IsType <BadRequestObjectResult>(result); Assert.Equal(400, result.StatusCode); }
public async Task PostReturnsBadRequestObjectResultWithCorrectErrorMessageWhenActivityIsNull() { var determineIfATaskIsEditable = new Mock <IDetermineIfATaskIsEditable>(); determineIfATaskIsEditable.Setup(x => x.For(It.IsAny <ClaimsPrincipal>(), It.IsAny <AllReadyTask>())).Returns(true); var sut = new TaskApiController(Mock.Of <IAllReadyDataAccess>(), Mock.Of <IMediator>(), determineIfATaskIsEditable.Object); var result = await sut.Post(new TaskViewModel()) as BadRequestObjectResult; Assert.IsType <BadRequestObjectResult>(result); Assert.Equal(result.StatusCode, 400); }
public async Task PostReturnsHttpUnauthorizedWhenUserDoesNotHaveTheAuthorizationToEditTheTaskOrTheTaskIsNotInAnEditableState() { var dataAccess = new Mock <IAllReadyDataAccess>(); dataAccess.Setup(x => x.GetActivity(It.IsAny <int>())).Returns(new Activity()); var determineIfATaskIsEditable = new Mock <IDetermineIfATaskIsEditable>(); determineIfATaskIsEditable.Setup(x => x.For(It.IsAny <ClaimsPrincipal>(), It.IsAny <AllReadyTask>())).Returns(false); var sut = new TaskApiController(dataAccess.Object, null, determineIfATaskIsEditable.Object); var result = await sut.Post(new TaskViewModel { ActivityId = 1 }); Assert.IsType <HttpUnauthorizedResult>(result); }
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>(), null)).Returns(false); var sut = new TaskApiController(mediator.Object, determineIfATaskIsEditable.Object, null); var result = await sut.Post(new TaskViewModel { EventId = 1 }); Assert.IsType <UnauthorizedResult>(result); }
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>(), null)).Returns(true); var sut = new TaskApiController(mediator.Object, determineIfATaskIsEditable.Object, null); var result = await sut.Post(new TaskViewModel { EventId = 1 }); Assert.IsType <BadRequestResult>(result); }
public async Task PostReturnsBadRequestResultWhenTaskAlreadyExists() { var dataAccess = new Mock <IAllReadyDataAccess>(); dataAccess.Setup(x => x.GetActivity(It.IsAny <int>())).Returns(new Activity()); 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(true); var sut = new TaskApiController(dataAccess.Object, mediator.Object, determineIfATaskIsEditable.Object); var result = await sut.Post(new TaskViewModel { ActivityId = 1 }); Assert.IsType <BadRequestResult>(result); }
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>(), null)).Returns(true); var sut = new TaskApiController(mediator.Object, provider.Object, null); var result = await sut.Post(model) as StatusCodeResult; Assert.IsType <StatusCodeResult>(result); Assert.Equal(result.StatusCode, 201); }
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>(), null)).Returns(true); var sut = new TaskApiController(mediator.Object, provider.Object, null); await sut.Post(model); mediator.Verify(x => x.Send(It.Is <TaskByTaskIdQuery>(y => y.TaskId == model.Id))); }
public async Task PostSendsTaskByTaskIdQueryWithCorrectTaskId() { var model = new TaskViewModel { ActivityId = 1, Id = 1 }; var dataAccess = new Mock <IAllReadyDataAccess>(); dataAccess.Setup(x => x.GetActivity(It.IsAny <int>())).Returns(new Activity()); dataAccess.Setup(x => x.GetTask(It.IsAny <int>())).Returns(new AllReadyTask()); var mediator = new Mock <IMediator>(); var provider = new Mock <IDetermineIfATaskIsEditable>(); provider.Setup(x => x.For(It.IsAny <ClaimsPrincipal>(), It.IsAny <AllReadyTask>())).Returns(true); var sut = new TaskApiController(dataAccess.Object, mediator.Object, provider.Object); await sut.Post(model); mediator.Verify(x => x.Send(It.Is <TaskByTaskIdQuery>(y => y.TaskId == model.Id))); }
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); }
public async Task PostSendsAddTaskCommandAsyncWithCorrectData() { var model = new TaskViewModel { ActivityId = 1, Id = 1 }; var allReadyTask = new AllReadyTask(); var dataAccess = new Mock <IAllReadyDataAccess>(); dataAccess.Setup(x => x.GetActivity(It.IsAny <int>())).Returns(new Activity()); dataAccess.Setup(x => x.GetTask(It.IsAny <int>())).Returns(allReadyTask); var mediator = new Mock <IMediator>(); var determineIfATaskIsEditable = new Mock <IDetermineIfATaskIsEditable>(); determineIfATaskIsEditable.Setup(x => x.For(It.IsAny <ClaimsPrincipal>(), It.IsAny <AllReadyTask>())).Returns(true); var sut = new TaskApiController(dataAccess.Object, mediator.Object, determineIfATaskIsEditable.Object); await sut.Post(model); mediator.Verify(x => x.SendAsync(It.Is <AddTaskCommandAsync>(y => y.AllReadyTask == allReadyTask)), Times.Once); }
public async Task PostReturnsHttpStatusCodeResultOf201() { var model = new TaskViewModel { ActivityId = 1, Id = 1 }; var dataAccess = new Mock <IAllReadyDataAccess>(); dataAccess.Setup(x => x.GetActivity(It.IsAny <int>())).Returns(new Activity()); dataAccess.Setup(x => x.GetTask(It.IsAny <int>())).Returns(new AllReadyTask()); var mediator = new Mock <IMediator>(); var provider = new Mock <IDetermineIfATaskIsEditable>(); provider.Setup(x => x.For(It.IsAny <ClaimsPrincipal>(), It.IsAny <AllReadyTask>())).Returns(true); var sut = new TaskApiController(dataAccess.Object, mediator.Object, provider.Object); var result = await sut.Post(model) as HttpStatusCodeResult; Assert.IsType <HttpStatusCodeResult>(result); Assert.Equal(result.StatusCode, 201); }