Esempio n. 1
0
        public void MustRespectBookingTimeOverrideRule()
        {
            var @event = new Event {
                Id = 3
            };

            var bookings = new Mock <IBookingProvider>();
            var rules    = new Mock <IRuleProvider>();
            var times    = new BookingTimeOverrideTimeProvider(new List <BookingTimeOverrideRule> {
                new BookingTimeOverrideRule(
                    @event.Id.Value,
                    new List <TimeSpan>()
                {
                    new TimeSpan(09, 30, 00),
                    new TimeSpan(10, 45, 00)
                })
            });

            var date     = new DateTime(2017, 1, 1, 10, 0, 0);
            var sheduler = new Scheduler(bookings.Object, rules.Object, times);

            bookings.Setup(p => p.GetBookings(date, date)).Returns(new List <Booking> ());
            rules.Setup(r => r.GetRules()).Returns(new List <IRule>());

            var dates = sheduler.GetBookingDateRange(date, date, @event);

            Assert.AreEqual(new TimeSpan(09, 30, 00), dates.ElementAt(0).Date.TimeOfDay);
            Assert.AreEqual(new TimeSpan(10, 45, 00), dates.ElementAt(1).Date.TimeOfDay);
        }
        public static IList <BookingDate> CalculateBookingDates(DateTime date, int eventId)
        {
            Scheduler scheduler;

            var bookingTimeOverrideRules = Database.Instance.GetRules().OfType <BookingTimeOverrideRule>().Where(r => r.EventId == eventId);

            if (bookingTimeOverrideRules.Any())
            {
                var timeProvider = new BookingTimeOverrideTimeProvider(bookingTimeOverrideRules);
                scheduler = new Scheduler(Database.Instance, Database.Instance, timeProvider);
            }
            else
            {
                scheduler = Scheduler.CreateNew(Database.Instance);
            }

            var @event = Database.Instance.GetEventBy(eventId);
            var monday = DateTimeUtility.GetMondayOfWeekFor(date);
            var sunday = DateTimeUtility.GetSundayOfWeekFor(date);

            return(scheduler.GetBookingDateRange(monday, sunday, @event));
        }