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