Пример #1
0
        public async Task CheckDeleteNotExistCommentThrowException()
        {
            _mockCommentRepo.Setup(repository => repository.ReadAsync(It.IsAny <int>()))
            .ReturnsAsync(null as Comment);
            var commentBl = new CommentBl(_mockCommentRepo.Object, _mockMapper, _mockProjectUserRepo.Object,
                                          _mockProjectRepo.Object, _mockSprintRepository.Object);
            await Assert.ThrowsAsync <NotFoundResponseException>(() => commentBl.DeleteAsync(It.IsAny <int>(), It.IsAny <string>()));

            _mockCommentRepo.Verify(repository => repository.DeleteAsync(It.IsAny <int>()), Times.Never);
        }
Пример #2
0
        public async Task CheckDevCantDeleteNotHimselfComment(string userId)
        {
            _mockCommentRepo.Setup(repository => repository.ReadAsync(It.IsAny <int>()))
            .ReturnsAsync(GetTestComments()[0]);
            _mockProjectUserRepo.Setup(r => r.GetRoleOfMember("dev1", It.IsAny <int>())).ReturnsAsync(AppUserRole.Developer);
            _mockSprintRepository.Setup(r => r.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(ItemBlTests.GetTestSprints()[0]);
            _mockProjectRepo.Setup(r => r.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(ItemBlTests.GetTestProjects()[0]);

            var commentBl = new CommentBl(_mockCommentRepo.Object, _mockMapper, _mockProjectUserRepo.Object,
                                          _mockProjectRepo.Object, _mockSprintRepository.Object);
            await Assert.ThrowsAsync <ForbiddenResponseException>(() => commentBl.DeleteAsync(It.IsAny <int>(), userId));

            _mockCommentRepo.Verify(repository => repository.DeleteAsync(It.IsAny <int>()), Times.Never);
        }
Пример #3
0
        public async Task CheckDevCanDeleteHimselfComment(string userId)
        {
            _mockCommentRepo.Setup(repository => repository.ReadAsync(It.IsAny <int>()))
            .ReturnsAsync(GetTestComments()[0]);
            _mockProjectUserRepo.Setup(r => r.GetRoleOfMember("dev", It.IsAny <int>())).ReturnsAsync(AppUserRole.Developer);
            _mockSprintRepository.Setup(r => r.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(ItemBlTests.GetTestSprints()[0]);
            _mockProjectRepo.Setup(r => r.GetByIdAsync(It.IsAny <int>())).ReturnsAsync(ItemBlTests.GetTestProjects()[0]);

            var commentBl = new CommentBl(_mockCommentRepo.Object, _mockMapper, _mockProjectUserRepo.Object,
                                          _mockProjectRepo.Object, _mockSprintRepository.Object);
            var response = await commentBl.DeleteAsync(It.IsAny <int>(), userId);

            Assert.IsAssignableFrom <ItemResponse>(response);
            Assert.True(response.Success);
            _mockCommentRepo.Verify(repository => repository.DeleteAsync(It.IsAny <int>()), Times.Once);
        }