public void CanBuildASalerWithOneItemAndCashPaymentInfo()
        {
            //Given
            var orderAndContext = AFullyPaidCashSaleAndContext();
            var order = orderAndContext.Sale;
            var context = orderAndContext.Context;

            var builder = new SaleEnvelopeBuilder(order, new MainOrderEnvelopeBuilder(context));

            //When 
            var result = builder.Build();
            
            //Then
            AssertCommonEnvelopeChecks(result, context);

            var documentCommands = ExtractDocumentCommands(result);

            //Check Create Order Command
            var createOrder = documentCommands.OfType<CreateMainOrderCommand>().First();
            Assert.AreEqual(order.ShipToAddress, createOrder.ShipToAddress, "Ship To Address");
            Assert.AreEqual(order.SaleDiscount, createOrder.SaleDiscount, "Sale Discount");
            Assert.AreEqual((int)order.OrderType, createOrder.OrderTypeId, "Sale Type");
            Assert.AreEqual(context.IssuedOnBehalfOfCostCentre, createOrder.IssuedOnBehalfOfCostCentreId, "IssuedOnBehalfOfCostCentreId");

            CheckReference("S", createOrder.DocumentReference, context.User.Username);

            var addMainOrderLineItems = documentCommands.OfType<AddMainOrderLineItemCommand>().ToList();

            CheckOrderLineCommand(order.LineItems[0], addMainOrderLineItems[0]);

            //Check order payment info
            var orderPaymentInfo = documentCommands.OfType<AddOrderPaymentInfoCommand>().First();
            CheckOrderPaymentInfo(order, orderPaymentInfo);
        }
        public void CanCreateAnInvoiceEnvelope()
        {
            //Given 
            var saleAndContext = AFullyPaidCashSaleAndContext();
            var order = saleAndContext.Sale;
            var context = saleAndContext.Context;

            var builder = new SaleEnvelopeBuilder(order, new InvoiceEnvelopeBuilder(context));

            //When 
            var result = builder.Build();

            //Then
            AssertCommonEnvelopeChecks(result, context);

            Assert.AreEqual(context.InvoiceId, result[0].DocumentId, "DocumentId");

            var documentCommands = ExtractDocumentCommands(result);

            //Check Create Invoice
            var createInvoice = documentCommands.OfType<CreateInvoiceCommand>().First();
            Assert.AreEqual(context.ParentDocumentId, createInvoice.OrderId, "Order Id");
            Assert.AreEqual(order.SaleDiscount, createInvoice.SaleDiscount, "Sale Discount");
            Assert.AreEqual(context.GeneratedByCostCentreId, createInvoice.DocumentIssuerCostCentreId, "DocumentIssuerCostCentreId");
            Assert.AreEqual(context.RecipientCostCentreId, createInvoice.DocumentRecipientCostCentreId, "DocumentRecipientCostCentreId");

            CheckReference("I", createInvoice.DocumentReference, context.User.Username);

            var addInvoiceLineItems = documentCommands.OfType<AddInvoiceLineItemCommand>().ToList();

            CheckAddInvoiceLineItemCommand(order.LineItems[0], addInvoiceLineItems[0]);
        }
        public void CanCreateAnInventoryAdjustmentNoteEnvelope()
        {
            //Given 
            var saleAndContext = AFullyPaidCashSaleAndContext();
            var order = saleAndContext.Sale;
            var context = saleAndContext.Context;
            var invtentoryRepository = new Mock<IInventoryRepository>();
            
            const int availableStock = 2;
            
            invtentoryRepository.Setup(i => i.GetBalanceForProduct(order.LineItems[0].ProductMasterId)).Returns(availableStock);

            var builder = new SaleEnvelopeBuilder(order, new InventoryAdjustmentNoteEnvelopeBuilder(context, invtentoryRepository.Object));

            //When 
            var result = builder.Build();

            //Then
            AssertCommonEnvelopeChecks(result, context);

            var documentCommands = ExtractDocumentCommands(result);

            //Check CreateInventoryAdjustmentNote
            var createInventoryAdjustmentNote = documentCommands.OfType<CreateInventoryAdjustmentNoteCommand>().First();
            Assert.AreEqual(context.RecipientCostCentreId, createInventoryAdjustmentNote.DocumentRecipientCostCentreId, "DocumentRecipientCostCentreId");
            Assert.AreEqual((int)InventoryAdjustmentNoteType.Available, createInventoryAdjustmentNote.InventoryAdjustmentNoteTypeId, "InventoryAdjustmentNoteTypeId");

            //Check InventoryAdjustmentNoteLineItem
            var inventoryAdjustmentNoteLineItem = documentCommands.OfType<AddInventoryAdjustmentNoteLineItemCommand>().First();
            CheckInventoryAdjustmentNoteLineCommand(order.LineItems[0], inventoryAdjustmentNoteLineItem, availableStock);
        }
        public void CanCreateAReceiptEnvelope()
        {
            //Given
            var saleAndContext = AFullyPaidCashSaleAndContext();
            var sale = saleAndContext.Sale;
            var context = saleAndContext.Context;

            var builder = new SaleEnvelopeBuilder(sale, new ReceiptEnvelopeBuilder(context));

            //When 
            var result = builder.Build();

            //Then
            AssertCommonEnvelopeChecks(result, context);

            var documentCommands = ExtractDocumentCommands(result);

            var createReceipt = documentCommands.OfType<CreateReceiptCommand>().First();
            CheckReference("R", createReceipt.DocumentReference, context.User.Username);

            //Check Receipt Line Item
            var addReceiptLineItem = documentCommands.OfType<AddReceiptLineItemCommand>().First();

            CheckReceiptLineItem(sale, addReceiptLineItem);
        }
        public void CanGenerateAnExternalDocRefEnvelope()
        {
            //Given 
            var saleAndContext = AFullyPaidCashSaleAndContext();
            var sale = saleAndContext.Sale;
            var context = saleAndContext.Context;

            var builder = new SaleEnvelopeBuilder(sale, new ExternalDocRefEnvelopeBuilder(context));

            //When 
            var result = builder.Build();

            //Then
            AssertCommonEnvelopeChecks(result, context);

            var documentCommands = ExtractDocumentCommands(result);

            var extDocRef = documentCommands.OfType<AddExternalDocRefCommand>().First();
            Assert.AreEqual(context.ExternalDocumentReference(), extDocRef.ExternalDocRef, "Ext Doc Ref");
        }
Example #6
0
        public Result<object> Process(Sale sale, IEnvelopeContext context)
        {

            var envelopeBuilder = new SaleEnvelopeBuilder(sale,
                new MainOrderEnvelopeBuilder(context,
                new CloseOrderEnvelopeBuilder(context,
                new ExternalDocRefEnvelopeBuilder(context,
                new DispatchNoteEnvelopeBuilder(context,
                new InvoiceEnvelopeBuilder(context,
                new PaymentNoteEnvelopeBuilder(context,
                new ReceiptEnvelopeBuilder(context,
                new InventoryAdjustmentNoteEnvelopeBuilder(context, inventoryRepository,
                new OutletVisitNoteEnvelopeBuilder(context))))))))));

            return new Transactor(database).Transact(() =>
            {
                envelopeBuilder.Build().ForEach(e => envelopeRouter.RouteCommandEnvelope(e));
                inventoryRepository.AdjustInventoryForSale(sale);
                sale.OrderReference = context.OrderSaleReference();
                sale.ConfirmNewPayments();
                sale.ProcessingStatus = ProcessingStatus.Confirmed;
                saleRepository.Save(sale);
            });
        }