コード例 #1
0
 private void WriteBasketInfoToConsole()
 {
     Console.WriteLine("----------- Basket Item Info ---------------------");
     Console.WriteLine("Total quantity count: {0}", CurrentCustomer.Basket().TotalQuantityCount);
     Console.WriteLine("Total basket price: {0}", CurrentCustomer.Basket().TotalBasketPrice);
     Console.WriteLine("Total item count: {0}", CurrentCustomer.Basket().TotalItemCount);
 }
コード例 #2
0
        public void Can_Generate_An_Invoice_For_Preview()
        {
            //// Arrange
            CurrentCustomer.Basket().AddItem(_product1, 10);
            CurrentCustomer.Basket().AddItem(_product2, 5);
            CurrentCustomer.Basket().AddItem(_product3, 1);

            this.CurrentCustomer.Basket().Save();
            var shipping = MockAddressMaker.GetAddress("US");
            var billing  = MockAddressMaker.GetAddress("US");

            var checkoutManager = this.CurrentCustomer.Basket().GetCheckoutManager();

            checkoutManager.Customer.SaveShipToAddress(shipping);
            checkoutManager.Customer.SaveBillToAddress(billing);

            var shipment = this.CurrentCustomer.Basket().PackageBasket(shipping).FirstOrDefault();
            var quotes   = shipment.ShipmentRateQuotes().ToArray();

            Assert.NotNull(quotes);
            Assert.IsTrue(quotes.Any(), "The collection of quotes was empty");

            checkoutManager.Shipping.SaveShipmentRateQuote(quotes.First());

            //// Act
            checkoutManager.Context.Settings.InvoiceNumberPrefix = "rss";
            var invoice = checkoutManager.Payment.PrepareInvoice();

            //// Assert
            Assert.NotNull(invoice);
            Assert.IsTrue(invoice.PrefixedInvoiceNumber().StartsWith("rss"));
        }
コード例 #3
0
        public void Can_Save_A_Shipment_Rate_Quote()
        {
            //// Arrange
            CurrentCustomer.Basket().AddItem(_product1, 10);
            this.CurrentCustomer.Basket().Save();
            var shipping = MockAddressMaker.GetAddress("US");

            var checkoutManager = this.CurrentCustomer.Basket().GetCheckoutManager();

            checkoutManager.Customer.SaveShipToAddress(shipping);

            //// Act
            var shipment = this.CurrentCustomer.Basket().PackageBasket(shipping).FirstOrDefault();

            Assert.NotNull(shipment);

            var quotes = shipment.ShipmentRateQuotes().ToArray();

            Assert.NotNull(quotes);
            Assert.IsTrue(quotes.Any(), "The collection of quotes was empty");

            checkoutManager.Shipping.SaveShipmentRateQuote(quotes.First());

            //// Assert
            var shippingLineItems =
                checkoutManager.Context.ItemCache.Items.Where(x => x.LineItemType == LineItemType.Shipping);

            Assert.IsTrue(shippingLineItems.Any());
        }
コード例 #4
0
        public void Can_Add_Custom_Discount_ToBasket_And_Transfer_It_To_CheckoutManager()
        {
            //// Arrange
            var basket = CurrentCustomer.Basket();

            var discount = new ItemCacheLineItem(LineItemType.Discount, "Test discount", "test", 1, 2, new ExtendedDataCollection());

            basket.AddItem(_product1, 10);
            basket.AddItem(_product2, 5);
            basket.AddItem(_product3, 1);

            var preDiscountTotal = basket.TotalBasketPrice;

            basket.AddItem(discount);

            var postDiscountTotal = basket.TotalBasketPrice;

            Assert.AreEqual(postDiscountTotal, preDiscountTotal - 2, "Discount failed to calculate correctly");

            var total = CurrentCustomer.Basket().TotalBasketPrice;

            this.CurrentCustomer.Basket().Save();
            Assert.AreEqual(4, CurrentCustomer.Basket().Items.Count());
            //

            var shipping = MockAddressMaker.GetAddress("US");
            var billing  = MockAddressMaker.GetAddress("US");

            var checkoutManager = this.CurrentCustomer.Basket().GetCheckoutManager();

            checkoutManager.Customer.SaveShipToAddress(shipping);
            checkoutManager.Customer.SaveBillToAddress(billing);

            var shipment = this.CurrentCustomer.Basket().PackageBasket(shipping).FirstOrDefault();
            var quotes   = shipment.ShipmentRateQuotes().ToArray();

            Assert.NotNull(quotes);
            Assert.IsTrue(quotes.Any(), "The collection of quotes was empty");

            checkoutManager.Shipping.SaveShipmentRateQuote(quotes.First());

            //// Act
            checkoutManager.Context.Settings.InvoiceNumberPrefix = "rss";
            var invoice = checkoutManager.Payment.PrepareInvoice();

            //// Assert
            Assert.NotNull(invoice);
            Assert.IsTrue(invoice.PrefixedInvoiceNumber().StartsWith("rss"));
        }
