Example #1
0
 public static void SetChain(this ParcelRuleCollection rules)
 {
     for (int i = 0; i < rules.ParcelRules.Count() - 1; i++)
     {
         rules.ParcelRules.ElementAt(i).SetNextRule(rules.ParcelRules.ElementAt(i + 1));
     }
 }
        public void ProcessRule_returns_correct_values(Parcel parcel, decimal cost)
        {
            //Given
            var rules = new ParcelRuleCollection
            {
                ParcelRules = new List <ParcelRule>
                {
                    new ParcelRule {
                        Rate = 0, WeightLimit = 50, VolumeLimit = 0
                    },
                    new ParcelRule {
                        Rate = 15, WeightLimit = 10, VolumeLimit = 0
                    },
                    new ParcelRule {
                        Rate = 0.05M, WeightLimit = 0, VolumeLimit = 1500
                    },
                    new ParcelRule {
                        Rate = 0.04M, WeightLimit = 0, VolumeLimit = 2500
                    },
                    new ParcelRule {
                        Rate = 0.03M, WeightLimit = 0, VolumeLimit = 0
                    },
                }
            };

            var ruleProcessor = new ParcelRuleProcessor(rules);
            var sut           = ruleProcessor.FirstRule;

            //When
            var actual = sut.ProcessRule(parcel);

            //Then
            Assert.IsType <ParcelCost>(actual);
            Assert.Equal(cost, actual.CostOfDelivery);
        }
        public void FirstRule_returns_correct_firstHandler(ParcelRuleCollection rules, int firstPriority)
        {
            //Given
            var sut = new ParcelRuleProcessor(rules);

            //When
            var actual = sut.FirstRule;

            //Then
            Assert.IsAssignableFrom <ParcelRuleBase>(actual);
            Assert.Equal(firstPriority, actual.Priority);
        }
Example #4
0
 public static void SortByPriority(this ParcelRuleCollection rules)
 {
     rules.ParcelRules = rules.ParcelRules.OrderBy(x => x.Priority);
 }