Exemplo n.º 1
0
        public async Task DeleteStockTypeAsync_Returns_NoResult()
        {
            //Arrange
            var id = 2;

            _fixture.MockStockTypeService.Setup(x => x.GetStockTypeAsync(It.IsAny <Expression <Func <StockType, bool> > >()))
            .Returns <Expression <Func <StockType, bool> > >(expression => Task.FromResult(_fixture.StockTypes.AsQueryable().FirstOrDefault(expression)));

            _fixture.MockStockTypeService.Setup(x => x.DeleteStockTypeAsync(It.IsAny <StockType>()));

            var repository = new StockTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockStockTypeService.Object);

            //Act
            await repository.DeleteStockTypeAsync(id);

            // Assert
            _fixture.MockStockTypeService.Verify(x => x.DeleteStockTypeAsync(It.IsAny <StockType>()), Times.Once);
        }
Exemplo n.º 2
0
        public async Task DeleteStockTypeAsync_Throws_NotFoundException()
        {
            //Arrange
            var id = 201;

            _fixture.MockStockTypeService.Setup(x => x.GetStockTypeAsync(It.IsAny <Expression <Func <StockType, bool> > >()))
            .Returns <Expression <Func <StockType, bool> > >(expression => Task.FromResult(_fixture.StockTypes.AsQueryable().FirstOrDefault(expression)));

            _fixture.MockStockTypeService.Setup(x => x.DeleteStockTypeAsync(It.IsAny <StockType>()));

            var repository = new StockTypeRepository(AutoMapperSingleton.Mapper, _fixture.MockStockTypeService.Object);

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

            //Assert
            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound);
            exception.ErrorMessage.Should().Be("Stock type not found.");
            exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString());
        }