annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
203
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
1 using System;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
2 using Implab.Components;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
3
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
4 namespace Implab.Test.Mock {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
5 class MockRunnableComponent : RunnableComponent {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
6 public MockRunnableComponent(bool initialized) : base(initialized) {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
7 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
8
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
9 public Action MockInit {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
10 get;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
11 set;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
12 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
13
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
14 public Func<IPromise> MockStart {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
15 get;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
16 set;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
17 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
18
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
19 public Func<IPromise> MockStop {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
20 get;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
21 set;
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
22 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
23
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
24 protected override IPromise OnStart() {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
25 return MockStart != null ? Safe.Run(MockStart).Chain(base.OnStart) : Safe.Run(base.OnStart);
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
26 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
27
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
28 protected override IPromise OnStop() {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
29 return MockStop != null ? Safe.Run(MockStop).Chain(base.OnStop) : Safe.Run(base.OnStop);
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
30 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
31
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
32 protected override void OnInitialize() {
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
33 if (MockInit != null)
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
34 MockInit();
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
35 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
36 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
37 }
4d9830a9bbb8 Added 'Fail' method to RunnableComponent which allows component to move from
cin
parents:
diff changeset
38