public void TestConfigurationChangeAggregate()
        {
            SchedulerConfiguration current = SchedulerConfiguration.Active;

            try
            {
                ISchedule oneOff    = Scheduler.GetSchedule("OneOff");
                ISchedule gap       = Scheduler.GetSchedule("Gap");
                ISchedule etm       = Scheduler.GetSchedule("EveryTwoMonths");
                ISchedule aggregate = Scheduler.GetSchedule("Aggregate");

                SchedulerConfiguration newConfig = CloneConfig(current);
                newConfig.Schedules["Aggregate"].Parameters.Remove("schedule3");

                SchedulerConfiguration.Active = newConfig;

                Thread.Sleep(ConfigurationExtensions.EventBufferMs * 2);

                Assert.AreSame(oneOff, Scheduler.GetSchedule("OneOff"));
                Assert.AreSame(gap, Scheduler.GetSchedule("Gap"));
                Assert.AreSame(etm, Scheduler.GetSchedule("EveryTwoMonths"));
                AggregateSchedule newAggregate = Scheduler.GetSchedule("Aggregate") as AggregateSchedule;
                Assert.IsNotNull(newAggregate);
                Assert.AreNotSame(aggregate, newAggregate);
                Assert.AreEqual(2, newAggregate.Count());
            }
            finally
            {
                SchedulerConfiguration.Active = current;
            }
        }
 public void EmptyAggregateSchedule()
 {
     string name = Tester.RandomGenerator.RandomString();
     AggregateSchedule aggregateSchedule = new AggregateSchedule(name);
     Assert.AreEqual(name, aggregateSchedule.Name);
     Assert.AreEqual(Instant.MaxValue, aggregateSchedule.Next(TimeHelpers.Clock.Now));
     Assert.AreEqual(0, aggregateSchedule.Count());
 }
示例#3
0
        public void EmptyAggregateSchedule()
        {
            string            name = Tester.RandomGenerator.RandomString();
            AggregateSchedule aggregateSchedule = new AggregateSchedule(name);

            Assert.AreEqual(name, aggregateSchedule.Name);
            Assert.AreEqual(Instant.MaxValue, aggregateSchedule.Next(TimeHelpers.Clock.Now));
            Assert.AreEqual(0, aggregateSchedule.Count());
        }
示例#4
0
    public void ShouldNotBeInSchedule_WhenNotTheDayOfWeek()
    {
        var schedule = new AggregateSchedule
                       (
            Schedule.On(DayOfWeek.Monday).At(TimeRange.AllDay())
                       );
        var result = schedule.IsInSchedule(new DateTime(2020, 10, 20, 12, 0, 0));

        Assert.That(result, Is.False, "Should not be scheduled when not the day of week");
    }
示例#5
0
    public void ShouldBeInScheduleByDayOfWeek()
    {
        var schedule = new AggregateSchedule
                       (
            Schedule.On(DayOfWeek.Monday).At(TimeRange.AllDay())
                       );
        var result = schedule.IsInSchedule(new DateTime(2020, 10, 19, 12, 0, 0));

        Assert.That(result, Is.True, "Should be scheduled by day of week");
    }
 public void SingleAggregateSchedule()
 {
     Instant i = new Instant(Tester.RandomGenerator.RandomInt32());
     OneOffSchedule oneOffSchedule = new OneOffSchedule(i);
     AggregateSchedule aggregateSchedule = new AggregateSchedule(oneOffSchedule);
     Assert.AreEqual(1, aggregateSchedule.Count());
     Assert.AreEqual(i, aggregateSchedule.Next(i - TimeHelpers.OneSecond));
     Assert.AreEqual(i, aggregateSchedule.Next(i));
     Assert.AreEqual(Instant.MaxValue, aggregateSchedule.Next(i + Duration.FromTicks(1)));
 }
示例#7
0
    public void ShouldNotBeInSchedule_WhenNotInTimeRange()
    {
        var schedule = new AggregateSchedule
                       (
            Schedule.On(DayOfWeek.Monday)
            .At(TimeRange.From(10, 0).For(2).Hours())
                       );
        var result = schedule.IsInSchedule(new DateTime(2020, 10, 19, 8, 0, 0));

        Assert.That(result, Is.False, "Should not be in schedule");
    }
