Пример #1
0
        public async Task Handle_GivenInvalidId_ShouldRaiseException()
        {
            // Arrange
            var mediatorMock = new Mock <IMediator>();
            // Login user
            var currentUserServiceMock = new Mock <ICurrentUserService>();

            currentUserServiceMock.Setup(m => m.UserId)
            .Returns(userId1.ToString());
            var sut = new ChangeStatusTaskItemCommandHandler(_context, mediatorMock.Object, currentUserServiceMock.Object);

            var assigneeId = Guid.NewGuid();
            // Act
            var command = new ChangeStatusTaskItemCommand
            {
                Id       = invalidTaskItemId,
                Status   = 1,
                Assignee = new UserModel
                {
                    UserId      = assigneeId,
                    DisplayName = "AssigneeTest"
                }
            };
            await Assert.ThrowsAsync <NotFoundException>(() => sut.Handle(command, CancellationToken.None));
        }
Пример #2
0
        public async Task Handle_LoginUserIsNotOwner_ShouldRaiseNotOwned()
        {
            // Arrange
            var mediatorMock = new Mock <IMediator>();
            // Login user
            var currentUserServiceMock = new Mock <ICurrentUserService>();

            currentUserServiceMock.Setup(m => m.UserId)
            .Returns(userId2.ToString());
            var sut = new ChangeStatusTaskItemCommandHandler(_context, mediatorMock.Object, currentUserServiceMock.Object);

            var assigneeId = Guid.NewGuid();

            // Act
            var command = new ChangeStatusTaskItemCommand
            {
                Id       = validTaskItemId,
                Status   = 1,
                Assignee = new UserModel
                {
                    UserId      = assigneeId,
                    DisplayName = "AssigneeTest"
                }
            };
            await Assert.ThrowsAsync <NotOwnedException>(() => sut.Handle(command, CancellationToken.None));

            // Assert
            //mediatorMock.Verify(m => m.Publish(It.Is<ChangeStatusTaskItemCommand>(cc => cc.Id == validTaskItemId), It.IsAny<CancellationToken>()), Times.Once);
        }
Пример #3
0
        public async Task <ActionResult> UpdateStatus(string id, ChangeStatusTaskItemCommand command)
        {
            if (!id.Equals(command.Id.ToString()))
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }
Пример #4
0
        public async Task GivenTaskItemIdDifferId_ReturnsNotFound()
        {
            var client = await _factory.GetAuthenticatedClientAsync();

            var command = new ChangeStatusTaskItemCommand
            {
                Id       = new Guid("197d0438-e04b-453d-b5de-eca05960c6ae"),
                Status   = 2,
                Assignee = new UserModel
                {
                    UserId      = Guid.NewGuid(),
                    DisplayName = "AssigneeTest"
                }
            };

            var content = IntegrationTestHelper.GetRequestContent(command);

            var response = await client.PutAsync($"/api/TaskItems/ChangeStatus/{Guid.NewGuid()}", content);

            response.StatusCode.ShouldBe(HttpStatusCode.BadRequest);
        }
Пример #5
0
        public async Task GivenValidUpdateTaskItemCommand_ReturnsSuccessCode()
        {
            var client = await _factory.GetAuthenticatedClientAsync();

            var command = new ChangeStatusTaskItemCommand
            {
                Id       = new Guid("197d0438-e04b-453d-b5de-eca05960c6ae"),
                Status   = 2,
                Assignee = new UserModel
                {
                    UserId      = Guid.NewGuid(),
                    DisplayName = "AssigneeTest"
                }
            };

            var content = IntegrationTestHelper.GetRequestContent(command);

            var response = await client.PutAsync($"/api/TaskItems/ChangeStatus/{command.Id}", content);

            response.EnsureSuccessStatusCode();
        }