public async Task DeletePurchaseOrderAsync_Returns_NoResult() { //Arrange var id = 2; _fixture.MockPurchaseOrderService.Setup(x => x.GetPurchaseOrderAsync(It.IsAny <Expression <Func <PurchaseOrder, bool> > >())) .Returns <Expression <Func <PurchaseOrder, bool> > >(expression => Task.FromResult(_fixture.PurchaseOrders.AsQueryable().FirstOrDefault(expression))); _fixture.MockPurchaseOrderService.Setup(x => x.DeletePurchaseOrderAsync(It.IsAny <PurchaseOrder>())); var repository = new PurchaseOrderRepository(AutoMapperSingleton.Mapper, _fixture.MockPurchaseOrderService.Object, _fixture.MockUserAccessorService.Object); //Act await repository.DeletePurchaseOrderAsync(id); // Assert _fixture.MockPurchaseOrderService.Verify(x => x.DeletePurchaseOrderAsync(It.IsAny <PurchaseOrder>()), Times.Once); }
public async Task DeletePurchaseOrderAsync_Throws_NotFoundException() { //Arrange var id = 201; _fixture.MockPurchaseOrderService.Setup(x => x.GetPurchaseOrderAsync(It.IsAny <Expression <Func <PurchaseOrder, bool> > >())) .Returns <Expression <Func <PurchaseOrder, bool> > >(expression => Task.FromResult(_fixture.PurchaseOrders.AsQueryable().FirstOrDefault(expression))); _fixture.MockPurchaseOrderService.Setup(x => x.DeletePurchaseOrderAsync(It.IsAny <PurchaseOrder>())); var repository = new PurchaseOrderRepository(AutoMapperSingleton.Mapper, _fixture.MockPurchaseOrderService.Object, _fixture.MockUserAccessorService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.DeletePurchaseOrderAsync(id)); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.NotFound); exception.ErrorMessage.Should().Be("Purchase order not found."); exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString()); }