RunnableComponentTests.cs
30 lines
| 898 B
| text/x-csharp
|
CSharpLexer
/ Implab.Test / RunnableComponentTests.cs
cin
|
r259 | using System; | ||
using System.Threading; | ||||
using System.Threading.Tasks; | ||||
using Implab.Components; | ||||
using Xunit; | ||||
cin
|
r260 | namespace Implab.Test { | ||
cin
|
r259 | |||
cin
|
r260 | public class RunnableComponentTests { | ||
cin
|
r259 | [Fact] | ||
cin
|
r260 | public async Task Test1() { | ||
cin
|
r259 | |||
cin
|
r260 | using (var m = new MockPollComponent(true)) { | ||
m.StartWorker = async (ct) => await Task.Yield(); | ||||
m.StopWorker = async (ct) => await Task.Yield(); | ||||
cin
|
r259 | |||
cin
|
r260 | Assert.Equal(ExecutionState.Ready, m.State); | ||
Assert.NotNull(m.Completion); | ||||
cin
|
r259 | |||
cin
|
r260 | m.Start(CancellationToken.None); | ||
await m.Completion; | ||||
Assert.Equal(ExecutionState.Running, m.State); | ||||
cin
|
r259 | |||
cin
|
r260 | m.Stop(CancellationToken.None); | ||
await m.Completion; | ||||
Assert.Equal(ExecutionState.Stopped, m.State); | ||||
cin
|
r259 | } | ||
} | ||||
} | ||||
} | ||||