public async Task CreateStockItemAsync_Throws_ConflictException() { //Arrange _fixture.MockStockItemService.Setup(x => x.GetStockItemAsync(It.IsAny <Expression <Func <StockItem, bool> > >())) .Returns <Expression <Func <StockItem, bool> > >(expression => Task.FromResult(_fixture.StockItems.AsQueryable().FirstOrDefault(expression))); var repository = new StockItemRepository(AutoMapperSingleton.Mapper, _fixture.MockStockItemService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.CreateStockItemAsync(new CreateStockItemDto { Name = "Rice", TypeId = 1, UnitOfMeasureId = 1, ItemUnit = 10 })); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.Conflict); exception.ErrorMessage.Should().Be("Stock item is already available."); exception.ErrorType.Should().Be(HttpStatusCode.Conflict.ToString()); }
public async Task CreateStockItemAsync_Returns_New_GetStockItemDto() { //Arrange _fixture.MockStockItemService.Setup(x => x.AddStockItemAsync(It.IsAny <StockItem>())) .ReturnsAsync(_fixture.CreatedNewStockItem); var repository = new StockItemRepository(AutoMapperSingleton.Mapper, _fixture.MockStockItemService.Object); //Act var result = await repository.CreateStockItemAsync(_fixture.CreateStockItemDto); //Assert result.Should().BeOfType(typeof(GetStockItemDto)); result.Id.Should().Be(5); result.Name.Should().Be("Cream Soda"); result.StockType.Should().Be("Beverage"); result.UnitOfMeasureCode.Should().Be("ml"); }