Beispiel #1
0
        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);
        }
Beispiel #2
0
        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)));
        }
Beispiel #3
0
        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)));
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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)));
        }
Beispiel #6
0
        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)));
        }