[TestFixture]
public class TaskSchedulerTests
{
- [Test]
- public void BasicRunSynchronouslyTest ()
- {
- bool ran = false;
- var t = new Task (() => ran = true);
-
- t.RunSynchronously ();
- Assert.IsTrue (t.IsCompleted);
- Assert.IsFalse (t.IsFaulted);
- Assert.IsFalse (t.IsCanceled);
- Assert.IsTrue (ran);
- }
-
class LazyCatScheduler : TaskScheduler
{
- public TaskStatus ExecuteInlineStatus {
+ public TaskStatus ExecuteInlineStatus
+ {
get;
set;
}
}
}
+ class DefaultScheduler : TaskScheduler
+ {
+ protected override IEnumerable<Task> GetScheduledTasks ()
+ {
+ throw new NotImplementedException ();
+ }
+
+ protected override void QueueTask (Task task)
+ {
+ throw new NotImplementedException ();
+ }
+
+ protected override bool TryExecuteTaskInline (Task task, bool taskWasPreviouslyQueued)
+ {
+ throw new NotImplementedException ();
+ }
+
+ public void TestDefaultMethod ()
+ {
+ Assert.IsFalse (TryDequeue (null), "#1");
+ }
+ }
+
+ [Test]
+ public void FromCurrentSynchronizationContextTest_Invalid()
+ {
+ var c = SynchronizationContext.Current;
+ try {
+ SynchronizationContext.SetSynchronizationContext (null);
+ TaskScheduler.FromCurrentSynchronizationContext ();
+ Assert.Fail ("#1");
+ } catch (InvalidOperationException) {
+ } finally {
+ SynchronizationContext.SetSynchronizationContext (c);
+ }
+ }
+
+ [Test]
+ public void BasicRunSynchronouslyTest ()
+ {
+ bool ran = false;
+ var t = new Task (() => ran = true);
+
+ t.RunSynchronously ();
+ Assert.IsTrue (t.IsCompleted);
+ Assert.IsFalse (t.IsFaulted);
+ Assert.IsFalse (t.IsCanceled);
+ Assert.IsTrue (ran);
+ }
+
[Test]
public void RunSynchronouslyButNoExecutionTest ()
{
}
}
+ [Test]
+ public void DefaultBehaviourTest ()
+ {
+ var s = new DefaultScheduler ();
+ s.TestDefaultMethod ();
+ }
+
// This test doesn't work if the GC uses multiple finalizer thread.
// For now it's fine since only one thread is used
[Test]