From 23c7dcdad9a81e15c4b72ab0a417c3339220d492 Mon Sep 17 00:00:00 2001 From: Ivan Maximov Date: Sun, 30 Jul 2023 20:51:25 +0300 Subject: [PATCH] Cleanup (#1966) --- Directory.Build.props | 2 ++ samples/HealthChecks.UI.Branding/Startup.cs | 10 +++++----- ...heusGatewayHealthCheckBuilderExtensions.cs | 4 +--- .../SignalRHealthCheckBuilderExtensions.cs | 6 +++--- src/HealthChecks.UI/Core/UIResourceMapper.cs | 2 +- .../DependencyInjection/RegistrationTests.cs | 6 +++--- .../DependencyInjection/RegistrationTests.cs | 8 ++++---- .../DependencyInjection/RegistrationTests.cs | 20 ++++++++++--------- 8 files changed, 30 insertions(+), 28 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 68c67c2f64..1c9eb33bd6 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -23,6 +23,8 @@ enable HealthCheck;HealthChecks;Health $(NoWarn);1591;IDISP013 + false + true diff --git a/samples/HealthChecks.UI.Branding/Startup.cs b/samples/HealthChecks.UI.Branding/Startup.cs index 274213a0c6..4a76026c52 100644 --- a/samples/HealthChecks.UI.Branding/Startup.cs +++ b/samples/HealthChecks.UI.Branding/Startup.cs @@ -11,7 +11,6 @@ public class Startup // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { - //To add authentication and authorization using demo identityserver uncomment AddDemoAuthentication and RequireAuthorization lines services @@ -44,10 +43,11 @@ public void ConfigureServices(IServiceCollection services) //Webhook endpoint with default failure and description messages - setup.AddWebhookNotification("webhook1", uri: "https://healthchecks.requestcatcher.com/", - payload: "{ message: \"Webhook report for [[LIVENESS]]: [[FAILURE]] - Description: [[DESCRIPTIONS]]\"}", - restorePayload: "{ message: \"[[LIVENESS]] is back to life\"}"); - + setup.AddWebhookNotification( + name: "webhook1", + uri: "https://healthchecks.requestcatcher.com/", + payload: "{ message: \"Webhook report for [[LIVENESS]]: [[FAILURE]] - Description: [[DESCRIPTIONS]]\"}", + restorePayload: "{ message: \"[[LIVENESS]] is back to life\"}"); }).AddInMemoryStorage() .Services .AddControllers(); diff --git a/src/HealthChecks.Publisher.Prometheus/DependencyInjection/PrometheusGatewayHealthCheckBuilderExtensions.cs b/src/HealthChecks.Publisher.Prometheus/DependencyInjection/PrometheusGatewayHealthCheckBuilderExtensions.cs index fa43ecf2e5..3963fd79ee 100644 --- a/src/HealthChecks.Publisher.Prometheus/DependencyInjection/PrometheusGatewayHealthCheckBuilderExtensions.cs +++ b/src/HealthChecks.Publisher.Prometheus/DependencyInjection/PrometheusGatewayHealthCheckBuilderExtensions.cs @@ -25,9 +25,7 @@ public static IHealthChecksBuilder AddPrometheusGatewayPublisher( string? instance = null) { builder.Services - .AddHttpClient(); - - builder.Services + .AddHttpClient() .AddSingleton(sp => new PrometheusGatewayPublisher(() => sp.GetRequiredService().CreateClient(), endpoint, job, instance)); return builder; diff --git a/src/HealthChecks.SignalR/DependencyInjection/SignalRHealthCheckBuilderExtensions.cs b/src/HealthChecks.SignalR/DependencyInjection/SignalRHealthCheckBuilderExtensions.cs index a21baa84df..33711feb25 100644 --- a/src/HealthChecks.SignalR/DependencyInjection/SignalRHealthCheckBuilderExtensions.cs +++ b/src/HealthChecks.SignalR/DependencyInjection/SignalRHealthCheckBuilderExtensions.cs @@ -32,7 +32,7 @@ public static IHealthChecksBuilder AddSignalRHub( IEnumerable? tags = default, TimeSpan? timeout = default) { - Func hubConnectionBuilder = () => + HubConnection hubConnectionBuilder() => new HubConnectionBuilder() .WithUrl(url) .Build(); @@ -40,7 +40,7 @@ public static IHealthChecksBuilder AddSignalRHub( return builder.Add( new HealthCheckRegistration( name ?? NAME, - sp => new SignalRHealthCheck(hubConnectionBuilder), + _ => new SignalRHealthCheck(hubConnectionBuilder), failureStatus, tags, timeout)); @@ -70,7 +70,7 @@ public static IHealthChecksBuilder AddSignalRHub( return builder.Add( new HealthCheckRegistration( name ?? NAME, - sp => new SignalRHealthCheck(hubConnectionBuilder), + _ => new SignalRHealthCheck(hubConnectionBuilder), failureStatus, tags, timeout)); diff --git a/src/HealthChecks.UI/Core/UIResourceMapper.cs b/src/HealthChecks.UI/Core/UIResourceMapper.cs index b0f2aeb060..9b2ec80432 100644 --- a/src/HealthChecks.UI/Core/UIResourceMapper.cs +++ b/src/HealthChecks.UI/Core/UIResourceMapper.cs @@ -38,7 +38,7 @@ public void Map(IApplicationBuilder app, Options options) context.Response.OnStarting(() => { // prevent user add previous middleware in the pipeline - // and set the cache-control + // and set the cache-control if (!context.Response.Headers.ContainsKey("Cache-Control")) { diff --git a/test/HealthChecks.Publisher.Datadog.Tests/DependencyInjection/RegistrationTests.cs b/test/HealthChecks.Publisher.Datadog.Tests/DependencyInjection/RegistrationTests.cs index a8fac7b943..6ae738363b 100644 --- a/test/HealthChecks.Publisher.Datadog.Tests/DependencyInjection/RegistrationTests.cs +++ b/test/HealthChecks.Publisher.Datadog.Tests/DependencyInjection/RegistrationTests.cs @@ -5,10 +5,10 @@ public class datadog_publisher_registration_should [Fact] public void add_healthcheck_when_properly_configured() { - var services = new ServiceCollection(); - services + var services = new ServiceCollection() .AddHealthChecks() - .AddDatadogPublisher(serviceCheckName: "serviceCheckName", datadogAgentName: "127.0.0.1"); + .AddDatadogPublisher(serviceCheckName: "serviceCheckName", datadogAgentName: "127.0.0.1") + .Services; using var serviceProvider = services.BuildServiceProvider(); var publisher = serviceProvider.GetService(); diff --git a/test/HealthChecks.Publisher.Prometheus.Tests/DependencyInjection/RegistrationTests.cs b/test/HealthChecks.Publisher.Prometheus.Tests/DependencyInjection/RegistrationTests.cs index ee11b50a2e..a56696f3a4 100644 --- a/test/HealthChecks.Publisher.Prometheus.Tests/DependencyInjection/RegistrationTests.cs +++ b/test/HealthChecks.Publisher.Prometheus.Tests/DependencyInjection/RegistrationTests.cs @@ -3,13 +3,13 @@ namespace HealthChecks.Publisher.ApplicationInsights.Tests.DependencyInjection; public class prometheus_publisher_registration_should { [Fact] - [System.Obsolete] + [Obsolete("AddPrometheusGatewayPublisher is obsolete")] public void add_healthcheck_when_properly_configured() { - var services = new ServiceCollection(); - services + var services = new ServiceCollection() .AddHealthChecks() - .AddPrometheusGatewayPublisher("http://endpoint.com", "job_name"); + .AddPrometheusGatewayPublisher("http://endpoint.com", "job_name") + .Services; using var serviceProvider = services.BuildServiceProvider(); var publisher = serviceProvider.GetService(); diff --git a/test/HealthChecks.SqlServer.Tests/DependencyInjection/RegistrationTests.cs b/test/HealthChecks.SqlServer.Tests/DependencyInjection/RegistrationTests.cs index 4c10b4be68..1d4eb0af86 100644 --- a/test/HealthChecks.SqlServer.Tests/DependencyInjection/RegistrationTests.cs +++ b/test/HealthChecks.SqlServer.Tests/DependencyInjection/RegistrationTests.cs @@ -7,9 +7,10 @@ public class sql_server_registration_should [Fact] public void add_health_check_when_properly_configured() { - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddSqlServer("connectionstring"); + var services = new ServiceCollection() + .AddHealthChecks() + .AddSqlServer("connectionstring") + .Services; using var serviceProvider = services.BuildServiceProvider(); var options = serviceProvider.GetRequiredService>(); @@ -27,11 +28,11 @@ public void invoke_beforeOpen_when_defined() var services = new ServiceCollection(); bool invoked = false; const string connectionstring = "Server=(local);Database=foo;User Id=bar;Password=baz;Connection Timeout=1"; - Action beforeOpen = connection => + void beforeOpen(SqlConnection connection) { invoked = true; connection.ConnectionString.ShouldBe(connectionstring); - }; + } services.AddHealthChecks() .AddSqlServer(connectionstring, configure: beforeOpen); @@ -48,9 +49,10 @@ public void invoke_beforeOpen_when_defined() [Fact] public void add_named_health_check_when_properly_configured() { - var services = new ServiceCollection(); - services.AddHealthChecks() - .AddSqlServer("connectionstring", name: "my-sql-server-1"); + var services = new ServiceCollection() + .AddHealthChecks() + .AddSqlServer("connectionstring", name: "my-sql-server-1") + .Services; using var serviceProvider = services.BuildServiceProvider(); var options = serviceProvider.GetRequiredService>(); @@ -66,7 +68,7 @@ public void add_named_health_check_when_properly_configured() public void add_health_check_with_connection_string_factory_when_properly_configured() { var services = new ServiceCollection(); - var factoryCalled = false; + bool factoryCalled = false; services.AddHealthChecks() .AddSqlServer(_ => {