diff Implab.Test/RunnableComponentTests.cs @ 203:4d9830a9bbb8 v2

Added 'Fail' method to RunnableComponent which allows component to move from Running to Failed state. Added PollingComponent a timer based runnable component More tests Added FailPromise a thin class to wrap exceptions Fixed error handling in SuccessPromise classes.
author cin
date Tue, 18 Oct 2016 17:49:54 +0300
parents d45bdf510514
children 8200ab154c8a
line wrap: on
line diff
--- a/Implab.Test/RunnableComponentTests.cs	Tue Oct 18 01:03:49 2016 +0300
+++ b/Implab.Test/RunnableComponentTests.cs	Tue Oct 18 17:49:54 2016 +0300
@@ -3,6 +3,7 @@
 using System.Threading;
 using Implab.Parallels;
 using Implab.Components;
+using Implab.Test.Mock;
 
 #if MONO
 
@@ -30,42 +31,11 @@
             }
         }
 
-        class Runnable : RunnableComponent {
-            public Runnable(bool initialized) : base(initialized) {
-            }
-                
-            public Action MockInit {
-                get;
-                set;
-            }
 
-            public Func<IPromise> MockStart {
-                get;
-                set;
-            }
-
-            public Func<IPromise> MockStop {
-                get;
-                set;
-            }
-
-            protected override IPromise OnStart() {
-                return MockStart != null ? MockStart() : base.OnStart();
-            }
-
-            protected override IPromise OnStop() {
-                return MockStop != null ? MockStop() : base.OnStart();
-            }
-
-            protected override void OnInitialize() {
-                if (MockInit != null)
-                    MockInit();
-            }
-        }
 
         [TestMethod]
         public void NormalFlowTest() {
-            var comp = new Runnable(false);
+            var comp = new MockRunnableComponent(false);
 
             Assert.AreEqual(ExecutionState.Created, comp.State);
 
@@ -85,7 +55,7 @@
 
         [TestMethod]
         public void InitFailTest() {
-            var comp = new Runnable(false) {
+            var comp = new MockRunnableComponent(false) {
                 MockInit = () => {
                     throw new Exception("BAD");
                 }
@@ -110,7 +80,7 @@
         [TestMethod]
         public void DisposedTest() {
 
-            var comp = new Runnable(false);
+            var comp = new MockRunnableComponent(false);
             comp.Dispose();
 
             ShouldThrow(() => comp.Start());
@@ -122,7 +92,7 @@
 
         [TestMethod]
         public void StartCancelTest() {
-            var comp = new Runnable(true) {
+            var comp = new MockRunnableComponent(true) {
                 MockStart = () => PromiseHelper.Sleep(100000, 0)
             };
 
@@ -140,7 +110,7 @@
         [TestMethod]
         public void StartStopTest() {
             var stop = new Signal();
-            var comp = new Runnable(true) {
+            var comp = new MockRunnableComponent(true) {
                 MockStart = () => PromiseHelper.Sleep(100000, 0),
                 MockStop = () => AsyncPool.RunThread(stop.Wait)
             };
@@ -160,7 +130,7 @@
 
         [TestMethod]
         public void StartStopFailTest() {
-            var comp = new Runnable(true) {
+            var comp = new MockRunnableComponent(true) {
                 MockStart = () => PromiseHelper.Sleep(100000, 0).Then(null,null,x => { throw new Exception("I'm dead"); })
             };
 
@@ -175,7 +145,7 @@
 
         [TestMethod]
         public void StopCancelTest() {
-            var comp = new Runnable(true) {
+            var comp = new MockRunnableComponent(true) {
                 MockStop = () => PromiseHelper.Sleep(100000, 0)
             };