Exemplo n.º 1
0
        public void Virtual_ScheduleAction()
        {
            var id        = Thread.CurrentThread.ManagedThreadId;
            var ran       = false;
            var scheduler = new VirtualSchedulerTestScheduler();

            scheduler.Schedule(() => { Assert.Equal(id, Thread.CurrentThread.ManagedThreadId); ran = true; });
            scheduler.Start();
            Assert.True(ran);
        }
Exemplo n.º 2
0
        public void Virtual_ScheduleActionDue()
        {
            var id        = Thread.CurrentThread.ManagedThreadId;
            var ran       = false;
            var scheduler = new VirtualSchedulerTestScheduler();

            scheduler.Schedule(TimeSpan.FromSeconds(0.2), () => { Assert.Equal(id, Thread.CurrentThread.ManagedThreadId); ran = true; });
            scheduler.Start();
            Assert.True(ran, "ran");
        }
Exemplo n.º 3
0
        public void Virtual_ScheduleActionDue()
        {
            var id  = Thread.CurrentThread.ManagedThreadId;
            var ran = false;
            var sw  = new Stopwatch();

            sw.Start();
            var scheduler = new VirtualSchedulerTestScheduler();

            scheduler.Schedule(TimeSpan.FromSeconds(0.2), () => { sw.Stop(); Assert.Equal(id, Thread.CurrentThread.ManagedThreadId); ran = true; });
            scheduler.Start();
            Assert.True(ran, "ran");
            Assert.True(sw.ElapsedMilliseconds > 180, "due " + sw.ElapsedMilliseconds);
        }
Exemplo n.º 4
0
        public void Virtual_ScheduleActionError()
        {
            var ex = new Exception();

            try
            {
                var scheduler = new VirtualSchedulerTestScheduler();
                scheduler.Schedule(() => { throw ex; });
                scheduler.Start();
                Assert.True(false);
            }
            catch (Exception e)
            {
                Assert.Same(e, ex);
            }
        }
Exemplo n.º 5
0
        public void Virtual_InitialAndComparer_Now()
        {
            var s = new VirtualSchedulerTestScheduler("Bar", Comparer <string> .Default);

            Assert.Equal(3, s.Now.Ticks);
        }
Exemplo n.º 6
0
        public void Virtual_Now()
        {
            var res = new VirtualSchedulerTestScheduler().Now - DateTime.Now;

            Assert.True(res.Seconds < 1);
        }