Exemplo n.º 1
0
        public void Context_AddSchedule_ShouldAddCauseEventToBeTriggeredFromSchedule()
        {
            bool reached = false;

            // create the orchestrator
            var context = new EventContext(defaultScheduleTimeIntervalInMilliseconds: 25);

            context.AddLogAction(
                (m) => output.WriteLine(m.ToString())
                );

            var timeSecond = DateTime.Now.Second;

            // create a schedule that will only fire the Action when the time matches the event time
            context.AddScheduledAction(new Schedule {
                Frequency = ScheduleFrequency.OnceEveryUnitsMinute, FrequencyUnit = timeSecond
            },
                                       (hitTime) => { output.WriteLine($"EVENT HIT: {hitTime}"); reached = true; });

            // run and ensure the listeners are all responding
            context.Initialize();

            Thread.Sleep(50);             // just wait a bit for the events to be handled

            // a few time e vents may be release
            context.AssertEventExists <TimeEvent>(atLeast: 1);
            reached.Should().BeTrue();
        }