Ejemplo n.º 1
0
        public void EveryWorkdayExactTimeLocal()
        {
            var evs = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "26"
                    , text         = "New event"
                    , start_date   = DateTime.SpecifyKind(new DateTime(2011, 10, 01, 12, 0, 0), DateTimeKind.Local)
                    , end_date     = new DateTime(9999, 02, 01)
                    , event_length = 5700
                    , rec_type     = "week_1___1,2,3,4,5#no"
                    , event_pid    = null
                }
            };
            var helper = new RecurringEventsHelper();


            var items = helper.GetOccurrences(evs, new DateTime(2011, 09, 01), new DateTime(2011, 10, 28));

            Assert.AreEqual(
                items.Count,
                items.Where(i =>
                            i.start_date.Hour == 12 &&
                            i.end_date.Hour == 13).Count()
                );
        }
Ejemplo n.º 2
0
        public void EveryWorkday()
        {
            var evs = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "26"
                    , text         = "New event"
                    , start_date   = new DateTime(2011, 10, 01, 12, 0, 0)
                    , end_date     = new DateTime(9999, 02, 01)
                    , event_length = 5700
                    , rec_type     = "week_1___1,2,3,4,5#no"
                    , event_pid    = null
                }
            };
            var helper = new RecurringEventsHelper();


            var items = helper.GetOccurrences(evs, new DateTime(2011, 09, 01), new DateTime(2011, 10, 28));

            Assert.AreEqual(
                0,
                items.Where(i => i.start_date.DayOfWeek == DayOfWeek.Saturday || i.start_date.DayOfWeek == DayOfWeek.Sunday).Count()
                );
        }
Ejemplo n.º 3
0
        public void MonthlySeriesMonthEnd()
        {
            var evs = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "1"
                    , text         = "New event"
                    , start_date   = new DateTime(2022, 1, 31, 8, 0, 0)
                    , end_date     = new DateTime(2023, 1, 31, 8, 0, 0, 0)
                    , event_length = 12600
                    , rec_type     = "month_1___#no"// repeat 31st day every month
                    , event_pid    = null
                }
            };
            var helper = new RecurringEventsHelper {
                OverflowInstances = RecurringEventsHelper.OverflowInstancesRule.Skip
            };

            var items = helper.GetOccurrences(evs, new DateTime(2022, 1, 31), new DateTime(2024, 1, 1));

            // event repeats on 31st day of every month, month that have less then 31 day won't have instances of the series due to the `OverlowInstances` rule
            // only these months must have instances of the series: Jan, March, May, July, August, October, December
            Assert.AreEqual(7, items.Count);
            Assert.AreEqual(new DateTime(2022, 1, 31, 8, 0, 0), items[0].start_date);
            Assert.AreEqual(new DateTime(2022, 3, 31, 8, 0, 0), items[1].start_date);
            Assert.AreEqual(new DateTime(2022, 5, 31, 8, 0, 0), items[2].start_date);
            Assert.AreEqual(new DateTime(2022, 7, 31, 8, 0, 0), items[3].start_date);
            Assert.AreEqual(new DateTime(2022, 8, 31, 8, 0, 0), items[4].start_date);
            Assert.AreEqual(new DateTime(2022, 10, 31, 8, 0, 0), items[5].start_date);
            Assert.AreEqual(new DateTime(2022, 12, 31, 8, 0, 0), items[6].start_date);
        }
Ejemplo n.º 4
0
        public void DeletedEventGetCount()
        {
            var evs = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "27"
                    , text         = "New event"
                    , start_date   = new DateTime(2011, 09, 27, 3, 05, 0)
                    , end_date     = new DateTime(2011, 09, 30, 3, 05, 0)
                    , event_length = 10800
                    , rec_type     = "day_1___#3"
                    , event_pid    = null
                }
                , new SchedulerEvent()
                {
                    id             = "28"
                    , text         = "New event"
                    , start_date   = new DateTime(2011, 09, 28, 3, 05, 0)
                    , end_date     = new DateTime(2011, 09, 28, 6, 05, 0)
                    , event_length = 1317168300
                    , rec_type     = "none"
                    , event_pid    = "27"
                }
            };
            var helper = new RecurringEventsHelper();


            var items = helper.GetOccurrences(evs, new DateTime(2011, 09, 1), new DateTime(2011, 10, 1));

            Assert.AreEqual(
                2,
                items.Count);
        }
