annotate Implab.Test/RunnableComponentTests.cs @ 217:6efb77590b15 v2

More verbose output with TextFileListener
author cin
date Tue, 02 May 2017 17:33:04 +0300
parents 7d07503621fe
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
1 using System;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
2 using System.Reflection;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
3 using System.Threading;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
4 using Implab.Parallels;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
5 using Implab.Components;
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
6 using Implab.Test.Mock;
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
7
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
8 #if MONO
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
9
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
10 using NUnit.Framework;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
11 using TestClassAttribute = NUnit.Framework.TestFixtureAttribute;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
12 using TestMethodAttribute = NUnit.Framework.TestAttribute;
188
3071220371f8 Updated VS project
cin
parents: 185
diff changeset
13 using AssertFailedException = NUnit.Framework.AssertionException;
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
14 #else
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
15
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
16 using Microsoft.VisualStudio.TestTools.UnitTesting;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
17
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
18 #endif
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
19
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
20 namespace Implab.Test {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
21 [TestClass]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
22 public class RunnableComponentTests {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
23
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
24 static void ShouldThrow(Action action) {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
25 try {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
26 action();
188
3071220371f8 Updated VS project
cin
parents: 185
diff changeset
27 Assert.Fail();
3071220371f8 Updated VS project
cin
parents: 185
diff changeset
28 } catch (AssertFailedException) {
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
29 throw;
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
30 } catch {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
31 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
32 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
33
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
34
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
35
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
36 [TestMethod]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
37 public void NormalFlowTest() {
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
38 var comp = new MockRunnableComponent(false);
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
39
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
40 Assert.AreEqual(ExecutionState.Created, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
41
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
42 comp.Initialize();
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
43
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
44 Assert.AreEqual(ExecutionState.Ready, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
45
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
46 comp.Start().Join(1000);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
47
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
48 Assert.AreEqual(ExecutionState.Running, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
49
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
50 comp.Stop().Join(1000);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
51
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
52 Assert.AreEqual(ExecutionState.Disposed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
53
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
54 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
55
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
56 [TestMethod]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
57 public void InitFailTest() {
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
58 var comp = new MockRunnableComponent(false) {
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
59 MockInit = () => {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
60 throw new Exception("BAD");
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
61 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
62 };
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
63
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
64 ShouldThrow(() => comp.Start());
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
65 ShouldThrow(() => comp.Stop());
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
66 Assert.AreEqual(ExecutionState.Created, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
67
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
68 ShouldThrow(comp.Initialize);
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
69
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
70 Assert.AreEqual(ExecutionState.Failed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
71
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
72 ShouldThrow(() => comp.Start());
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
73 ShouldThrow(() => comp.Stop());
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
74 Assert.AreEqual(ExecutionState.Failed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
75
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
76 comp.Dispose();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
77 Assert.AreEqual(ExecutionState.Disposed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
78 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
79
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
80 [TestMethod]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
81 public void DisposedTest() {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
82
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
83 var comp = new MockRunnableComponent(false);
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
84 comp.Dispose();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
85
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
86 ShouldThrow(() => comp.Start());
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
87 ShouldThrow(() => comp.Stop());
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
88 ShouldThrow(comp.Initialize);
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
89
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
90 Assert.AreEqual(ExecutionState.Disposed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
91 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
92
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
93 [TestMethod]
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
94 public void ShouldCallDisposeOnStop() {
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
95 var comp = new MockRunnableComponent(true);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
96
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
97 bool disposed = false;
208
7d07503621fe RunnableComponent.Dispose(bool,Exception) changed to standart Dispose(bool)
cin
parents: 205
diff changeset
98 comp.MockDispose = (disposing) => {
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
99 disposed = true;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
100 };
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
101
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
102 comp.Start().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
103 comp.Stop().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
104
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
105 ShouldThrow(() => comp.Start());
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
106 ShouldThrow(() => comp.Stop());
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
107 ShouldThrow(comp.Initialize);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
108
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
109 Assert.AreEqual(ExecutionState.Disposed, comp.State);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
110 Assert.IsTrue(disposed);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
111 }
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
112
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
113 [TestMethod]
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
114 public void ShouldNotCallDisposeOnStop() {
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
115 var comp = new MockRunnableComponent(true, true);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
116
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
117 bool disposed = false;
208
7d07503621fe RunnableComponent.Dispose(bool,Exception) changed to standart Dispose(bool)
cin
parents: 205
diff changeset
118 comp.MockDispose = (disposing) => {
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
119 disposed = true;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
120 };
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
121
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
122 comp.Start().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
123 comp.Stop().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
124
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
125 Assert.AreEqual(ExecutionState.Ready, comp.State);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
126 Assert.IsFalse(disposed);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
127 }
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
128
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
129 [TestMethod]
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
130 public void SelfDisposeOnStop() {
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
131 var comp = new MockRunnableComponent(true, true);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
132
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
133 bool disposed = false;
208
7d07503621fe RunnableComponent.Dispose(bool,Exception) changed to standart Dispose(bool)
cin
parents: 205
diff changeset
134 comp.MockDispose = (disposing) => {
205
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
135 disposed = true;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
136 };
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
137
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
138 comp.Start().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
139 comp.Stop().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
140
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
141 Assert.AreEqual(ExecutionState.Ready, comp.State);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
142 Assert.IsFalse(disposed);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
143
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
144 comp.MockStop = () => {
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
145 comp.Dispose();
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
146 return Promise.Success;
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
147 };
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
148
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
149 comp.Start().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
150 comp.Stop().Join(1000);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
151
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
152 Assert.AreEqual(ExecutionState.Disposed, comp.State);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
153 Assert.IsTrue(disposed);
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
154 }
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
155
8200ab154c8a Added ResetState to RunnableComponent to reset in case of failure
cin
parents: 203
diff changeset
156 [TestMethod]
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
157 public void StartCancelTest() {
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
158 var comp = new MockRunnableComponent(true) {
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
159 MockStart = () => PromiseHelper.Sleep(100000, 0)
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
160 };
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
161
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
162 var p = comp.Start();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
163 Assert.AreEqual(ExecutionState.Starting, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
164 p.Cancel();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
165 ShouldThrow(() => p.Join(1000));
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
166 Assert.AreEqual(ExecutionState.Failed, comp.State);
188
3071220371f8 Updated VS project
cin
parents: 185
diff changeset
167
194
d45bdf510514 working on diagnostics
cin
parents: 188
diff changeset
168 Assert.IsTrue(comp.LastError is OperationCanceledException);
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
169
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
170 comp.Dispose();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
171 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
172
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
173 [TestMethod]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
174 public void StartStopTest() {
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
175 var stop = new Signal();
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
176 var comp = new MockRunnableComponent(true) {
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
177 MockStart = () => PromiseHelper.Sleep(100000, 0),
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
178 MockStop = () => AsyncPool.RunThread(stop.Wait)
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
179 };
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
180
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
181 var p1 = comp.Start();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
182 var p2 = comp.Stop();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
183 // should enter stopping state
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
184
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
185 ShouldThrow(p1.Join);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
186 Assert.IsTrue(p1.IsCancelled);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
187 Assert.AreEqual(ExecutionState.Stopping, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
188
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
189 stop.Set();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
190 p2.Join(1000);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
191 Assert.AreEqual(ExecutionState.Disposed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
192 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
193
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
194 [TestMethod]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
195 public void StartStopFailTest() {
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
196 var comp = new MockRunnableComponent(true) {
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
197 MockStart = () => PromiseHelper.Sleep(100000, 0).Then(null,null,x => { throw new Exception("I'm dead"); })
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
198 };
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
199
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
200 comp.Start();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
201 var p = comp.Stop();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
202 // if Start fails to cancel, should fail to stop
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
203 ShouldThrow(() => p.Join(1000));
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
204 Assert.AreEqual(ExecutionState.Failed, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
205 Assert.IsNotNull(comp.LastError);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
206 Assert.AreEqual("I'm dead", comp.LastError.Message);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
207 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
208
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
209 [TestMethod]
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
210 public void StopCancelTest() {
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents: 194
diff changeset
211 var comp = new MockRunnableComponent(true) {
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
212 MockStop = () => PromiseHelper.Sleep(100000, 0)
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
213 };
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
214
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
215 comp.Start();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
216 var p = comp.Stop();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
217 Assert.AreEqual(ExecutionState.Stopping, comp.State);
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
218 p.Cancel();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
219 ShouldThrow(() => p.Join(1000));
188
3071220371f8 Updated VS project
cin
parents: 185
diff changeset
220 Assert.AreEqual(ExecutionState.Failed, comp.State);
194
d45bdf510514 working on diagnostics
cin
parents: 188
diff changeset
221 Assert.IsTrue(comp.LastError is OperationCanceledException);
185
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
222
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
223 comp.Dispose();
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
224 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
225
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
226 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
227 }
822aab37b107 runnable component, work in progress
cin
parents:
diff changeset
228