示例#8
0
        public void SingleAggregateSchedule()
        {
            Instant           i = new Instant(Tester.RandomGenerator.RandomInt32());
            OneOffSchedule    oneOffSchedule    = new OneOffSchedule(i);
            AggregateSchedule aggregateSchedule = new AggregateSchedule(oneOffSchedule);

            Assert.AreEqual(1, aggregateSchedule.Count());
            Assert.AreEqual(i, aggregateSchedule.Next(i - TimeHelpers.OneSecond));
            Assert.AreEqual(i, aggregateSchedule.Next(i));
            Assert.AreEqual(Instant.MaxValue, aggregateSchedule.Next(i + Duration.FromTicks(1)));
        }
 public void DoubleAggregateSchedule()
 {
     Instant i = new Instant(Tester.RandomGenerator.RandomInt32());
     Instant j = i + TimeHelpers.OneSecond;
     OneOffSchedule s1 = new OneOffSchedule(i);
     OneOffSchedule s2 = new OneOffSchedule(j);
     AggregateSchedule aggregateSchedule = new AggregateSchedule(s1, s2);
     Assert.AreEqual(2, aggregateSchedule.Count());
     Assert.AreEqual(i, aggregateSchedule.Next(i - TimeHelpers.OneSecond));
     Assert.AreEqual(i, aggregateSchedule.Next(i));
     Assert.AreEqual(j, aggregateSchedule.Next(i + Duration.FromTicks(1)));
     Assert.AreEqual(j, aggregateSchedule.Next(j));
     Assert.AreEqual(Instant.MaxValue, aggregateSchedule.Next(j + Duration.FromTicks(1)));
 }
示例#10
0
    public void ShouldBeInSchedule_WhenDateTimeIsInAnyOfTheOptionDaysOfTheWeek()
    {
        var schedule = new AggregateSchedule
                       (
            Schedule.On(DayOfWeek.Monday, DayOfWeek.Wednesday)
            .At
            (
                TimeRange.From(10, 0).For(2).Hours(),
                TimeRange.From(17, 0).For(2).Hours()
            )
                       );
        var result = schedule.IsInSchedule(new DateTime(2020, 10, 21, 18, 0, 0));

        Assert.That(result, Is.True, "Should be in schedule");
    }
示例#11
0
        public void DoubleAggregateSchedule()
        {
            Instant           i  = new Instant(Tester.RandomGenerator.RandomInt32());
            Instant           j  = i + TimeHelpers.OneSecond;
            OneOffSchedule    s1 = new OneOffSchedule(i);
            OneOffSchedule    s2 = new OneOffSchedule(j);
            AggregateSchedule aggregateSchedule = new AggregateSchedule(s1, s2);

            Assert.AreEqual(2, aggregateSchedule.Count());
            Assert.AreEqual(i, aggregateSchedule.Next(i - TimeHelpers.OneSecond));
            Assert.AreEqual(i, aggregateSchedule.Next(i));
            Assert.AreEqual(j, aggregateSchedule.Next(i + Duration.FromTicks(1)));
            Assert.AreEqual(j, aggregateSchedule.Next(j));
            Assert.AreEqual(Instant.MaxValue, aggregateSchedule.Next(j + Duration.FromTicks(1)));
        }
        public void TestConfigurationChangeGap()
        {
            SchedulerConfiguration current = SchedulerConfiguration.Active;

            try
            {
                ISchedule oneOff    = Scheduler.GetSchedule("OneOff");
                ISchedule gap       = Scheduler.GetSchedule("Gap");
                ISchedule etm       = Scheduler.GetSchedule("EveryTwoMonths");
                ISchedule aggregate = Scheduler.GetSchedule("Aggregate");

                SchedulerConfiguration newConfig = CloneConfig(current);
                newConfig.Schedules["Gap"].Parameters["timeSpan"].Value = "4.00:00:00";

                SchedulerConfiguration.Active = newConfig;

                Thread.Sleep(ConfigurationExtensions.EventBufferMs * 2);

                Assert.AreSame(oneOff, Scheduler.GetSchedule("OneOff"));
                Assert.AreNotSame(gap, Scheduler.GetSchedule("Gap"));
                Assert.AreSame(etm, Scheduler.GetSchedule("EveryTwoMonths"));
                Assert.AreNotSame(aggregate, Scheduler.GetSchedule("Aggregate"));

                ISchedule newGap = Scheduler.GetSchedule("Gap");
                Assert.IsNotNull(newGap);
                Assert.IsInstanceOfType(newGap, typeof(GapSchedule));

                Instant  i = Instant.FromDateTimeOffset(DateTimeOffset.Parse("13/01/2100 09:10:11 +00:00"));
                Duration d = Duration.FromTimeSpan(TimeSpan.Parse("4.00:00:00"));
                Assert.AreEqual(i + d, newGap.Next(i));

                AggregateSchedule newAggregate = Scheduler.GetSchedule("Aggregate") as AggregateSchedule;
                Assert.IsNotNull(newAggregate);

                ISchedule[] array = newAggregate.ToArray();
                Assert.AreEqual(3, array.Length);
                Assert.AreSame(oneOff, array[0]);
                Assert.AreSame(newGap, array[1]);
                Assert.AreSame(etm, array[2]);
            }
            finally
            {
                SchedulerConfiguration.Active = current;
            }
        }
        public void TestMethod1()
        {
            ISchedule oneOff = Scheduler.GetSchedule("OneOff");

            Assert.IsNotNull(oneOff);
            Assert.IsInstanceOfType(oneOff, typeof(OneOffSchedule));

            Instant i = Instant.FromDateTimeOffset(DateTimeOffset.Parse("13/01/2100 09:10:11 +00:00"));

            Assert.AreEqual(i, oneOff.Next(Instant.MinValue));
            Assert.AreEqual(Instant.MaxValue, oneOff.Next(i + Duration.FromTicks(1)));


            ISchedule gap = Scheduler.GetSchedule("Gap");

            Assert.IsNotNull(gap);
            Assert.IsInstanceOfType(gap, typeof(GapSchedule));

            Duration d = Duration.FromTimeSpan(TimeSpan.Parse("3.12:00:00"));

            Assert.AreEqual(i + d, gap.Next(i));

            ISchedule etm = Scheduler.GetSchedule("EveryTwoMonths");

            Assert.IsNotNull(etm);
            Assert.IsInstanceOfType(etm, typeof(PeriodicSchedule));

            ISchedule aggregate = Scheduler.GetSchedule("Aggregate");

            Assert.IsNotNull(aggregate);
            Assert.IsInstanceOfType(aggregate, typeof(AggregateSchedule));

            AggregateSchedule ags = aggregate as AggregateSchedule;

            Assert.IsNotNull(ags);

            ISchedule[] array = ags.ToArray();
            Assert.AreEqual(3, array.Length);
            Assert.AreSame(oneOff, array[0]);
            Assert.AreSame(gap, array[1]);
            Assert.AreSame(etm, array[2]);
        }