Ejemplo n.º 5
0
        public void EditedEventGetModified()
        {
            var evs = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "30"
                    , text         = "New event"
                    , start_date   = new DateTime(2011, 09, 27, 2, 00, 0)
                    , end_date     = new DateTime(2011, 09, 30, 2, 00, 0)
                    , event_length = 12300
                    , rec_type     = "day_1___#3"
                    , event_pid    = null
                }
                , new SchedulerEvent()
                {
                    id             = "31"
                    , text         = "New event"
                    , start_date   = new DateTime(2011, 09, 28, 6, 15, 0)
                    , end_date     = new DateTime(2011, 09, 28, 9, 40, 0)
                    , event_length = 1317164400
                    , rec_type     = ""
                    , event_pid    = "30"
                }
            };
            var helper = new RecurringEventsHelper();


            var items = helper.GetOccurrences(evs, new DateTime(2011, 09, 1), new DateTime(2011, 10, 1));

            Assert.AreEqual(
                1,
                items.Where(i => i.start_date.Hour == 6).Count());
        }
Ejemplo n.º 6
0
        public void DeletedEvent()
        {
            var data = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "35"
                    , text         = "!DELETED DAY"
                    , start_date   = new DateTime(2011, 09, 26, 0, 20, 0)
                    , end_date     = new DateTime(9999, 2, 1)
                    , event_length = 5100
                    , rec_type     = "week_1___0,1,2,3#no"
                    , event_pid    = null
                }

                , new SchedulerEvent()
                {
                    id             = "36"
                    , text         = "!DELETED DAY"
                    , start_date   = new DateTime(2011, 09, 28, 0, 20, 0)
                    , end_date     = new DateTime(2011, 09, 28, 1, 45, 0)
                    , event_length = 1317158400
                    , rec_type     = "none"
                    , event_pid    = "35"
                }
            };

            var helper = new RecurringEventsHelper();
            var items  = helper.GetOccurrences(data, new DateTime(2011, 9, 26), new DateTime(2011, 10, 10, 23, 59, 59));

            Assert.AreEqual(8, items.Count);
        }
Ejemplo n.º 7
0
        public void AllTogether()
        {
            var helper = new RecurringEventsHelper();

            var items = helper.GetOccurrences(getData(), new DateTime(2011, 09, 26), new DateTime(2011, 10, 28, 23, 59, 59));

            Assert.AreEqual(24, items.Count);
        }
Ejemplo n.º 8
0
        public void ParseOutOfRangePartial()
        {
            var helper           = new RecurringEventsHelper();
            var parseSingleEvent = helper.GetOccurrences(_getTestEventArray(), new DateTime(2019, 10, 1), new DateTime(2019, 11, 1));
            var expected         = _getTestEventArray();

            Assert.AreEqual(parseSingleEvent.Count, 1);
            Assert.AreEqual(expected.First(), parseSingleEvent.First());
        }
Ejemplo n.º 9
0
        public void ParseOutOfRangeEvent()
        {
            var helper           = new RecurringEventsHelper();
            var parseSingleEvent = helper.GetOccurrences(new List <SchedulerEvent> {
                this._getTestEvent()
            }, new DateTime(2019, 10, 1), new DateTime(2019, 11, 1));

            Assert.AreEqual(parseSingleEvent.Count, 0);
        }
Ejemplo n.º 10
0
        public void ParseSingleEvent()
        {
            var helper = new RecurringEventsHelper();

            var parseSingleEvent = helper.GetOccurrences(_getTestEvent(), new DateTime(2019, 1, 1), new DateTime(2020, 1, 1));

            Assert.AreEqual(parseSingleEvent.Count, 1);
            Assert.AreEqual(_getTestEvent(), parseSingleEvent.First());
        }
