Example #1
0
        public async Task DeleteGoodsReceivedNoteItemAsync_Returns_NoResult()
        {
            //Arrange
            var id = 2;

            _fixture.MockGoodsReceivedNoteItemService.Setup(x => x.GetGoodsReceivedNoteItemAsync(It.IsAny <Expression <Func <GoodsReceivedNoteItem, bool> > >()))
            .Returns <Expression <Func <GoodsReceivedNoteItem, bool> > >(expression => Task.FromResult(_fixture.GoodsReceivedNoteItems.AsQueryable().FirstOrDefault(expression)));

            _fixture.MockGoodsReceivedNoteItemService.Setup(x => x.DeleteGoodsReceivedNoteItemAsync(It.IsAny <GoodsReceivedNoteItem>()));

            var repository = new GoodsReceivedNoteItemRepository(AutoMapperSingleton.Mapper, _fixture.MockGoodsReceivedNoteItemService.Object);

            //Act
            await repository.DeleteGoodsReceivedNoteItemAsync(id);

            // Assert
            _fixture.MockGoodsReceivedNoteItemService.Verify(x => x.DeleteGoodsReceivedNoteItemAsync(It.IsAny <GoodsReceivedNoteItem>()), Times.Once);
        }
Example #2
0
        public async Task DeleteGoodsReceivedNoteItemAsync_Throws_NotFoundException()
        {
            //Arrange
            var id = 201;

            _fixture.MockGoodsReceivedNoteItemService.Setup(x => x.GetGoodsReceivedNoteItemAsync(It.IsAny <Expression <Func <GoodsReceivedNoteItem, bool> > >()))
            .Returns <Expression <Func <GoodsReceivedNoteItem, bool> > >(expression => Task.FromResult(_fixture.GoodsReceivedNoteItems.AsQueryable().FirstOrDefault(expression)));

            _fixture.MockGoodsReceivedNoteItemService.Setup(x => x.DeleteGoodsReceivedNoteItemAsync(It.IsAny <GoodsReceivedNoteItem>()));

            var repository = new GoodsReceivedNoteItemRepository(AutoMapperSingleton.Mapper, _fixture.MockGoodsReceivedNoteItemService.Object);

            //Act
            var exception = await Assert.ThrowsAsync <RestException>(() => repository.DeleteGoodsReceivedNoteItemAsync(id));

            //Assert
            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound);
            exception.ErrorMessage.Should().Be("Goods received note item not found.");
            exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString());
        }