public void Wait_Inlined () { bool? previouslyQueued = null; var scheduler = new MockScheduler (); scheduler.TryExecuteTaskInlineHandler += (task, b) => { previouslyQueued = b; }; var tf = new TaskFactory (scheduler); var t = tf.StartNew (() => { }); t.Wait (); Assert.AreEqual (true, previouslyQueued); }
public void RunSynchronously_SchedulerException() { var scheduler = new MockScheduler(); scheduler.TryExecuteTaskInlineHandler += (task, b) => { throw new ApplicationException(); }; Task t = new Task(() => { }); try { t.RunSynchronously(scheduler); Assert.Fail(); } catch (Exception e) { Assert.AreEqual(t.Exception.InnerException, e); } }
public void RunSynchronously () { var val = 0; Task t = new Task (() => { Thread.Sleep (100); val = 1; }); t.RunSynchronously (); Assert.AreEqual (1, val, "#1"); t = new Task (() => { Thread.Sleep (0); val = 2; }); bool? previouslyQueued = null; var scheduler = new MockScheduler (); scheduler.TryExecuteTaskInlineHandler += (task, b) => { previouslyQueued = b; }; t.RunSynchronously (scheduler); Assert.AreEqual (2, val, "#2"); Assert.AreEqual (false, previouslyQueued, "#2a"); }
public void RunSynchronously () { var val = 0; Task t = new Task (() => { Thread.Sleep (100); val = 1; }); t.RunSynchronously (); Assert.AreEqual (1, val, "#1"); t = new Task (() => { Thread.Sleep (0); val = 2; }); bool? previouslyQueued = null; var scheduler = new MockScheduler (); scheduler.TryExecuteTaskInlineHandler += (task, b) => { previouslyQueued = b; }; t.RunSynchronously (scheduler); Assert.AreEqual (2, val, "#2"); Assert.AreEqual (false, previouslyQueued, "#2a"); }
public void Wait_Inlined () { bool? previouslyQueued = null; var scheduler = new MockScheduler (); scheduler.TryExecuteTaskInlineHandler += (task, b) => { previouslyQueued = b; }; var tf = new TaskFactory (scheduler); var t = tf.StartNew (() => { }); t.Wait (); Assert.AreEqual (true, previouslyQueued); }
public void RunSynchronously_SchedulerException() { var scheduler = new MockScheduler(); scheduler.TryExecuteTaskInlineHandler += (task, b) => { throw new ApplicationException(); }; Task t = new Task(() => { }); try { t.RunSynchronously(scheduler); Assert.Fail(); } catch (Exception e) { Assert.AreEqual(t.Exception.InnerException, e); } }