view Implab.Test/RunnableComponentTests.cs @ 260:547a2fc0d93e v3 v3.0.6

minor fixes
author cin
date Fri, 13 Apr 2018 19:14:59 +0300
parents 7d52dc684bbd
children f1696cdc3d7a
line wrap: on
line source

using System;
using System.Threading;
using System.Threading.Tasks;
using Implab.Components;
using Xunit;

namespace Implab.Test {

    public class RunnableComponentTests {
        [Fact]
        public async Task Test1() {

            using (var m = new MockPollComponent(true)) {
                m.StartWorker = async (ct) => await Task.Yield();
                m.StopWorker = async (ct) => await Task.Yield();

                Assert.Equal(ExecutionState.Ready, m.State);
                Assert.NotNull(m.Completion);
                
                m.Start(CancellationToken.None);
                await m.Completion;
                Assert.Equal(ExecutionState.Running, m.State);

                m.Stop(CancellationToken.None);
                await m.Completion;
                Assert.Equal(ExecutionState.Stopped, m.State);
            }
        }
    }
}