public void When_ScheduleOnce_using_canceled_Cancelable_Then_their_actions_should_not_be_invoked()
        {
            // Prepare, set up actions to be fired
            IActionScheduler scheduler = new DedicatedThreadScheduler(Sys);

            var canceled = Cancelable.CreateCanceled();
            scheduler.ScheduleOnce(0, () => TestActor.Tell("Test"), canceled);

            //Validate that no messages were sent
            ExpectNoMsg(100);
        }
        public void When_ScheduleOnce_and_then_canceling_before_they_occur_Then_their_actions_should_not_be_invoked()
        {
            // Prepare, set up actions to be fired
            IActionScheduler scheduler = new DedicatedThreadScheduler(Sys);

            var cancelable = new Cancelable(scheduler);
            scheduler.ScheduleOnce(100, () => TestActor.Tell("Test"), cancelable);
            cancelable.Cancel();

            //Validate that no messages were sent
            ExpectNoMsg(150);
        }
        public void When_ScheduleOnce_and_then_canceling_before_they_occur_Then_their_actions_should_not_be_invoked()
        {
            // Prepare, set up actions to be fired
            IActionScheduler scheduler = new DedicatedThreadScheduler(Sys.Settings.Config, Log);

            try
            {
                var cancelable = new Cancelable(scheduler);
                scheduler.ScheduleOnce(100, () => TestActor.Tell("Test"), cancelable);
                cancelable.Cancel();

                //Validate that no messages were sent
                ExpectNoMsg(150);
            }
            finally
            {
                scheduler.AsInstanceOf<IDisposable>().Dispose();
            }
        }
        public void ScheduleOnceTests()
        {
            // Prepare, set up actions to be fired
            IActionScheduler testScheduler = new DedicatedThreadScheduler(Sys);

            testScheduler.ScheduleOnce(50, () => TestActor.Tell("Test1"));
            testScheduler.ScheduleOnce(100, () => TestActor.Tell("Test2"));

            ExpectMsg("Test1");
            ExpectMsg("Test2");

            ExpectNoMsg(100);
        }
        public void When_ScheduleOnce_with_0_delay_Then_action_is_executed_immediately()
        {
            IActionScheduler testScheduler = new DedicatedThreadScheduler(Sys);
            var manualResetEvent = new ManualResetEventSlim();
            manualResetEvent.IsSet.ShouldBeFalse();
            testScheduler.ScheduleOnce(0, () => manualResetEvent.Set());

            manualResetEvent.Wait(500).ShouldBeTrue();
        }
        public void When_ScheduleOnce_with_invalid_delay_Then_exception_is_thrown(int invalidTime)
        {
            IActionScheduler testScheduler = new DedicatedThreadScheduler(Sys);

            XAssert.Throws<ArgumentOutOfRangeException>(() =>
                testScheduler.ScheduleOnce(invalidTime, () => { })
                );
        }
        public void When_ScheduleOnce_many_at_the_same_time_Then_all_fires(int[] times)
        {
            // Prepare, set up actions to be fired
            IActionScheduler scheduler = new DedicatedThreadScheduler(Sys);

            foreach(var time in times)
            {
                var t = time;
                scheduler.ScheduleOnce(time, () => TestActor.Tell("Test" + t));
            }

            //Perform the test
            ExpectMsg("Test1");
            ExpectMsg("Test1");
            ExpectMsg("Test50");
            ExpectMsg("Test50");
            ExpectMsg("Test100");
            ExpectMsg("Test100");
            ExpectNoMsg(50);
        }