public async Task ShouldCancelTheTaskIfTheDeadManSwitchWasPausedAndResumedAndTheTaskTakesTooLong()
        {
            using (var cts = new CancellationTokenSource())
            {
                // Arrange
                double?pi = null, e = null;
                var    options = new DeadManSwitchOptions {
                    Timeout = TimeSpan.FromSeconds(2)
                };
                var workItems = WorkItems(
                    Work(
                        Pause(),
                        Sleep(TimeSpan.FromSeconds(3)),
                        Do(_ => pi = Math.PI),
                        Resume(),
                        Sleep(TimeSpan.FromSeconds(3)),
                        Do(_ => e = Math.E)
                        ),
                    Work(
                        Do(_ => _logger.LogInformation("Cancelling infinite worker")),
                        Do(_ => cts.Cancel())
                        )
                    );
                var worker = new ConfigurableDeadManSwitchInfiniteWorker(workItems);

                // Act
                await _runner.RunAsync(worker, options, cts.Token).ConfigureAwait(false);

                // Assert
                pi.Should().NotBeNull();
                e.Should().BeNull();
            }
        }
        public async Task ShouldBeAbleToRunCreatedInfiniteRunner()
        {
            using (var cts = new CancellationTokenSource())
            {
                // Arrange
                var serviceProvider = new ServiceCollection()
                                      .AddLogging(b => b.AddSerilog())
                                      .AddDeadManSwitch()
                                      .BuildServiceProvider();

                // Act
                var runner = serviceProvider.GetRequiredService <IInfiniteDeadManSwitchRunner>();

                double?pi     = null;
                var    worker = new ConfigurableDeadManSwitchInfiniteWorker(
                    new Func <IDeadManSwitch, CancellationToken, Task>[]
                {
                    (d, t) =>
                    {
                        pi = Math.PI;
                        return(Task.CompletedTask);
                    },
                    (d, t) =>
                    {
                        cts.Cancel();
                        return(Task.CompletedTask);
                    }
                }
                    );
                await runner.RunAsync(worker, new DeadManSwitchOptions(), cts.Token).ConfigureAwait(false);

                // Arrange
                runner.Should().NotBeNull();
                pi.Should().Be(Math.PI);
            }
        }