示例#14
0
    public void ShouldDeserializeSchedule()
    {
        var schedule = new AggregateSchedule
                       (
            Schedule.On(DayOfWeek.Monday)
            .At(TimeRange.From(10, 0).ForOneHour()),
            Schedule.On(new MonthDay(15))
            .At(TimeRange.From(11, 0).ForOneHour()),
            Schedule.First(DayOfWeek.Monday).OfEveryMonth()
            .At(TimeRange.From(12, 0).ForOneHour()),
            Schedule.On(new YearDay(10, 13))
            .At(TimeRange.From(13, 0).ForOneHour()),
            Schedule.First(DayOfWeek.Tuesday).Of(Months.October)
            .At(TimeRange.From(14, 0).ForOneHour()),
            Schedule.Every(2).Weeks().Starting(new DateTime(2021, 10, 12))
            .At(TimeRange.From(15, 0).ForOneHour())
                       );
        var serialized   = schedule.Serialize();
        var deserialized = AggregateSchedule.Deserialize(serialized);

        Assert.That
        (
            deserialized.DateTimeRanges
            (
                DateRange.Between(new DateTime(2021, 10, 1), new DateTime(2021, 10, 31))
            ),
            Is.EqualTo
            (
                new[]
        {
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 4, 10, 0, 0),
                new DateTime(2021, 10, 4, 11, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 4, 12, 0, 0),
                new DateTime(2021, 10, 4, 13, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 5, 14, 0, 0),
                new DateTime(2021, 10, 5, 15, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 11, 10, 0, 0),
                new DateTime(2021, 10, 11, 11, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 12, 15, 0, 0),
                new DateTime(2021, 10, 12, 16, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 13, 13, 0, 0),
                new DateTime(2021, 10, 13, 14, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 15, 11, 0, 0),
                new DateTime(2021, 10, 15, 12, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 18, 10, 0, 0),
                new DateTime(2021, 10, 18, 11, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 25, 10, 0, 0),
                new DateTime(2021, 10, 25, 11, 0, 0)
            ),
            DateTimeRange.Between
            (
                new DateTime(2021, 10, 26, 15, 0, 0),
                new DateTime(2021, 10, 26, 16, 0, 0)
            )
        }
            )
        );
    }