public void Control_ScheduleAction() { var id = Thread.CurrentThread.ManagedThreadId; var lbl = CreateLabel(); var sch = new ControlScheduler(lbl); var evt = new ManualResetEvent(false); sch.Schedule(() => { lbl.Text = "Okay"; Assert.AreNotEqual(id, Thread.CurrentThread.ManagedThreadId); }); sch.Schedule(() => { Assert.AreEqual("Okay", lbl.Text); Assert.AreNotEqual(id, Thread.CurrentThread.ManagedThreadId); evt.Set(); }); evt.WaitOne(); Application.Exit(); }
public void Control_ScheduleActionError() { var ex = new Exception(); var evt = new ManualResetEvent(false); var id = Thread.CurrentThread.ManagedThreadId; var lbl = CreateLabelWithHandler(e => { Assert.AreSame(ex, e); evt.Set(); }); var sch = new ControlScheduler(lbl); sch.Schedule(() => { throw ex; }); evt.WaitOne(); Application.Exit(); }
public void Control_ScheduleActionDue() { var id = Thread.CurrentThread.ManagedThreadId; var lbl = CreateLabel(); var sch = new ControlScheduler(lbl); var evt = new ManualResetEvent(false); var sw = new Stopwatch(); sw.Start(); sch.Schedule(() => { sw.Stop(); lbl.Text = "Okay"; Assert.AreNotEqual(id, Thread.CurrentThread.ManagedThreadId); sw.Start(); sch.Schedule(() => { sw.Stop(); Assert.AreEqual("Okay", lbl.Text); Assert.AreNotEqual(id, Thread.CurrentThread.ManagedThreadId); evt.Set(); }, TimeSpan.FromSeconds(0.2)); }, TimeSpan.FromSeconds(0.2)); evt.WaitOne(); Assert.IsTrue(sw.ElapsedMilliseconds > 380, "due " + sw.ElapsedMilliseconds); Application.Exit(); }
public void Control_ScheduleActionDueNow() { var id = Thread.CurrentThread.ManagedThreadId; var lbl = CreateLabel(); var sch = new ControlScheduler(lbl); var evt = new ManualResetEvent(false); var sw = new Stopwatch(); sw.Start(); sch.Schedule(() => { sw.Stop(); lbl.Text = "Okay"; Assert.AreNotEqual(id, Thread.CurrentThread.ManagedThreadId); sw.Start(); sch.Schedule(() => { sw.Stop(); Assert.AreEqual("Okay", lbl.Text); Assert.AreNotEqual(id, Thread.CurrentThread.ManagedThreadId); evt.Set(); }, TimeSpan.Zero); }, TimeSpan.Zero); evt.WaitOne(); Application.Exit(); }
public void Control_Now() { var res = new ControlScheduler(new Label()).Now - DateTime.Now; Assert.IsTrue(res.Seconds < 1); }