public async Task DeletePurchaseOrderItemAsync_Returns_NoResult() { //Arrange var id = 2; _fixture.MockPurchaseOrderItemService.Setup(x => x.GetPurchaseOrderItemAsync(It.IsAny <Expression <Func <PurchaseOrderItem, bool> > >())) .Returns <Expression <Func <PurchaseOrderItem, bool> > >(expression => Task.FromResult(_fixture.PurchaseOrderItems.AsQueryable().FirstOrDefault(expression))); _fixture.MockPurchaseOrderItemService.Setup(x => x.DeletePurchaseOrderItemAsync(It.IsAny <PurchaseOrderItem>())); var repository = new PurchaseOrderItemRepository(AutoMapperSingleton.Mapper, _fixture.MockPurchaseOrderItemService.Object); //Act await repository.DeletePurchaseOrderItemAsync(id); // Assert _fixture.MockPurchaseOrderItemService.Verify(x => x.DeletePurchaseOrderItemAsync(It.IsAny <PurchaseOrderItem>()), Times.Once); }
public async Task DeletePurchaseOrderItemAsync_Throws_NotFoundException() { //Arrange var id = 201; _fixture.MockPurchaseOrderItemService.Setup(x => x.GetPurchaseOrderItemAsync(It.IsAny <Expression <Func <PurchaseOrderItem, bool> > >())) .Returns <Expression <Func <PurchaseOrderItem, bool> > >(expression => Task.FromResult(_fixture.PurchaseOrderItems.AsQueryable().FirstOrDefault(expression))); _fixture.MockPurchaseOrderItemService.Setup(x => x.DeletePurchaseOrderItemAsync(It.IsAny <PurchaseOrderItem>())); var repository = new PurchaseOrderItemRepository(AutoMapperSingleton.Mapper, _fixture.MockPurchaseOrderItemService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.DeletePurchaseOrderItemAsync(id)); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.NotFound); exception.ErrorMessage.Should().Be("Purchase order item not found."); exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString()); }