Ejemplo n.º 1
0
        public void Start_ArgsNull_Should_Ex()
        {
            using (var simpleDaemon = new SimpleDaemon())
            {
                var config   = TimeSpan.FromMilliseconds(50);
                var mockTask = MockTask.Create();

                AssertHelper.ShouldAsyncThrows <ArgumentException>(() => simpleDaemon.Start(TimeSpan.Zero, mockTask.MockAction, false));
                AssertHelper.ShouldAsyncThrows <ArgumentNullException>(() => simpleDaemon.Start(config, null, false));
            }
        }
Ejemplo n.º 2
0
        public async Task Start_NotStop_Should_Running()
        {
            using (var simpleDaemon = new SimpleDaemon())
            {
                var config = TimeSpan.FromMilliseconds(10);

                var mockTask    = MockTask.Create();
                var startResult = await simpleDaemon.Start(config, mockTask.MockAction, false).ConfigureAwait(false);

                startResult.Success.ShouldTrue();
                startResult.Message.Log();

                var lastInvokeCount = 0;
                for (int i = 0; i < 5; i++)
                {
                    await Task.Delay(20).ConfigureAwait(false);

                    var isRunning = mockTask.InvokeCount >= lastInvokeCount;
                    string.Format("Running Invoked: {0}", mockTask.InvokeCount).Log();
                    isRunning.ShouldTrue();
                    lastInvokeCount = mockTask.InvokeCount;
                }

                var stopResult = await simpleDaemon.Stop();

                stopResult.Success.ShouldTrue();
                stopResult.Message.Log();
            }
        }
Ejemplo n.º 3
0
        public async Task Start_SecondTime_Should_Fail()
        {
            using (var simpleDaemon = new SimpleDaemon())
            {
                var config   = TimeSpan.FromMilliseconds(50);
                var mockTask = MockTask.Create();

                var startResult = await simpleDaemon.Start(config, mockTask.MockAction, false).ConfigureAwait(false);

                startResult.Success.ShouldTrue();
                startResult.Message.Log();

                var startResult2 = await simpleDaemon.Start(config, mockTask.MockAction, false).ConfigureAwait(false);

                startResult2.Success.ShouldFalse();
                startResult2.Message.Log();
            }
        }