コード例 #5
0
        public void Can_Show_Adding_An_Additional_Item_To_Basket_Triggers_IsNewVersion()
        {
            this.WriteBasketInfoToConsole();

            //// Arrange
            CurrentCustomer.Basket().AddItem(_product1, 10);
            this.CurrentCustomer.Basket().Save();

            //// Act/Assert
            Assert.IsTrue(this.CurrentCustomer.Basket().GetCheckoutManager().Context.IsNewVersion, "Initialized as new version");
            Assert.IsFalse(this.CurrentCustomer.Basket().GetCheckoutManager().Context.IsNewVersion, "Second call should not be a new version");
            CurrentCustomer.Basket().AddItem(_product2, 5);
            this.CurrentCustomer.Basket().Save();
            Assert.IsTrue(this.CurrentCustomer.Basket().GetCheckoutManager().Context.IsNewVersion, "Basket version changed so new version should be true");
        }
コード例 #6
0
        public void Can_Create_A_CheckoutContext()
        {
            this.WriteBasketInfoToConsole();

            //// Arrange
            CurrentCustomer.Basket().AddItem(_product1, 10);
            this.WriteBasketInfoToConsole();

            //// Act
            var context = this.CurrentCustomer.Basket().CreateCheckoutContext(MerchelloContext.Current, new CheckoutContextSettings());

            //// Assert
            Assert.NotNull(context);
            Assert.NotNull(context.Services);
            Assert.NotNull(context.Gateways);
            Assert.IsTrue(context.Settings.ApplyTaxesToInvoice);
            Assert.AreEqual(1, context.ItemCache.Items.Count);
        }
コード例 #7
0
        public void Can_Show_Customer_Addresses_Are_Cleared_After_VersionReset()
        {
            //// Arrange
            var shipping = MockAddressMaker.GetAddress();
            var billing  = MockAddressMaker.GetAddress();

            var checkoutManager = this.CurrentCustomer.Basket().GetCheckoutManager();

            checkoutManager.Customer.SaveShipToAddress(shipping);
            checkoutManager.Customer.SaveBillToAddress(billing);

            //// Act
            CurrentCustomer.Basket().AddItem(_product1, 10);
            this.CurrentCustomer.Basket().Save();

            Assert.IsNull(this.CurrentCustomer.Basket().GetCheckoutManager().Customer.GetShipToAddress());
            Assert.IsNull(this.CurrentCustomer.Basket().GetCheckoutManager().Customer.GetBillToAddress());
        }
コード例 #8
0
        public void Can_Get_CustomerCheckoutManager()
        {
            this.WriteBasketInfoToConsole();

            //// Arrange
            CurrentCustomer.Basket().AddItem(_product1, 10);
            CurrentCustomer.Basket().AddItem(_product2, 5);
            CurrentCustomer.Basket().AddItem(_product2, 1);
            this.CurrentCustomer.Basket().Save();
            this.WriteBasketInfoToConsole();

            //// Act
            var checkoutManager = this.CurrentCustomer.Basket().GetCheckoutManager();

            //// Assert
            Assert.NotNull(checkoutManager);
            Assert.NotNull(checkoutManager.Customer, "Customer manager was null");
            Assert.NotNull(checkoutManager.Extended, "Extended manager was null");
            Assert.NotNull(checkoutManager.Offer, "Offer manager was null");
            Assert.NotNull(checkoutManager.Payment, "Payment manager was null");
            Assert.NotNull(checkoutManager.Shipping, "Shipping manager was null");
        }
コード例 #9
0
        public void Can_Show_Customer_Addresses_Are_Not_Cleared_After_VersionReset_WithCustomSettings()
        {
            //// Arrange
            var shipping = MockAddressMaker.GetAddress();
            var billing  = MockAddressMaker.GetAddress();
            var settings = new CheckoutContextSettings()
            {
                ResetCustomerManagerDataOnVersionChange = false
            };

            var checkoutManager = this.CurrentCustomer.Basket().GetCheckoutManager();

            checkoutManager.Customer.SaveShipToAddress(shipping);
            checkoutManager.Customer.SaveBillToAddress(billing);

            //// Act
            CurrentCustomer.Basket().AddItem(_product1, 10);
            this.CurrentCustomer.Basket().Save();

            Assert.NotNull(this.CurrentCustomer.Basket().GetCheckoutManager(settings).Customer.GetShipToAddress());
            Assert.NotNull(this.CurrentCustomer.Basket().GetCheckoutManager(settings).Customer.GetBillToAddress());
        }