Ejemplo n.º 11
0
        public void EventsAtTheMoment()
        {
            var evs = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id           = "1",
                    text         = "Sample Event",
                    start_date   = new DateTime(2013, 05, 07, 08, 00, 00),
                    end_date     = new DateTime(2013, 07, 14, 00, 00, 00),
                    event_pid    = null,
                    event_length = 43200,
                    rec_type     = "day_1___#"
                }
                , new SchedulerEvent()
                {
                    id           = "2",
                    text         = "Sample Event",
                    start_date   = new DateTime(2013, 06, 07, 08, 00, 00),
                    end_date     = new DateTime(2013, 07, 14, 00, 00, 00),
                    event_pid    = null,
                    event_length = 43200,
                    rec_type     = "day_1___#"
                }
                , new SchedulerEvent()
                {
                    id           = "3",
                    text         = "Sample Event",
                    start_date   = new DateTime(2013, 05, 07, 2, 00, 00),
                    end_date     = new DateTime(2013, 05, 07, 12, 00, 00),
                    event_pid    = null,
                    event_length = 0,
                    rec_type     = ""
                }
                , new SchedulerEvent()
                {
                    id           = "4",
                    text         = "Sample Event",
                    start_date   = new DateTime(2013, 05, 07, 10, 00, 00),
                    end_date     = new DateTime(2013, 05, 07, 15, 00, 00),
                    event_pid    = null,
                    event_length = 0,
                    rec_type     = ""
                }
            };
            var helper = new RecurringEventsHelper();

            var dat   = new DateTime(2013, 05, 07, 09, 00, 00);
            var items = helper.GetOccurrences(evs, dat, dat.AddSeconds(10));

            Assert.AreEqual(
                2,
                items.Count());
        }
Ejemplo n.º 12
0
        public void ParseSingleEventArray()
        {
            var helper           = new RecurringEventsHelper();
            var parseSingleEvent = helper.GetOccurrences(_getTestEventArray(), new DateTime(2019, 1, 1), new DateTime(2020, 1, 1));

            var expected = _getTestEventArray();

            Assert.AreEqual(parseSingleEvent.Count, expected.Count);

            for (var i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected[i], parseSingleEvent[i]);
            }
        }
Ejemplo n.º 13
0
        public void MonthlySeriesEveryNDayOfWeek()
        {
            var evs = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "1"
                    , text         = "New event"
                    , start_date   = new DateTime(2020, 7, 20, 8, 0, 0)
                    , end_date     = new DateTime(2021, 5, 3, 8, 0, 0, 0)
                    , event_length = 12600
                    , rec_type     = "month_1_1_1_#10"// the first monday of each month 10 times
                    , event_pid    = null
                }
            };
            var helper = new RecurringEventsHelper();
            var items  = helper.GetOccurrences(evs, new DateTime(2020, 06, 29), new DateTime(2021, 10, 1));

            Assert.AreEqual(new DateTime(2020, 8, 3, 8, 0, 0), items[0].start_date);
        }
Ejemplo n.º 14
0
        public void WeeklyLimit()
        {
            var data = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "25"
                    , text         = "Every monday"
                    , start_date   = new DateTime(2011, 10, 03, 03, 50, 00)
                    , end_date     = new DateTime(9999, 10, 16)
                    , event_length = 8400
                    , rec_type     = "month_1_1_1_#5"
                    , event_pid    = null
                }
            };

            var helper = new RecurringEventsHelper();
            var items  = helper.GetOccurrences(data, new DateTime(2011, 9, 26), new DateTime(2012, 10, 10, 23, 59, 59));

            Assert.AreEqual(5, items.Count);
        }
Ejemplo n.º 15
0
        public void DailyEveryTwoDays()
        {
            var data = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "25"
                    , text         = "Every 2 days"
                    , start_date   = new DateTime(2011, 10, 03, 00, 45, 00)
                    , end_date     = new DateTime(9999, 01, 02)
                    , event_length = 7800
                    , rec_type     = "day_2___#no"
                    , event_pid    = null
                }
            };

            var helper = new RecurringEventsHelper();
            var items  = helper.GetOccurrences(data, new DateTime(2011, 9, 26), new DateTime(2011, 10, 10, 23, 59, 59));

            Assert.AreEqual(4, items.Count);
        }
