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); }
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"); }
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); }
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); } }