Ejemplo n.º 1
0
        public void upperbound_rule_should_pass_for_30_percent_or_less()
        {
            UpperBoundRule rule = new UpperBoundRule();
            RedPencilItem item = new RedPencilItem(100.00m);

            Assert.IsTrue(rule.Process(item, 70.00m ));
        }
Ejemplo n.º 2
0
        private RedPencilItem endPromotion(RedPencilItem item)
        {
            item.PromotionEndDate = DateTime.Now;
            item.MarkedDownPrice = null;

            return item;
        }
Ejemplo n.º 3
0
        public bool Process(RedPencilItem item, decimal newPrice)
        {
            if (!item.PromotionEndDate.HasValue)
                return true;

            return DateTime.Now.Subtract(item.PromotionEndDate.Value).Days >= 30;
        }
Ejemplo n.º 4
0
        public void stable_price_rule_false_for_end_date_younger_than_30_days()
        {
            RedPencilItem item = new RedPencilItem(100.00m);
            item.PromotionEndDate = DateTime.Now.AddDays(-15);

            Assert.IsFalse(new StablePriceRule().Process(item, 100.0m));
        }
Ejemplo n.º 5
0
 public void price_change_should_trigger_promotion()
 {
     RedPencilItem item = new RedPencilItem(100.00m);
     item = _engine.ChangePrice(item, 90.00m);
     Assert.IsTrue(item.PromotionStartDate.HasValue);
     Assert.IsTrue(item.PromotionEndDate.HasValue);
 }
Ejemplo n.º 6
0
        private RedPencilItem startPromotion(RedPencilItem item, decimal newPrice)
        {
            item.MarkedDownPrice = newPrice;
            item.PromotionStartDate = DateTime.Now;
            item.PromotionEndDate = item.PromotionStartDate.Value.AddDays(30);

            return item;
        }
Ejemplo n.º 7
0
        public bool Process(RedPencilItem item, decimal newPrice)
        {
            if (item.MarkedDownPrice.HasValue)
            {
                return newPrice > item.MarkedDownPrice.Value;
            }

            return newPrice > item.OriginalPrice;
        }
Ejemplo n.º 8
0
        public void invalid_price_reduction_during_promotion_ends_promotion()
        {
            RedPencilItem item = new RedPencilItem(100.00m);
            item = _engine.ChangePrice(item, 91.00m);

            item = _engine.ChangePrice(item, 69.99m);

            Assert.IsFalse(item.MarkedDownPrice.HasValue);
            Assert.IsTrue(item.PromotionEndDate.HasValue);
        }
Ejemplo n.º 9
0
        public void price_change_must_be_equal_to_or_less_than_thirty_percent_of_original()
        {
            RedPencilItem item = new RedPencilItem(100.00m);
            item = _engine.ChangePrice(item, 70.00m);
            Assert.IsTrue(item.MarkedDownPrice.HasValue);

            RedPencilItem item2 = new RedPencilItem(100.00m);
            item2 = _engine.ChangePrice(item2, 69.99m);
            Assert.IsFalse(item2.MarkedDownPrice.HasValue);
        }
Ejemplo n.º 10
0
        public void price_increase_during_promotion_ends_promotion()
        {
            RedPencilItem item = new RedPencilItem(100.00m);
            item = _engine.ChangePrice(item, 89.00m);

            Assert.IsTrue(item.MarkedDownPrice.HasValue);

            item = _engine.ChangePrice(item, 91.00m);

            Assert.IsFalse(item.MarkedDownPrice.HasValue);
        }
Ejemplo n.º 11
0
        public void price_change_must_be_five_percent_or_greater_of_original()
        {
            RedPencilItem item  = new RedPencilItem(100.00m);
            item = _engine.ChangePrice(item, 96.00m);
            Assert.IsFalse(item.MarkedDownPrice.HasValue);

            RedPencilItem item2 = new RedPencilItem(100.00m);
            item2 = _engine.ChangePrice(item2, 95.01m);
            Assert.IsFalse(item2.MarkedDownPrice.HasValue);

            RedPencilItem item3 = new RedPencilItem(100.00m);
            item3 = _engine.ChangePrice(item3, 94.99m);
            Assert.IsTrue(item3.MarkedDownPrice.HasValue);
        }
