ca8309e21b235e29b242051c64521f3f23e25ecc
[mono.git] / mcs / class / System.Threading.Tasks.Dataflow / Test / System.Threading.Tasks.Dataflow / CompletionHelperTest.cs
1 // 
2 // CompletionHelperTest.cs
3 //  
4 // Author:
5 //       Jérémie "garuma" Laval <jeremie.laval@gmail.com>
6 // 
7 // Copyright (c) 2011 Jérémie "garuma" Laval
8 // 
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 // 
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 // 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
26
27 using System;
28 using System.Linq;
29 using System.Threading.Tasks;
30 using System.Threading.Tasks.Dataflow;
31
32 using NUnit.Framework;
33
34 namespace MonoTests.System.Threading.Tasks.Dataflow
35 {
36         [TestFixture]
37         public class CompletionHelperTest
38         {
39                 CompletionHelper helper;
40
41                 [SetUp]
42                 public void Setup ()
43                 {
44                         helper = CompletionHelper.GetNew (null);
45                 }
46
47                 [Test]
48                 public void InitialStateTest ()
49                 {
50                         Task completed = helper.Completion;
51
52                         Assert.IsNotNull (completed);
53                         Assert.IsFalse (completed.IsCompleted);
54                 }
55
56                 [Test]
57                 public void FaultedTest ()
58                 {
59                         Exception ex = new ApplicationException ("Foobar");
60                         helper.RequestFault (ex);
61                         Task completed = helper.Completion;
62
63                         Assert.IsNotNull (completed);
64                         Assert.IsTrue (completed.IsCompleted);
65                         Assert.AreEqual (TaskStatus.Faulted, completed.Status);
66                         Assert.AreEqual (ex, completed.Exception.InnerExceptions.First ());
67                 }
68
69                 [Test]
70                 public void CompleteTest ()
71                 {
72                         helper.Complete ();
73                         Task completed = helper.Completion;
74
75                         Assert.IsNotNull (completed);
76                         Assert.IsTrue (completed.IsCompleted);
77                         Assert.IsFalse (completed.IsFaulted);
78                         Assert.IsFalse (completed.IsCanceled);
79                 }
80         }
81 }