comparison 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
comparison
equal deleted inserted replaced
259:7d52dc684bbd 260:547a2fc0d93e
2 using System.Threading; 2 using System.Threading;
3 using System.Threading.Tasks; 3 using System.Threading.Tasks;
4 using Implab.Components; 4 using Implab.Components;
5 using Xunit; 5 using Xunit;
6 6
7 namespace Implab.Test 7 namespace Implab.Test {
8 {
9 class TimeLog : PollingComponent {
10 public TimeLog() : base(true) {
11 }
12 8
13 protected override Task Poll(CancellationToken ct) { 9 public class RunnableComponentTests {
14 Console.WriteLine("Poll"); 10 [Fact]
15 return Task.CompletedTask; 11 public async Task Test1() {
16 }
17 }
18 12
19 public class UnitTest1 13 using (var m = new MockPollComponent(true)) {
20 { 14 m.StartWorker = async (ct) => await Task.Yield();
21 [Fact] 15 m.StopWorker = async (ct) => await Task.Yield();
22 public async Task Test1()
23 {
24 16
25 using(var tl = new TimeLog()) { 17 Assert.Equal(ExecutionState.Ready, m.State);
26 tl.StateChanged += (self, args) => Console.WriteLine("{0}", args.State); 18 Assert.NotNull(m.Completion);
27 tl.Delay = 1000; 19
28 tl.Interval = 500; 20 m.Start(CancellationToken.None);
21 await m.Completion;
22 Assert.Equal(ExecutionState.Running, m.State);
29 23
30 24 m.Stop(CancellationToken.None);
31 tl.Start(CancellationToken.None); 25 await m.Completion;
32 await tl.Completion; 26 Assert.Equal(ExecutionState.Stopped, m.State);
33
34 await Task.Delay(2000);
35
36 tl.Stop(CancellationToken.None);
37 await tl.Completion;
38 await Task.Delay(3000);
39 } 27 }
40 } 28 }
41 } 29 }
42 } 30 }