コード例 #10
0
        public void Can_Save_And_Get_Customer_Addresses()
        {
            this.WriteBasketInfoToConsole();

            //// Arrange
            CurrentCustomer.Basket().AddItem(_product1, 10);
            this.CurrentCustomer.Basket().Save();
            var shipping = MockAddressMaker.GetAddress();
            var billing  = MockAddressMaker.GetAddress();

            var checkoutManager = this.CurrentCustomer.Basket().GetCheckoutManager();

            //// Act
            checkoutManager.Customer.SaveShipToAddress(shipping);
            checkoutManager.Customer.SaveBillToAddress(billing);
            var savedShipping = checkoutManager.Customer.GetShipToAddress();
            var savedBilling  = checkoutManager.Customer.GetBillToAddress();

            //// Assert
            Assert.NotNull(savedShipping);
            Assert.NotNull(savedBilling);
            Assert.AreEqual(savedShipping.Address1, shipping.Address1);
            Assert.AreEqual(savedBilling.Address1, billing.Address1);
        }
コード例 #11
0
        public void Can_Complete_Simple_Checkout_Scenario()
        {
            // The basket is empty
            WriteBasketInfoToConsole();

            #region Customer Does Basket Operations

            // -------------------------
            // Add a couple of products
            // -------------------------
            Console.WriteLine("Adding 10 'Product1' to the Basket");
            CurrentCustomer.Basket().AddItem(_product1, 10);

            Console.WriteLine("Adding 2 'Product2' to the Basket");
            CurrentCustomer.Basket().AddItem(_product2, 2);
            CurrentCustomer.Basket().Save();

            WriteBasketInfoToConsole();
            Assert.AreEqual(12, CurrentCustomer.Basket().TotalQuantityCount);
            Assert.AreEqual(14, CurrentCustomer.Basket().TotalBasketPrice);
            Assert.AreEqual(2, CurrentCustomer.Basket().TotalItemCount);

            // -------------------------
            // Add another product2
            // -------------------------
            Console.WriteLine("Adding another 'Product2' to the Basket");
            CurrentCustomer.Basket().AddItem(_product2);
            CurrentCustomer.Basket().Save();

            WriteBasketInfoToConsole();
            Assert.AreEqual(13, CurrentCustomer.Basket().TotalQuantityCount);
            Assert.AreEqual(16, CurrentCustomer.Basket().TotalBasketPrice);
            Assert.AreEqual(2, CurrentCustomer.Basket().TotalItemCount);

            // -------------------------
            // Add products - product3 and product4
            // -------------------------
            Console.WriteLine("Adding 2 'Product4' to the Basket");
            CurrentCustomer.Basket().AddItem(_product4, 2);

            WriteBasketInfoToConsole();
            Assert.AreEqual(15, CurrentCustomer.Basket().TotalQuantityCount);
            Assert.AreEqual(24, CurrentCustomer.Basket().TotalBasketPrice);
            Assert.AreEqual(3, CurrentCustomer.Basket().TotalItemCount);

            Console.WriteLine("Adding 1 'Product3' to the Basket");
            CurrentCustomer.Basket().AddItem(_product3, 1);
            CurrentCustomer.Basket().Save();

            WriteBasketInfoToConsole();
            Assert.AreEqual(16, CurrentCustomer.Basket().TotalQuantityCount);
            Assert.AreEqual(27, CurrentCustomer.Basket().TotalBasketPrice);
            Assert.AreEqual(4, CurrentCustomer.Basket().TotalItemCount);

            // -------------------------
            // Update Product4's quantity to 1
            // -------------------------
            CurrentCustomer.Basket().Items.First(x => x.Sku == _product4.Sku).Quantity = 1;
            CurrentCustomer.Basket().Save();

            WriteBasketInfoToConsole();
            Assert.AreEqual(15, CurrentCustomer.Basket().TotalQuantityCount);
            Assert.AreEqual(23, CurrentCustomer.Basket().TotalBasketPrice);
            Assert.AreEqual(4, CurrentCustomer.Basket().TotalItemCount);

            // -------------------------
            // Remove Product3 from the basket
            // -------------------------
            CurrentCustomer.Basket().RemoveItem(_product3.Sku);
            CurrentCustomer.Basket().Save();

            WriteBasketInfoToConsole();
            Assert.AreEqual(14, CurrentCustomer.Basket().TotalQuantityCount);
            Assert.AreEqual(20, CurrentCustomer.Basket().TotalBasketPrice);
            Assert.AreEqual(3, CurrentCustomer.Basket().TotalItemCount);


            #endregion


            #region CheckOut

            // ------------- Customer Shipping Address Entry -------------------------

            // Customer enters the destination shipping address
            var destination = new Address()
            {
                Name        = "Mindfly Web Design Studio",
                Address1    = "115 W. Magnolia St.",
                Address2    = "Suite 504",
                Locality    = "Bellingham",
                Region      = "WA",
                PostalCode  = "98225",
                CountryCode = "US"
            };

            // 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();

            Assert.IsTrue(shipments.Any());
            Assert.AreEqual(1, shipments.Count());

            var shipment = shipments.First();

            // Get a shipment rate quote
            //
            // This should return a collection containing 2 shipment rate quotes (for US)
            //
            var shipRateQuotes = shipment.ShipmentRateQuotes().ToArray();

            foreach (var srq in shipRateQuotes)
            {
                WriteShipRateQuote(srq);
            }

            // Customer chooses the cheapest shipping rate
            var approvedShipRateQuote = shipRateQuotes.FirstOrDefault();

            // start the Checkout process
            Assert.AreEqual(CurrentCustomer.Basket().TotalItemCount, CurrentCustomer.Basket().SalePreparation().ItemCache.Items.Count);

            CurrentCustomer.Basket().SalePreparation().SaveShipmentRateQuote(approvedShipRateQuote);

            // Customer changes their mind and adds Product 5 to the basket
            CurrentCustomer.Basket().AddItem(_product5);
            CurrentCustomer.Basket().Save();

            WriteBasketInfoToConsole();
            Assert.AreEqual(15, CurrentCustomer.Basket().TotalQuantityCount);
            Assert.AreEqual(25, CurrentCustomer.Basket().TotalBasketPrice);
            Assert.AreEqual(4, CurrentCustomer.Basket().TotalItemCount);

            // This should have cleared the CheckoutPreparation and reconstructed so that it matches the basket again
            Assert.AreEqual(CurrentCustomer.Basket().TotalItemCount, CurrentCustomer.Basket().SalePreparation().ItemCache.Items.Count(x => x.LineItemType == LineItemType.Product));
            Console.WriteLine("OrderPrepartion was cleared!");

            // Because the customer went back and added another item the checkout workflow needs to
            // be restarted

            // User is finally finished and going to checkout
            #region Final Checkout Prepartion

            #region Shipping information

            // Save the billing information (again - the same as shipping information)
            CurrentCustomer.Basket().SalePreparation().SaveBillToAddress(destination);

            shipments = CurrentCustomer.Basket().PackageBasket(destination).ToArray();
            Assert.IsTrue(shipments.Any());

            shipment = shipments.First();

            // shipment should have all four items packaged in it since they all were marked shippable
            Assert.AreEqual(CurrentCustomer.Basket().TotalItemCount, shipment.Items.Count, "Shipment did not contain all of the items");

            var shipmentRateQuotes = shipment.ShipmentRateQuotes().ToArray();
            Assert.AreEqual(2, shipmentRateQuotes.Count());


            // customer picks faster delivery so picks the more expensive rate from a drop down
            var dropDownListValue = shipmentRateQuotes.Last().ShipMethod.Key.ToString();

            var approvedShipmentRateQuote = shipment.ShipmentRateQuoteByShipMethod(dropDownListValue);

            // The shipment in the rate quote should have all four items packaged in it since they all were marked shippable
            Assert.AreEqual(CurrentCustomer.Basket().Items.Count, approvedShipmentRateQuote.Shipment.Items.Count);

            Assert.NotNull(approvedShipRateQuote);
            WriteShipRateQuote(approvedShipmentRateQuote);

            // save the rate quote
            CurrentCustomer.Basket().SalePreparation().SaveShipmentRateQuote(approvedShipmentRateQuote);


            #endregion // end shipping info round 2

            // generate an invoice to preview
            var isReadytoInvoice = CurrentCustomer.Basket().SalePreparation().IsReadyToInvoice();

            Assert.IsTrue(isReadytoInvoice);

            var invoice = CurrentCustomer.Basket().SalePreparation().PrepareInvoice();
            WriteInvoiceInfoToConsole(invoice);

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

            var paymentResult = CurrentCustomer.Basket().SalePreparation().AuthorizePayment(paymentMethods.FirstOrDefault());

            Assert.IsTrue(paymentResult.Payment.Success);
            Assert.IsTrue(CurrentCustomer.Basket().IsEmpty);

            #endregion // completed checkout preparation

            // capture the payment
            invoice.CapturePayment(paymentResult.Payment.Result, paymentMethods.FirstOrDefault(), invoice.Total);

            Assert.AreEqual(Constants.DefaultKeys.InvoiceStatus.Paid, invoice.InvoiceStatusKey);

            if (paymentResult.ApproveOrderCreation)
            {
                MerchelloContext.Current.Services.OrderService.Save(invoice.PrepareOrder());
            }


            #endregion
        }
コード例 #12
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);
            }
        }