Ejemplo n.º 12
0
        public RedPencilItem ChangePrice(RedPencilItem item, decimal newPrice)
        {
            if (_startRules.All(x => x.Process(item, newPrice)))
            {
                return startPromotion(item, newPrice);
            }

            if (_endRules.All(x => x.Process(item, newPrice)))
            {
                return endPromotion(item);
            }

            if (_endRules2.Any(x => !x.Process(item, newPrice)))
            {
                return endPromotion(item);
            }

            if (_continueRules.All(x => x.Process(item, newPrice)))
            {
                return continuePromotion(item, newPrice);
            }

            return item;
        }
Ejemplo n.º 13
0
        public void stable_price_rule_is_true_for_null_end_date()
        {
            RedPencilItem item = new RedPencilItem(100.00m);

            Assert.IsTrue(new StablePriceRule().Process(item, 100.00m));
        }
Ejemplo n.º 14
0
        public void price_increase_rule_should_return_true_for_increase()
        {
            RedPencilItem item = new RedPencilItem(100.00m);

            Assert.IsTrue(new PriceIncreaseRule().Process(item, 101.00m));
        }
Ejemplo n.º 15
0
        public void lowerbound_rule_should_pass_for_5_percent_or_greater()
        {
            RedPencilItem item = new RedPencilItem(100.00m);

            Assert.IsTrue(new LowerBoundRule().Process(item, 95.00m));
        }
Ejemplo n.º 16
0
        public void lowerbound_rule_shoud_fail_for_less_than_5_percent()
        {
            RedPencilItem item = new RedPencilItem(100.00m);

            Assert.IsFalse(new LowerBoundRule().Process(item, 96.66m));
        }
Ejemplo n.º 17
0
 public bool Process(RedPencilItem item, decimal newPrice)
 {
     return honorsUpperBound(item.OriginalPrice, newPrice);
 }
Ejemplo n.º 18
0
        private RedPencilItem continuePromotion(RedPencilItem item, decimal newPrice)
        {
            item.MarkedDownPrice = newPrice;

            return item;
        }
Ejemplo n.º 19
0
        public void valid_price_reduction_during_promotion_does_not_extend_promotion()
        {
            RedPencilItem item = new RedPencilItem(100.00m);
            item = _engine.ChangePrice(item, 95.00m);
            DateTime origEndDate = item.PromotionEndDate.Value;

            item = _engine.ChangePrice(item, 90.00m);
            Assert.AreEqual(origEndDate, item.PromotionEndDate.Value);
        }
Ejemplo n.º 20
0
 public void promotion_start_and_end_date_should_be_30_days_apart()
 {
     RedPencilItem item = new RedPencilItem(100.00m);
     item = _engine.ChangePrice(item, 90.00m);
     TimeSpan dateDiff = item.PromotionEndDate.Value.Subtract(item.PromotionStartDate.Value);
     Assert.AreEqual(30, dateDiff.Days);
 }
Ejemplo n.º 21
0
 public void newly_created_item_has_nulled_markdown_price()
 {
     RedPencilItem item = new RedPencilItem(100.00m);
     Assert.IsFalse(item.MarkedDownPrice.HasValue);
 }
Ejemplo n.º 22
0
 public void can_change_price()
 {
     RedPencilItem item = new RedPencilItem(100.00m);
     item = _engine.ChangePrice(item, 90.00m);
     Assert.AreEqual(90.00m, item.MarkedDownPrice.Value);
 }
Ejemplo n.º 23
0
        public void uppoerbound_rule_should_fail_for_more_than_30_percent()
        {
            RedPencilItem item = new RedPencilItem(100.00m);

            Assert.IsFalse(new UpperBoundRule().Process(item, 69.99m));
        }
Ejemplo n.º 24
0
 public void can_create_entity_with_price()
 {
     RedPencilItem item = new RedPencilItem(100.00m);
     Assert.AreEqual(100.00m, item.OriginalPrice);
 }