Пример #1
0
        public async Task GetStockTypeAsync_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)));

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

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

            //Assert
            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound);
            exception.ErrorMessage.Should().Be("Stock type not found.");
            exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString());
        }
Пример #2
0
        public async Task GetStockTypeAsync_Returns_GetStockTypeDto()
        {
            //Arrange
            var id = 1;

            _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)));

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

            //Act
            var result = await repository.GetStockTypeAsync(id);

            //Assert
            result.Should().BeOfType(typeof(GetStockTypeDto));
            result.Id.Should().Be(id);
            result.Type.Should().Be("Grocery");
            result.Description.Should().Be("");
        }