Beispiel #1
0
        public async Task UpdateStockTypeAsync_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.UpdateStockTypeAsync(It.IsAny <StockType>()));

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

            //Act
            var exception = await Assert.ThrowsAsync <RestException>(() => repository.UpdateStockTypeAsync(id, _fixture.EditStockTypeDto));

            //Assert
            exception.ErrorCode.Should().Be(HttpStatusCode.NotFound);
            exception.ErrorMessage.Should().Be("Stock type not found.");
            exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString());
        }
Beispiel #2
0
        public async Task UpdateStockTypeAsync_Returns_Updated_GetStockTypeDto()
        {
            //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.UpdateStockTypeAsync(It.IsAny <StockType>()));

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

            //Act
            var result = await repository.UpdateStockTypeAsync(id, _fixture.EditStockTypeDto);

            //Assert
            result.Should().BeOfType(typeof(GetStockTypeDto));
            result.Id.Should().Be(id);
            result.Type.Should().Be(_fixture.EditStockTypeDto.Type);
            result.Description.Should().Be(_fixture.EditStockTypeDto.Description);
        }
Beispiel #3
0
        public async Task UpdateStockTypeAsync_Throws_ConflictException()
        {
            //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.UpdateStockTypeAsync(It.IsAny <StockType>()));

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

            //Act
            var exception = await Assert.ThrowsAsync <RestException>(() => repository.UpdateStockTypeAsync(id, new EditStockTypeDto {
                Type = "Grocery", Description = ""
            }));

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