diff 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
line wrap: on
line diff
--- a/Implab.Test/RunnableComponentTests.cs	Fri Apr 13 03:57:39 2018 +0300
+++ b/Implab.Test/RunnableComponentTests.cs	Fri Apr 13 19:14:59 2018 +0300
@@ -4,38 +4,26 @@
 using Implab.Components;
 using Xunit;
 
-namespace Implab.Test
-{
-    class TimeLog : PollingComponent {
-        public TimeLog() : base(true) {
-        }
+namespace Implab.Test {
 
-        protected override Task Poll(CancellationToken ct) {
-            Console.WriteLine("Poll");
-            return Task.CompletedTask;
-        }
-    }
-
-    public class UnitTest1
-    {
+    public class RunnableComponentTests {
         [Fact]
-        public async Task Test1()
-        {
+        public async Task Test1() {
 
-            using(var  tl = new TimeLog()) {
-                tl.StateChanged += (self, args) => Console.WriteLine("{0}", args.State);
-                tl.Delay = 1000;
-                tl.Interval = 500;
+            using (var m = new MockPollComponent(true)) {
+                m.StartWorker = async (ct) => await Task.Yield();
+                m.StopWorker = async (ct) => await Task.Yield();
 
+                Assert.Equal(ExecutionState.Ready, m.State);
+                Assert.NotNull(m.Completion);
                 
-                tl.Start(CancellationToken.None);
-                await tl.Completion;
+                m.Start(CancellationToken.None);
+                await m.Completion;
+                Assert.Equal(ExecutionState.Running, m.State);
 
-                await Task.Delay(2000);
-
-                tl.Stop(CancellationToken.None);
-                await tl.Completion;
-                await Task.Delay(3000);
+                m.Stop(CancellationToken.None);
+                await m.Completion;
+                Assert.Equal(ExecutionState.Stopped, m.State);
             }
         }
     }