예제 #1
0
        public int CalculatePrice(string message)
        {
            var msg = new MessageForProcessing()
            {
                Text         = message,
                CurrentPrice = 0,
                Weight       = CalculateWeight(message)
            };

            // Base Price
            foreach (var costRule in _basePriceRules)
            {
                if (costRule.AppliesTo(msg))
                {
                    _logger.Debug($"Applying Base Price Rule: {costRule.RuleName}");
                    msg.CurrentPrice = costRule.Apply(msg);
                }
            }

            // Extended Prices
            foreach (var ExtRule in _extendedPriceRules)
            {
                if (ExtRule.AppliesTo(msg))
                {
                    _logger.Debug($"Applying Extended Rule: {ExtRule.RuleName}");
                    msg.CurrentPrice = ExtRule.Apply(msg);
                }
            }

            return(msg.CurrentPrice);
        }
예제 #2
0
        public void _should_apply_base_price_of_4()
        {
            var msg = new MessageForProcessing()
            {
                Text = "123", CurrentPrice = 0, Weight = 0
            };

            Assert.AreEqual <int>(4, _rule.Apply(msg));
        }
예제 #3
0
        public void _should_not_accept_when_weight_greater_than_5()
        {
            var msg = new MessageForProcessing()
            {
                Text = "123", CurrentPrice = 0, Weight = 6
            };

            Assert.IsFalse(_rule.AppliesTo(msg));
        }
예제 #4
0
        public void _should_accept_when_weight_less_than_5()
        {
            var msg = new MessageForProcessing()
            {
                Text = "123", CurrentPrice = 0, Weight = 4
            };

            Assert.IsTrue(_rule.AppliesTo(msg));
        }
        public void Should_not_apply_when_doesnt_apply()
        {
            var invalidMsg = new MessageForProcessing()
            {
                CurrentPrice = 20, Text = "This is a message", Weight = 30
            };

            Assert.IsFalse(rule.AppliesTo(invalidMsg));
        }
        public void Should_Set_as_free_when_applies()
        {
            var validMsg = new MessageForProcessing()
            {
                CurrentPrice = 10, Text = "GodSaveTheQueen", Weight = 10
            };

            Assert.IsTrue(rule.AppliesTo(validMsg));
            Assert.IsTrue(0 == rule.Apply(validMsg));
        }
예제 #7
0
        public void SetUp()
        {
            basePriceRules = new List <IBasePriceRule>();
            extPriceRules  = new List <IExtendedPriceRule>();
            _logger        = new Mock <IAppLogger>().Object;

            message = new MessageForProcessing()
            {
                CurrentPrice = 0, Text = "Hello World", Weight = 0
            };
        }
 public int Apply(MessageForProcessing Message)
 {
     return(4);
 }
 public bool AppliesTo(MessageForProcessing Message)
 {
     return(Message.Weight < 5);
 }
예제 #10
0
 public int Apply(MessageForProcessing Message)
 {
     return(Message.CurrentPrice * 3);
 }
예제 #11
0
 public bool AppliesTo(MessageForProcessing Message)
 {
     return(Message.Text.Contains("!!!"));
 }
 public bool AppliesTo(MessageForProcessing Message)
 {
     return(Message.Text.Contains("GodSaveTheQueen"));
 }