comparison Implab.Test/Mock/MockPollingComponent.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
comparison
equal deleted inserted replaced
202:2651cb9a4250 203:4d9830a9bbb8
1 using System;
2 using Implab.Components;
3
4 namespace Implab.Test.Mock {
5 class MockPollingComponent : PollingComponent {
6 public MockPollingComponent(TimeSpan interval, Func<Func<ICancellationToken, IPromise>, IPromise> dispatcher, bool initialized) : base(interval, dispatcher, initialized) {
7 }
8
9 public Action MockInit {
10 get;
11 set;
12 }
13
14 public Action<Exception> MockOnError {
15 get;
16 set;
17 }
18
19 public Action<Exception> MockOnCancel {
20 get;
21 set;
22 }
23
24 public Func<IPromise> MockStart {
25 get;
26 set;
27 }
28
29 public Func<IPromise> MockStop {
30 get;
31 set;
32 }
33
34 public Func<ICancellationToken, IPromise> MockTick {
35 get;
36 set;
37 }
38
39 protected override IPromise OnStart() {
40 return MockStart != null ? Safe.Run(MockStart).Chain(base.OnStart) : Safe.Run(base.OnStart);
41 }
42
43 protected override IPromise OnStop() {
44 return MockStop != null ? Safe.Run(MockStop).Chain(base.OnStop) : Safe.Run(base.OnStop);
45 }
46
47 protected override void OnInitialize() {
48 if (MockInit != null)
49 MockInit();
50 }
51
52 protected override IPromise OnTick(ICancellationToken cancellationToken) {
53 return MockTick != null ? Safe.Run(() => MockTick(cancellationToken)) : Promise.SUCCESS;
54 }
55
56 protected override void OnTickCancel(Exception error) {
57 if (MockOnCancel != null)
58 MockOnCancel(error);
59 }
60
61 protected override void OnTickError(Exception error) {
62 if (MockOnError != null)
63 MockOnError(error);
64 }
65
66 public void CallComponentFail(Exception error) {
67 Fail(error);
68 }
69 }
70 }
71