示例#1
0
        public double Calculate()

        {
            double totalCost = 0;

            double adjustedValue = 0;

            foreach (Item item in Items)

            {
                totalCost += item.Accept(promotion);
            }

            if (promotion.GetType().Equals(typeof(Promotion1)))

            {
                int noOfCItems = 0;

                double costOfCItem = 0.0;

                int noOfDItems = 0;

                double costOfDItem = 0.0;

                if (Items.OfType <ItemC>().FirstOrDefault() != null)

                {
                    noOfCItems = Items.OfType <ItemC>().FirstOrDefault().NoOfItems;

                    costOfCItem = Items.OfType <ItemC>().FirstOrDefault().Cost;
                }

                if (Items.OfType <ItemD>().FirstOrDefault() != null)

                {
                    noOfDItems = Items.OfType <ItemD>().FirstOrDefault().NoOfItems;

                    costOfDItem = Items.OfType <ItemD>().FirstOrDefault().Cost;
                }

                if (noOfCItems > 0 && noOfDItems > 0)

                {
                    if (noOfCItems == noOfDItems)
                    {
                        adjustedValue = noOfCItems * 5;
                    }

                    if (noOfCItems != noOfDItems)
                    {
                        adjustedValue = (noOfCItems > noOfDItems) ? ((noOfCItems - noOfDItems) * costOfCItem) : ((noOfDItems - noOfCItems) * costOfDItem);
                    }
                }
            }

            return(totalCost - adjustedValue);
        }
示例#2
0
        public void TestPromotionStarCard()
        {
            // arrange
            string coupon     = "STARCARD";
            Type   expectType = typeof(PromotionStarCard);

            // act
            PromotionFactory promoFactory = new PromotionFactory();
            IPromotion       promo        = promoFactory.GetPromotionByCode(coupon);
            Type             actualType   = promo.GetType();

            // assert
            Assert.AreEqual(expectType, actualType);
        }
示例#3
0
        public void TestPromotionDefault()
        {
            // arrange
            string coupon     = "NONE";
            Type   expectType = typeof(DefaultPromotion);

            // act
            PromotionFactory promoFactory = new PromotionFactory();
            IPromotion       promo        = promoFactory.GetPromotionByCode(coupon);
            Type             actualType   = promo.GetType();

            // assert
            Assert.AreEqual(expectType, actualType);
        }
示例#4
0
        public void TestDiscount10Percent()
        {
            // arrange
            string coupon     = "DIS10";
            Type   expectType = typeof(PromotionDis10);

            // act
            PromotionFactory promoFactory = new PromotionFactory();
            IPromotion       promo        = promoFactory.GetPromotionByCode(coupon);
            Type             actualType   = promo.GetType();

            // assert
            Assert.AreEqual(expectType, actualType);
        }