annotate Implab.Test/RunnableComponentTests.cs @ 260:547a2fc0d93e v3 v3.0.6

minor fixes
author cin
date Fri, 13 Apr 2018 19:14:59 +0300
parents 7d52dc684bbd
children f1696cdc3d7a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
259
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
1 using System;
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
2 using System.Threading;
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
3 using System.Threading.Tasks;
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
4 using Implab.Components;
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
5 using Xunit;
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
6
260
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
7 namespace Implab.Test {
259
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
8
260
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
9 public class RunnableComponentTests {
259
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
10 [Fact]
260
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
11 public async Task Test1() {
259
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
12
260
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
13 using (var m = new MockPollComponent(true)) {
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
14 m.StartWorker = async (ct) => await Task.Yield();
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
15 m.StopWorker = async (ct) => await Task.Yield();
259
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
16
260
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
17 Assert.Equal(ExecutionState.Ready, m.State);
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
18 Assert.NotNull(m.Completion);
259
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
19
260
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
20 m.Start(CancellationToken.None);
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
21 await m.Completion;
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
22 Assert.Equal(ExecutionState.Running, m.State);
259
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
23
260
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
24 m.Stop(CancellationToken.None);
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
25 await m.Completion;
547a2fc0d93e minor fixes
cin
parents: 259
diff changeset
26 Assert.Equal(ExecutionState.Stopped, m.State);
259
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
27 }
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
28 }
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
29 }
7d52dc684bbd PollingComponent: implemented correct stopping
cin
parents:
diff changeset
30 }