public async Task CheckHealth_AlwaysReturnsHealthy() { var ctx = new HealthCheckContext(); var appHealthCheck = new ApplicationHealthCheck(); var result = await appHealthCheck.CheckHealthAsync(ctx, CancellationToken.None); Assert.Equal(HealthStatus.Healthy, result.Status); }
static void Main(string[] args) { Log.Debug("Start Application"); if (HealthChecksSection == null || HealthChecksSection.HealthChecks == null || HealthChecksSection.HealthChecks.Count == 0) { Log.Error(SystemConstants.MISSING_HEALTH_CHECK_SECTION); return; } if (args.Length == 0) { Console.WriteLine("Enter one of HealthChecksSection Names:"); foreach (object key in HealthChecksSection.HealthChecks) { var healthCheck = key as HealthCheck; Console.WriteLine($"\"{healthCheck.Name}\""); } } else if (args.Length > 1) { Console.WriteLine($"Expected only 1 argument but found {args.Length}"); } else { string healthCheckName = args[0]; Log.DebugFormat($"Run The Health Check: \"{args[0]}\""); try { HealthChecksSection config = HealthChecksSection.GetConfig(); IEnumerable <BoundsLimit> bounds = config.HealthChecks[healthCheckName].HealthCheckParameters.ReturnAll() .Select(boundsLimit => new BoundsLimit(boundsLimit.Name, boundsLimit.Type, boundsLimit.Value)); IKernel kernel = new BindKernelwithHealthChecks(new StandardKernel(new ServiceModule()), HealthChecksSection.HealthChecks).Bind(); ApplicationHealthCheck app = kernel.Get <ApplicationHealthCheck>(healthCheckName); if (app == null) { throw new ArgumentException($"{healthCheckName} is not a valid Health Check Name"); } HealthMonitorResult healthMonitorResult = app.DoHealthCheck(bounds); Log.DebugFormat(healthMonitorResult.ToString()); if (healthMonitorResult.IsSerious) { //SendNotification(kernel, healthMonitorResult, config.HealthChecks[healthCheckName]); Console.WriteLine(healthMonitorResult); } } catch (Exception e) { Log.Error(e); } finally { Log.DebugFormat($"Finished health check: {healthCheckName}"); } } }