Esempio n. 1
0
        public async void Tick_ShouldCallHealthCheck_WhenItNeedsToRun(IHealthCheck check)
        {
            check.NeedsToRun.Returns(true);
            HealthMonitor.AddCheck(check).Should().BeTrue();

            HealthMonitor.Tick();

            // wait for the queue to run
            await Task.Delay(5);

            check.Received(1).RunAsync();
        }
        public async Task GivenTheHealthCheckCache_WhenCancellationIsRequested_ThenWeDoNotThrowAndReturnLastHealthCheckResult()
        {
            // Trigger a health check so as to populate lastResult
            await _cahcedHealthCheck.CheckHealthAsync(_context, CancellationToken.None);

            var ctSource = new CancellationTokenSource();

            ctSource.Cancel();

            HealthCheckResult result = await _cahcedHealthCheck.CheckHealthAsync(_context, ctSource.Token);

            // Confirm we only called CheckHealthAsync once.
            await _healthCheck.Received(1).CheckHealthAsync(Arg.Any <HealthCheckContext>(), Arg.Any <CancellationToken>());

            Assert.Equal(HealthStatus.Healthy, result.Status);
        }