diff Implab.Test/Mock/MockRunnableComponent.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
children 8200ab154c8a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Implab.Test/Mock/MockRunnableComponent.cs	Tue Oct 18 17:49:54 2016 +0300
@@ -0,0 +1,38 @@
+using System;
+using Implab.Components;
+
+namespace Implab.Test.Mock {
+    class MockRunnableComponent : RunnableComponent {
+        public MockRunnableComponent(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 ? Safe.Run(MockStart).Chain(base.OnStart) : Safe.Run(base.OnStart);
+        }
+
+        protected override IPromise OnStop() {
+            return MockStop != null ? Safe.Run(MockStop).Chain(base.OnStop) : Safe.Run(base.OnStop);
+        }
+
+        protected override void OnInitialize() {
+            if (MockInit != null)
+                MockInit();
+        }
+    }
+}
+