Exemple #1
0
        public void Schedule_in_future_using_DateTimeOffset_invokes_Enqueue_in_background_on_threadpool()
        {
            var        dispatcher                = new TestDispatcher();
            bool       disposeCalled             = false;
            var        eventWaitHandle           = new ManualResetEvent(false);
            var        dueTime                   = DateTimeOffset.Now.AddMilliseconds(100);
            int?       statePassedToCallback     = null;
            IScheduler schedulerPassedToCallback = null;

            using (dispatcher.Schedule(1337, dueTime, (sched, state) =>
            {
                statePassedToCallback = state;
                schedulerPassedToCallback = sched;
                eventWaitHandle.Set();
                return(Disposable.Create(() => disposeCalled = true));
            }))
            {
                Assert.That(eventWaitHandle.WaitOne(1000), Is.True, "Timed out waiting for action to get invoked in background");
                Assert.That(disposeCalled, Is.False);
            }

            Assert.That(statePassedToCallback, Is.EqualTo(1337));
            Assert.That(schedulerPassedToCallback, Is.EqualTo(dispatcher));
            Assert.That(disposeCalled, Is.True);
        }
Exemple #2
0
        public void Schedule_with_state_and_action()
        {
            var  dispatcher    = new TestDispatcher();
            bool disposeCalled = false;

            using (dispatcher.Schedule(1337, (sched, state) =>
            {
                Assert.That(state, Is.EqualTo(1337));
                Assert.That(sched, Is.EqualTo(dispatcher));
                return(Disposable.Create(() => disposeCalled = true));
            }))
            {
                // Should be scheduled immediately
                Assert.That(disposeCalled, Is.False);
            }

            Assert.That(disposeCalled, Is.True);
        }