public void PatchInvoice_EmptyId_ExceptionRaised()
        {
            var client       = CreateClient();
            var patchInvoice = new PatchInvoice
            {
                Id = Guid.Empty
            };
            var ex = Assert.Throws <WebServiceException>(() => client.Patch <InvoiceResponse>(patchInvoice));

            Assert.IsTrue(ex.ErrorCode == "NotEqual");
            Assert.IsTrue(ex.ErrorMessage == "Specify nonempty Id for Invoice.");
        }
        public void PatchInvoice_NonExistingId_ExceptionRaised()
        {
            var  client        = CreateClient();
            Guid nonExistingId = Guid.NewGuid();
            var  patchInvoice  = new PatchInvoice
            {
                Id = nonExistingId
            };
            var ex = Assert.Throws <WebServiceException>(() => client.Patch <InvoiceResponse>(patchInvoice));

            Assert.IsTrue(ex.ErrorCode == "NotFound");
            Assert.IsTrue(ex.ErrorMessage == $"There is no Invoice with id : {nonExistingId}");
        }
예제 #3
0
        public InvoiceResponse Patch(PatchInvoice request)
        {
            InvoiceModel invoice = null;

            try
            {
                using (var session = mongoDbContext.StartSession())
                {
                    session.StartTransaction();

                    try
                    {
                        invoice = invoiceRepository.Find(session, request.Id);
                        if (invoice == default(InvoiceModel))
                        {
                            throw HttpError.NotFound($"There is no Invoice with id : {request.Id}");
                        }
                        foreach (InvoiceLineModel invoiceLine in invoice.Lines)
                        {
                            if (invoiceLine.IsPaired)
                            {
                                continue;
                            }
                            var purchaseOrder = purchaseOrderRepository.List(session, po => po.Number == invoiceLine.PoNumber && po.CustomerId == invoice.CustomerId).FirstOrDefault();
                            var pairedPOLine  = purchaseOrder.Lines.Where(pol => pol.Description == invoiceLine.Description && pol.Quantity == invoiceLine.Quantity).FirstOrDefault();
                            pairedPOLine.IsPaired = true;
                            invoiceLine.IsPaired  = true;
                            var poReplaceResult = purchaseOrderRepository.Update(session, purchaseOrder);
                        }
                        var invoiceReplaceResult = invoiceRepository.Update(session, invoice);

                        session.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        session.AbortTransaction();
                        Log.Error(ex, "Something went wrong with transaction while pairing Invoice to PO.");
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Something general went wrong while pairing Invoice to PO.");
                throw;
            }

            return(invoice?.ConvertTo <InvoiceResponse>());
        }
예제 #4
0
        public void PairInvoiceToPO_CanBePaired_PairedInvoiceReturned()
        {
            var createInvoice = new CreateInvoice
            {
                Number      = "INV00900300",
                CreatedDate = DateTime.Now,
                DueDate     = DateTime.Now.Date.AddDays(30),
                CustomerId  = starbucksBPResponse.Id,
                VendorId    = microsoftBPResponse.Id,
                TaxAmount   = 368.99,
                NetAmount   = 1844.95,
                TotalPrice  = 2213.94,
                Lines       = new List <InvoiceLine>()
                {
                    new InvoiceLine
                    {
                        Description = "Xbox One S NBA 2K20 Bundle (1TB)",
                        Quantity    = 5,
                        UnitPrice   = 299,
                        TaxRate     = 20,
                        TaxAmount   = 299,
                        TotalPrice  = 1794,
                        PoNumber    = "PO000100",
                        IsPaired    = false
                    },
                    new InvoiceLine
                    {
                        Description = "WRC 9 Deluxe Edition FIA World Rally Championship",
                        Quantity    = 5,
                        UnitPrice   = 69.99,
                        TaxRate     = 20,
                        TaxAmount   = 69.99,
                        TotalPrice  = 419.94,
                        PoNumber    = "PO000101",
                        IsPaired    = false
                    }
                }
            };

            var invoiceService = appHost.Container.Resolve <InvoiceService>();
            var invoiceToPair  = invoiceService.Post(createInvoice);

            var createPO100 = new CreatePurchaseOrder
            {
                Number     = "PO000100",
                CustomerId = starbucksBPResponse.Id,
                Lines      = new List <PurchaseOrderLine>()
                {
                    new PurchaseOrderLine
                    {
                        Description = "Xbox One S NBA 2K20 Bundle (1TB)",
                        Quantity    = 5,
                        IsPaired    = false
                    },
                    new PurchaseOrderLine
                    {
                        Description = "Xbox One S Star Wars Jedi: Fallen Order Bundle (1TB)",
                        Quantity    = 5,
                        IsPaired    = false
                    }
                }
            };
            var createPO101 = new CreatePurchaseOrder
            {
                Number     = "PO000101",
                CustomerId = starbucksBPResponse.Id,
                Lines      = new List <PurchaseOrderLine>()
                {
                    new PurchaseOrderLine
                    {
                        Description = "WRC 9 Deluxe Edition FIA World Rally Championship",
                        Quantity    = 5,
                        IsPaired    = false
                    },
                    new PurchaseOrderLine
                    {
                        Description = "Tony Hawk’s Pro Skater 1 + 2",
                        Quantity    = 5,
                        IsPaired    = false
                    }
                }
            };

            var poService   = appHost.Container.Resolve <PurchaseOrderService>();
            var poToPair100 = poService.Post(createPO100);
            var poToPair101 = poService.Post(createPO101);

            var patchInvoice = new PatchInvoice
            {
                Id = invoiceToPair.Id
            };

            var pairedInvoice = invoiceService.Patch(patchInvoice);

            Assert.IsTrue(pairedInvoice.Lines.Where(l => l.IsPaired).Count() == 2);

            var getPO = new GetPurchaseOrder
            {
                Id = poToPair100.Id
            };
            var partialyPairedPO100 = poService.Get(getPO);

            Assert.IsTrue(partialyPairedPO100.Lines.Where(l => l.IsPaired).Count() == 1);
            getPO.Id = poToPair101.Id;
            var partialyPairedPO101 = poService.Get(getPO);

            Assert.IsTrue(partialyPairedPO101.Lines.Where(l => l.IsPaired).Count() == 1);
        }