view Implab.Test/Mock/MockRunnableComponent.cs @ 209:a867536c68fc v2

Bound promise to CancellationToken Added new states to ExecutionSate enum. Added Safe.Guard() method to handle cleanup of the result of the promise
author cin
date Wed, 16 Nov 2016 03:06:08 +0300
parents 7d07503621fe
children
line wrap: on
line source

using System;
using Implab.Components;

namespace Implab.Test.Mock {
    class MockRunnableComponent : RunnableComponent {
        public MockRunnableComponent(bool initialized) : base(initialized) {
        }

        public MockRunnableComponent(bool initialized, bool reusable) : base(initialized, reusable) {
        }

        public Action MockInit {
            get;
            set;
        }

        public Func<IPromise> MockStart {
            get;
            set;
        }

        public Func<IPromise> MockStop {
            get;
            set;
        }

        public Action<bool> MockDispose {
            get;
            set;
        }

        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();
        }

        protected override void Dispose(bool disposing) {
            if (MockDispose != null)
                MockDispose(disposing);
            base.Dispose(disposing);
        }
    }
}