Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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)));
        }
Ejemplo n.º 3
0
        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)));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }