Esempio n. 1
0
        public async Task CreateStockTypeAsync_Returns_New_GetStockTypeDto()
        {
            //Arrange
            _fixture.MockStockTypeService.Setup(x => x.AddStockTypeAsync(It.IsAny <StockType>()))
            .ReturnsAsync(_fixture.CreatedNewStockType);

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

            //Act
            var result = await repository.CreateStockTypeAsync(_fixture.CreateStockTypeDto);

            //Assert
            result.Should().BeOfType(typeof(GetStockTypeDto));
            result.Id.Should().Be(3);
            result.Type.Should().Be(_fixture.CreateStockTypeDto.Type);
            result.Description.Should().Be(_fixture.CreateStockTypeDto.Description);
        }
Esempio n. 2
0
        public async Task CreateStockTypeAsync_Throws_ConflictException()
        {
            //Arrange
            _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.CreateStockTypeAsync(new CreateStockTypeDto {
                Type = "Beverage", Description = ""
            }));

            //Assert
            exception.ErrorCode.Should().Be(HttpStatusCode.Conflict);
            exception.ErrorMessage.Should().Be("Stock type \"Beverage\" is already available.");
            exception.ErrorType.Should().Be(HttpStatusCode.Conflict.ToString());
        }