Merge pull request #3796 from ntherning/windows-backend-for-MemoryMappedFile
[mono.git] / mcs / class / corlib / Test / System.Threading.Tasks / TaskFactoryTest_T.cs
index 0c30a093b03e1f30e010b5b4141f1794cffb6118..803b10c15eb9d4384b89465ad77d1d190bde275e 100644 (file)
@@ -26,7 +26,6 @@
 //
 //
 
-#if NET_4_0
 
 using System;
 using System.Threading;
@@ -249,7 +248,28 @@ namespace MonoTests.System.Threading.Tasks
                        Assert.AreEqual ("1", task.Result, "#2");
                }
 
+               [Test]
+               public void StartNewCancelled ()
+               {
+                       var ct = new CancellationToken (true);
+                       var factory = new TaskFactory<int> ();
+
+                       var task = factory.StartNew (() => { Assert.Fail ("Should never be called"); return 1; }, ct);
+                       try {
+                               task.Start ();
+                               Assert.Fail ("#1");
+                       } catch (InvalidOperationException) {
+                       }
+
+                       try {
+                               task.Wait ();
+                               Assert.Fail ("#2");
+                       } catch (AggregateException e) {
+                               Assert.That (e.InnerException, Is.TypeOf (typeof (TaskCanceledException)), "#3");
+                       }
+
+                       Assert.IsTrue (task.IsCanceled, "#4");
+               }
        }
 }
 
-#endif