Ejemplo n.º 16
0
        public void MonthlyStartDate()
        {
            var data = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "25"
                    , text         = "Every monday"
                    , start_date   = new DateTime(2011, 09, 01, 10, 30, 00)
                    , end_date     = new DateTime(2012, 06, 02, 10, 30, 00)
                    , event_length = 6900
                    , rec_type     = "month_1_1_1_#5"
                    , event_pid    = null
                }
            };
            var helper = new RecurringEventsHelper();

            var items = helper.GetOccurrences(data, new DateTime(2011, 09, 26), new DateTime(2011, 10, 28, 23, 59, 59));

            Assert.AreEqual(1, items.Count);
        }
Ejemplo n.º 17
0
        public void Yearly()
        {
            var data = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "38"
                    , text         = "yearly event"
                    , start_date   = new DateTime(2011, 01, 01, 14, 45, 00)
                    , end_date     = new DateTime(9999, 02, 01)
                    , event_length = 13500
                    , rec_type     = "year_1_5_2_#no"
                    , event_pid    = null
                }
            };

            var helper = new RecurringEventsHelper();
            var items  = helper.GetOccurrences(data, new DateTime(2011, 01, 1), new DateTime(2013, 1, 1, 23, 59, 59));

            Assert.AreEqual(2, items.Count);
        }
Ejemplo n.º 18
0
        public void EveryTwoMonthsExactDay()
        {
            var data = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "38"
                    , text         = "Second tuesday"
                    , start_date   = new DateTime(2011, 10, 01, 11, 50, 00)
                    , end_date     = new DateTime(9999, 02, 01)
                    , event_length = 300
                    , rec_type     = "month_2_2_2_#no"
                    , event_pid    = null
                }
            };

            var helper = new RecurringEventsHelper();
            var items  = helper.GetOccurrences(data, new DateTime(2011, 10, 11), new DateTime(2011, 11, 12, 23, 59, 59));

            Assert.AreEqual(1, items.Count);
        }
Ejemplo n.º 19
0
        public void MonthlySeriesMonthEndLastDayRule()
        {
            var evs = new List <SchedulerEvent>()
            {
                new SchedulerEvent()
                {
                    id             = "1"
                    , text         = "New event"
                    , start_date   = new DateTime(2022, 1, 31, 8, 0, 0)
                    , end_date     = new DateTime(2023, 1, 31, 8, 0, 0, 0)
                    , event_length = 12600
                    , rec_type     = "month_1___#no"// repeat 31st day every month
                    , event_pid    = null
                }
            };
            var helper = new RecurringEventsHelper
            {
                OverflowInstances = RecurringEventsHelper.OverflowInstancesRule.LastDay
            };

            var items = helper.GetOccurrences(evs, new DateTime(2022, 1, 31), new DateTime(2024, 1, 1));

            // event repeats on 31st day of every month, or on the last day of the month due to the `OverlowInstances` rule
            Assert.AreEqual(12, items.Count);
            Assert.AreEqual(new DateTime(2022, 1, 31, 8, 0, 0), items[0].start_date);
            Assert.AreEqual(new DateTime(2022, 2, 28, 8, 0, 0), items[1].start_date);
            Assert.AreEqual(new DateTime(2022, 3, 31, 8, 0, 0), items[2].start_date);
            Assert.AreEqual(new DateTime(2022, 4, 30, 8, 0, 0), items[3].start_date);
            Assert.AreEqual(new DateTime(2022, 5, 31, 8, 0, 0), items[4].start_date);
            Assert.AreEqual(new DateTime(2022, 6, 30, 8, 0, 0), items[5].start_date);
            Assert.AreEqual(new DateTime(2022, 7, 31, 8, 0, 0), items[6].start_date);
            Assert.AreEqual(new DateTime(2022, 8, 31, 8, 0, 0), items[7].start_date);
            Assert.AreEqual(new DateTime(2022, 9, 30, 8, 0, 0), items[8].start_date);
            Assert.AreEqual(new DateTime(2022, 10, 31, 8, 0, 0), items[9].start_date);
            Assert.AreEqual(new DateTime(2022, 11, 30, 8, 0, 0), items[10].start_date);
            Assert.AreEqual(new DateTime(2022, 12, 31, 8, 0, 0), items[11].start_date);
        }