public async Task CheckCreateRelationReturnOk(int firstItemId, int secondItemId, string userId) { _mockItemRepo.Setup(repo => repo.ReadAsync(firstItemId)).ReturnsAsync(ItemBlTests.GetTestItems()[0]); _mockItemRepo.Setup(repo => repo.ReadAsync(secondItemId)).ReturnsAsync(ItemBlTests.GetTestItems()[1]); _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]); _itemRelationRepo.Setup(repo => repo.GetRecordAsync(firstItemId, secondItemId)) .ReturnsAsync(null as ItemRelation); _itemRelationRepo.Setup(repo => repo.GetRecordAsync(secondItemId, firstItemId)) .ReturnsAsync(null as ItemRelation); ItemRelationBl itemRelationBl = new ItemRelationBl(_mockItemRepo.Object, _mockMapper, _itemRelationRepo.Object, _mockProjectUserRepo.Object, _mockProjectRepo.Object, _mockSprintRepository.Object); var response = await itemRelationBl.CreateRecordAsync(firstItemId, secondItemId, userId); Assert.True(response.Success); }
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); }
public async Task CheckCreateExistRelationThrowsException(int firstItemId, int secondItemId, string userId) { _mockItemRepo.Setup(repo => repo.ReadAsync(firstItemId)).ReturnsAsync(ItemBlTests.GetTestItems()[0]); _mockItemRepo.Setup(repo => repo.ReadAsync(secondItemId)).ReturnsAsync(ItemBlTests.GetTestItems()[1]); _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]); _itemRelationRepo.Setup(repo => repo.GetRecordAsync(firstItemId, secondItemId)) .ReturnsAsync(GetTestRelations()[0]); _itemRelationRepo.Setup(repo => repo.GetRecordAsync(secondItemId, firstItemId)) .ReturnsAsync(GetTestRelations()[1]); ItemRelationBl itemRelationBl = new ItemRelationBl(_mockItemRepo.Object, _mockMapper, _itemRelationRepo.Object, _mockProjectUserRepo.Object, _mockProjectRepo.Object, _mockSprintRepository.Object); await Assert.ThrowsAsync <ForbiddenResponseException>(() => itemRelationBl.CreateRecordAsync(firstItemId, secondItemId, userId)); }
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); }