示例#1
0
        public void CountIsTheNumberOfEntries()
        {
            var testContext = new TestContext();

            Sku sku1 = testContext.CreateNewSku("A", 100);
            Sku sku2 = testContext.CreateNewSku("B", 200);
            Sku sku3 = testContext.CreateNewSku("C", 300);

            ICart cart = testContext.CartFactory.Create();

            cart.Add(new SkuCartEntry()
            {
                Sku = sku1, Quantity = 1
            });
            cart.Add(new SkuCartEntry()
            {
                Sku = sku2, Quantity = 2
            });
            cart.Add(new SkuCartEntry()
            {
                Sku = sku3, Quantity = 3
            });

            Assert.NotEqual(cart.Quantity, cart.Count);
            Assert.Equal(3, cart.Count);
        }
示例#2
0
        public void MergeIsCommutative()
        {
            var testContext = new TestContext();

            Sku sku1 = testContext.CreateNewSku("A", 100);
            Sku sku2 = testContext.CreateNewSku("B", 200);
            Sku sku3 = testContext.CreateNewSku("C", 300);

            ICart cart1 = testContext.CartFactory.Create();

            cart1.Add(sku1);

            ICart cart2 = testContext.CartFactory.Create();

            cart2.Add(sku2);
            cart2.Add(sku3);

            ICart mergedCart1 = cart1.Merge(cart2);
            ICart mergedCart2 = cart2.Merge(cart1);

            Assert.Equal(mergedCart1.Quantity, mergedCart2.Quantity);
            Assert.Equal(1, mergedCart1.Count(entry => entry.Sku == sku1));
            Assert.Equal(1, mergedCart1.Count(entry => entry.Sku == sku2));
            Assert.Equal(1, mergedCart1.Count(entry => entry.Sku == sku3));
            Assert.Equal(1, mergedCart2.Count(entry => entry.Sku == sku1));
            Assert.Equal(1, mergedCart2.Count(entry => entry.Sku == sku2));
            Assert.Equal(1, mergedCart2.Count(entry => entry.Sku == sku3));
        }
示例#3
0
        public void QuantityIsTheSumOfAllEntriesQuantity()
        {
            var testContext = new TestContext();

            Sku sku1      = testContext.CreateNewSku("A", 100);
            Sku sku2      = testContext.CreateNewSku("B", 200);
            Sku sku3      = testContext.CreateNewSku("C", 300);
            int quantity1 = 1;
            int quantity2 = 2;
            int quantity3 = 3;

            ICart cart = testContext.CartFactory.Create();

            cart.Add(sku1);
            cart.Add(new SkuCartEntry()
            {
                Sku = sku2, Quantity = quantity2
            });
            cart.Add(new SkuCartEntry()
            {
                Sku = sku3, Quantity = quantity3
            });

            Assert.Equal(quantity1 + quantity2 + quantity3, cart.Quantity);
        }
示例#4
0
 public static int Add(CartInfo entity, int userId)
 {
     if (userId > 0)
     {
         return(dal.Add(entity));
     }
     else
     {
         return(CartHelper.AddToCart(entity));
     }
 }
示例#5
0
        public void QuantityWithEntriesHavingNonUnitQuantities()
        {
            var testContext = new TestContext();

            ICart cart = testContext.CartFactory.Create();

            cart.Add(new SkuCartEntry()
            {
                Sku      = testContext.CreateNewSku("A", 100),
                Quantity = 2
            });
            cart.Add(testContext.CreateNewSku("B", 200));

            Assert.Equal(3, cart.Quantity);
        }
示例#6
0
        public void TotalIsTheSumOfAllEntriesPrice()
        {
            var testContext = new TestContext();

            Sku sku1 = testContext.CreateNewSku("A", 100);
            Sku sku2 = testContext.CreateNewSku("B", 200);
            Sku sku3 = testContext.CreateNewSku("C", 300);

            ICart cart = testContext.CartFactory.Create();

            cart.Add(sku1);
            cart.Add(sku2);
            cart.Add(sku3);

            Assert.Equal(testContext.PriceList[sku1] + testContext.PriceList[sku2] + testContext.PriceList[sku3], cart.Total);
        }
示例#7
0
        public void WhenAddingASkuWithZeroUnitPriceThenTotalDoesNotChange()
        {
            var testContext = new TestContext();

            ICart cart = testContext.CartFactory.Create();

            cart.Add(testContext.CreateNewSku("A", 100));
            var total1 = cart.Total;

            Assert.NotEqual(0, total1);

            cart.Add(testContext.CreateNewSku("Z", 0));
            var total2 = cart.Total;

            Assert.Equal(total1, total2);
        }
示例#8
0
        public void ToStringReturnsANonEmptyStringWhenCartIsNotEmpty()
        {
            var testContext = new TestContext();

            ICart cart = testContext.CartFactory.Create();

            cart.Add(testContext.CreateNewSku("A", 100));

            Assert.False(string.IsNullOrEmpty(cart.ToString()));
        }
示例#9
0
        public void WhenAddingASkuThenQuantityIsUnit()
        {
            var testContext = new TestContext();

            ICart cart = testContext.CartFactory.Create();

            cart.Add(testContext.CreateNewSku("A", 100));

            Assert.Equal(1, cart.First().Quantity);
        }
