コード例 #1
0
        public void GetTollFee_Handle_Specified_Day()
        {
            var expectedTollFee = 10;
            var vehicle         = new Mock <IVehicle>();
            var date            = new DateTime(2018, 12, 22);

            var rule = new WeekDaysRule(expectedTollFee, new[] { date.DayOfWeek });

            var actualTollFee = rule.GetTollFee(vehicle.Object, new DateTime(2018, 12, 22));

            Assert.Equal(expectedTollFee, actualTollFee, 0);
        }
コード例 #2
0
        private static IRule CreateRule()
        {
            var vehicleEqualityComparer = new VehicleEqualityComparer();

            var rootRule = new WeekDaysRule(0.0, new[] { DayOfWeek.Saturday, DayOfWeek.Sunday });

            rootRule
            .AddRule(new FixedRule(0.0, new[] {
                _vehicles[VehicleType.Motorbike],
                _vehicles[VehicleType.Tractor],
                _vehicles[VehicleType.Emergency],
                _vehicles[VehicleType.Diplomat],
                _vehicles[VehicleType.Foreign],
                _vehicles[VehicleType.Military],
            }, vehicleEqualityComparer))
            .AddRule(new DaysRule(0.0, new[] {
                new DateTime(2013, 1, 1),
                new DateTime(2013, 3, 28),
                new DateTime(2013, 3, 29),
                new DateTime(2013, 4, 1),
                new DateTime(2013, 4, 30),
                new DateTime(2013, 5, 1),
                new DateTime(2013, 5, 8),
                new DateTime(2013, 5, 9),
                new DateTime(2013, 6, 5),
                new DateTime(2013, 6, 6),
                new DateTime(2013, 6, 21),
                new DateTime(2013, 11, 1),
                new DateTime(2013, 12, 24),
                new DateTime(2013, 12, 25),
                new DateTime(2013, 12, 26),
                new DateTime(2013, 12, 31),
            }))
            .AddRule(new MonthRule(0.0, 7))
            .AddRule(new DayRule()
                     .AddTime(new TimeSpan(6, 0, 0), 9)
                     .AddTime(new TimeSpan(6, 30, 0), 16)
                     .AddTime(new TimeSpan(7, 0, 0), 22)
                     .AddTime(new TimeSpan(8, 0, 0), 16)
                     .AddTime(new TimeSpan(8, 30, 0), 9)
                     .AddTime(new TimeSpan(15, 0, 0), 16)
                     .AddTime(new TimeSpan(15, 30, 0), 22)
                     .AddTime(new TimeSpan(17, 0, 0), 16)
                     .AddTime(new TimeSpan(18, 0, 0), 9)
                     .AddTime(new TimeSpan(18, 30, 0), 0)
                     .EndConfiguration());

            return(rootRule);
        }
コード例 #3
0
        public void GetTollFee_Do_Not_Handle_Unspecified_Day()
        {
            var expectedNextTollFee = 20;
            var handledDayOfWeek    = new DateTime(2018, 12, 20).DayOfWeek;
            var chekedDate          = new DateTime(2018, 12, 19);

            var vehicle  = new Mock <IVehicle>();
            var nextRule = new Mock <IRule>();

            nextRule.Setup(r => r.GetTollFee(vehicle.Object, chekedDate))
            .Returns(expectedNextTollFee);

            var rule = new WeekDaysRule(0, new[] { handledDayOfWeek });

            rule.SetNextRule(nextRule.Object);

            var actualTollFee = rule.GetTollFee(vehicle.Object, chekedDate);

            Assert.Equal(expectedNextTollFee, actualTollFee, 0);
        }