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"));
        }
        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());
        }
        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"));
        }
        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());
        }
        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());
        }
        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);
        }