summaryrefslogtreecommitdiff
path: root/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest_T.cs
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest_T.cs')
-rw-r--r--mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest_T.cs26
1 files changed, 26 insertions, 0 deletions
diff --git a/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest_T.cs b/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest_T.cs
index 0c30a093b0..ff964bb9cf 100644
--- a/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest_T.cs
+++ b/mcs/class/corlib/Test/System.Threading.Tasks/TaskFactoryTest_T.cs
@@ -33,6 +33,9 @@ using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
+#if !MOBILE
+using NUnit.Framework.SyntaxHelpers;
+#endif
namespace MonoTests.System.Threading.Tasks
{
@@ -249,6 +252,29 @@ 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) {
+ }
+
+ Assert.IsTrue (task.IsCanceled, "#2");
+
+ task = factory.StartNew (() => 1, ct);
+ try {
+ task.Wait ();
+ } catch (AggregateException e) {
+ Assert.IsTrue (task.IsCanceled, "#3");
+ Assert.That (e.InnerException, Is.TypeOf (typeof (TaskCanceledException)), "#4");
+ }
+ }
}
}