示例#1
0
        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);
        }
示例#2
0
        public async Task CheckGetRelatedItemsIfNotExistThrowException(int itemId)
        {
            _itemRelationRepo.Setup(repo => repo.GetRelatedItems(itemId)).ReturnsAsync(null as List <ItemRelation>);

            ItemRelationBl itemRelationBl = new ItemRelationBl(_mockItemRepo.Object, _mockMapper,
                                                               _itemRelationRepo.Object, _mockProjectUserRepo.Object, _mockProjectRepo.Object,
                                                               _mockSprintRepository.Object);

            await Assert.ThrowsAsync <NotFoundResponseException>(() => itemRelationBl.GetRelatedItemsAsync(itemId));
        }
示例#3
0
        public async Task CheckGetRelatedItemsReturnListOfItemDto(int itemId)
        {
            _itemRelationRepo.Setup(repo => repo.GetRelatedItems(itemId)).ReturnsAsync(GetTestRelations());

            ItemRelationBl itemRelationBl = new ItemRelationBl(_mockItemRepo.Object, _mockMapper,
                                                               _itemRelationRepo.Object, _mockProjectUserRepo.Object, _mockProjectRepo.Object,
                                                               _mockSprintRepository.Object);

            var response = await itemRelationBl.GetRelatedItemsAsync(itemId);

            Assert.IsAssignableFrom <IEnumerable <ItemDto> >(response);
            Assert.NotNull(response);
        }
示例#4
0
        public async Task CheckGetRecordReturnItemRelation(int firstItemId, int secondItemId)
        {
            _itemRelationRepo.Setup(repo => repo.GetRecordAsync(firstItemId, secondItemId))
            .ReturnsAsync(GetTestRelations()[0]);

            ItemRelationBl itemRelationBl = new ItemRelationBl(_mockItemRepo.Object, _mockMapper,
                                                               _itemRelationRepo.Object, _mockProjectUserRepo.Object, _mockProjectRepo.Object,
                                                               _mockSprintRepository.Object);

            var response = await itemRelationBl.GetRecordAsync(firstItemId, secondItemId);

            Assert.IsAssignableFrom <ItemRelation>(response);
            Assert.NotNull(response);
        }
示例#5
0
        public async Task CheckDeleteNotExistRelationThrowsException(int firstItemId, int secondItemId, string userId)
        {
            _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);

            await Assert.ThrowsAsync <ForbiddenResponseException>(() =>
                                                                  itemRelationBl.DeleteRecordAsync(firstItemId, secondItemId, userId));
        }
示例#6
0
        public async Task CheckDeleteRelationReturnsOk(int firstItemId, int secondItemId, string userId)
        {
            _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);

            var response = await itemRelationBl.DeleteRecordAsync(firstItemId, secondItemId, userId);

            Assert.True(response.Success);
        }
示例#7
0
        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));
        }