示例#10
0
        public void WhenSkuIsNotInPricelistThenAddRaisesException()
        {
            var testContext = new TestContext();

            ICart cart = testContext.CartFactory.Create();

            decimal registeredSkuPrice = 100;
            var     registeredSku      = testContext.CreateNewSku("A", registeredSkuPrice);

            cart.Add(registeredSku);
            Assert.Equal(registeredSkuPrice, cart.Total);

            var unregisteredSku = new Sku("U");

            Assert.Throws <StandardCart.SkuNotFoundInPriceListException>(() =>
            {
                cart.Add(unregisteredSku); // Adding SKU but no price registered in pricelist
            });
        }
示例#11
0
        public void WhenAddingASkuThenPriceIsSameAsItsUnitPrice()
        {
            var testContext = new TestContext();

            ICart cart = testContext.CartFactory.Create();
            Sku   sku  = testContext.CreateNewSku("A", 100);

            cart.Add(sku);

            Assert.Equal(testContext.PriceList[sku], cart.First().Price);
        }
示例#12
0
        public void WhenAddingItemsThenTotalChanges()
        {
            var testContext = new TestContext();

            ICart cart = testContext.CartFactory.Create();

            Assert.Equal(0, cart.Total);

            cart.Add(testContext.CreateNewSku("A", 100));
            Assert.NotEqual(0, cart.Total);
        }
示例#13
0
        public void WhenAddingASkuWithQuantityThenPriceIsUnitByQuantity()
        {
            var testContext = new TestContext();

            ICart cart     = testContext.CartFactory.Create();
            Sku   sku      = testContext.CreateNewSku("A", 100);
            int   quantity = 3;

            cart.Add(sku, quantity);

            Assert.Equal(testContext.PriceList[sku] * quantity, cart.First().Price);
        }
示例#14
0
        public void WhenMergingWithAnEmptyCartThenResultingCartHasSameTotalAsOriginal()
        {
            var testContext = new TestContext();

            ICart cart = testContext.CartFactory.Create();

            cart.Add(testContext.CreateNewSku("A", 100));

            ICart mergedCart = cart.Merge(testContext.CartFactory.Create());

            Assert.Equal(cart.Quantity, mergedCart.Quantity);
        }
示例#15
0
        static void Run(ICart cart, IDeliveryCostCalculator deliveryCostCalculator)
        {
            ICategory categoryConsumerElectronics = new Category("Consumer Electronics");
            IProduct  productAppleWatch           = new Product(categoryConsumerElectronics, "Apple Watch", 2000.0);
            IProduct  productAppleMacbookPro      = new Product(categoryConsumerElectronics, "Apple Macbook Pro", 10000.0);

            ICategory categoryToysAndGames = new Category("Toys & Games");
            IProduct  productLego          = new Product(categoryToysAndGames, "Lego Classic Pack", 100.0);

            cart.Add(productAppleWatch, 2);
            cart.Add(productAppleMacbookPro, 1);
            cart.Add(productLego, 10);

            ICollection <ICampaign> campaigns = new Collection <ICampaign>();
            ICollection <ICoupon>   coupons   = new Collection <ICoupon>();

            IRateCampaign   inapplicableRateCampaign = new RateCampaign(categoryToysAndGames, "80% discount on Toys & Games category", .5, true, true, 50000.0, 20);
            IAmountCampaign lowAmountCampaign        = new AmountCampaign(categoryConsumerElectronics, "100 TL discount on Toys & Games category", 100, false, false, 0.0, 0);
            IAmountCampaign bestAmountCampaign       = new AmountCampaign(categoryConsumerElectronics, "1400 TL discount on Toys & Games category", 1400, false, true, 0.0, 3);
            IAmountCoupon   inapplicableAmountCoupon = new AmountCoupon(5000, "5000 TL discount coupon", true, true, 50000, 50);
            IRateCoupon     lowRateCoupon            = new RateCoupon(.1, "10% discount coupon", false, false, 0.0, 0);
            IRateCoupon     bestRateCoupon           = new RateCoupon(.5, "50% discount coupon", true, true, 10000, 13);

            campaigns.Add(inapplicableRateCampaign);
            campaigns.Add(lowAmountCampaign);
            campaigns.Add(bestAmountCampaign);
            coupons.Add(inapplicableAmountCoupon);
            coupons.Add(lowRateCoupon);
            coupons.Add(bestRateCoupon);

            cart.ApplyDiscounts(campaigns, coupons);

            cart.DeliveryCost = deliveryCostCalculator.Calculate(cart);

            var response = cart.Print();

            Console.Write(response);
        }
示例#16
0
 private void button_add_Click(object sender, EventArgs e)
 {
     if (textBox_costcentre.Text == string.Empty)
     {
         label_costcentre.ForeColor = System.Drawing.Color.Red;
         return;
     }
     P.Annotation = richTextBox_notice.Text;
     P.Ammount    = trackBar_ammount.Value;
     P.Costcentre = textBox_costcentre.Text;
     P.Name       = _productname;
     if (change)
     {
         _w.Remove(old);
     }
     _w.Add(P);
     Close();
 }
示例#17
0
 public void AddToCart(IProduct p)
 {
     cart.Add(p);
 }
示例#18
0
 public void AddComment(Cart c)
 {
     cartRepository.Add(c);
 }