public async Task GetStockItemAsync_Throws_NotFoundException() { //Arrange var id = 201; _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.GetStockItemAsync(id)); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.NotFound); exception.ErrorMessage.Should().Be("Stock item not found."); exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString()); }
public async Task GetStockItemAsync_Returns_GetStockItemDto() { //Arrange var id = 1; _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 result = await repository.GetStockItemAsync(id); //Assert result.Should().BeOfType(typeof(GetStockItemDto)); result.Id.Should().Be(id); result.Name.Should().Be("Rice"); result.StockType.Should().Be("Grocery"); result.UnitOfMeasureCode.Should().Be("kg"); }