MockRunnableComponent.cs
52 lines
| 1.3 KiB
| text/x-csharp
|
CSharpLexer
cin
|
r203 | using System; | ||
using Implab.Components; | ||||
namespace Implab.Test.Mock { | ||||
class MockRunnableComponent : RunnableComponent { | ||||
public MockRunnableComponent(bool initialized) : base(initialized) { | ||||
} | ||||
cin
|
r205 | public MockRunnableComponent(bool initialized, bool reusable) : base(initialized, reusable) { | ||
} | ||||
cin
|
r203 | public Action MockInit { | ||
get; | ||||
set; | ||||
} | ||||
public Func<IPromise> MockStart { | ||||
get; | ||||
set; | ||||
} | ||||
public Func<IPromise> MockStop { | ||||
get; | ||||
set; | ||||
} | ||||
cin
|
r205 | public Action<bool, Exception> MockDispose { | ||
get; | ||||
set; | ||||
} | ||||
cin
|
r203 | 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(); | ||||
} | ||||
cin
|
r205 | |||
protected override void Dispose(bool disposing, Exception lastError) { | ||||
if (MockDispose != null) | ||||
MockDispose(disposing, lastError); | ||||
base.Dispose(disposing, lastError); | ||||
} | ||||
cin
|
r203 | } | ||
} | ||||