public async Task ApprovalPurchaseOrderAsync_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.UpdatePurchaseOrderAsync(It.IsAny <PurchaseOrder>())); var repository = new PurchaseOrderRepository(AutoMapperSingleton.Mapper, _fixture.MockPurchaseOrderService.Object, _fixture.MockUserAccessorService.Object); //Act var exception = await Assert.ThrowsAsync <RestException>(() => repository.ApprovalPurchaseOrderAsync(id, _fixture.ApprovalPurchaseOrderDto)); //Assert exception.ErrorCode.Should().Be(HttpStatusCode.NotFound); exception.ErrorMessage.Should().Be("Purchase order not found."); exception.ErrorType.Should().Be(HttpStatusCode.NotFound.ToString()); }
public async Task ApprovalPurchaseOrderAsync_Returns_Approval_GetPurchaseOrderDto() { //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.UpdatePurchaseOrderAsync(It.IsAny <PurchaseOrder>())) .Returns(Task.FromResult(_fixture.ApprovedPurchaseOrder)); _fixture.MockUserAccessorService.Setup(x => x.GetCurrentUser()).Returns(_fixture.CurrentUser); var repository = new PurchaseOrderRepository(AutoMapperSingleton.Mapper, _fixture.MockPurchaseOrderService.Object, _fixture.MockUserAccessorService.Object); //Act var result = await repository.ApprovalPurchaseOrderAsync(id, _fixture.ApprovalPurchaseOrderDto); //Assert result.Should().BeOfType(typeof(GetPurchaseOrderDto)); result.Id.Should().Be(id); result.OrderNumber.Should().Be("PO_20210130_8d8c512f7cd7920"); result.ApprovalStatus.Should().Be("Rejected"); }