Beispiel #1
0
        public void BuildOrders()
        {
            var products  = DbPreTestDataWorker.ProductService.GetAll().ToArray();
            var addresses = MockDataMakerBase.FakeAddresses().Where(x => x.CountryCode == "US").ToArray();

            var maxProductIndex = products.Count() - 1;
            var maxAddressIndex = addresses.Count();

            var itemCount = MockDataMakerBase.NoWhammyStop.Next(11);

            var invoiceDate = DateTime.Today.AddDays(-1 * InvoiceCount);

            for (var j = 0; j < InvoiceCount; j++)
            {
                if (j % 2 == 0)
                {
                    CurrentCustomer = DbPreTestDataWorker.MakeExistingAnonymousCustomer();
                }

                for (var i = 0; i < itemCount; i++)
                {
                    CurrentCustomer.Basket().AddItem(products[MockDataMakerBase.NoWhammyStop.Next(maxProductIndex)], MockDataMakerBase.NoWhammyStop.Next(5));
                }
                CurrentCustomer.Basket().Save();



                // Customer enters the destination shipping address
                var destination = addresses[MockDataMakerBase.NoWhammyStop.Next(maxAddressIndex)];

                // Assume customer selects billing address is same as shipping address
                CurrentCustomer.Basket().SalePreparation().SaveBillToAddress(destination);

                // --------------- ShipMethod Selection ----------------------------------

                // Package the shipments
                //
                // This should return a collection containing a single shipment
                //
                var shipments = CurrentCustomer.Basket().PackageBasket(destination).ToArray();

                var shipment = shipments.FirstOrDefault();

                if (shipment != null)
                {
                    var shipRateQuotes = shipment.ShipmentRateQuotes().ToArray();

                    CurrentCustomer.Basket().SalePreparation().SaveShipmentRateQuote(shipRateQuotes.First());
                }

                var paymentMethods = CurrentCustomer.Basket().SalePreparation().GetPaymentGatewayMethods();


                IPaymentResult paymentResult;
                paymentResult = invoiceDate.Month < DateTime.Now.AddDays(-30).Month
                    ?
                                CurrentCustomer.Basket()
                                .SalePreparation()
                                .AuthorizeCapturePayment(paymentMethods.FirstOrDefault())
                    :
                                CurrentCustomer.Basket()
                                .SalePreparation()
                                .AuthorizePayment(paymentMethods.FirstOrDefault());

                var invoice = paymentResult.Invoice;

                invoice.InvoiceDate = invoiceDate;

                invoiceDate = invoiceDate.AddDays(1);

                DbPreTestDataWorker.InvoiceService.Save(invoice);
            }
        }