Skip to content

Commit

Permalink
Cleanup (#1966)
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r authored Jul 30, 2023
1 parent 630800c commit 23c7dcd
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 28 deletions.
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<Nullable>enable</Nullable>
<PackageTags>HealthCheck;HealthChecks;Health</PackageTags>
<NoWarn>$(NoWarn);1591;IDISP013</NoWarn> <!--TODO: temporary solution-->
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
</PropertyGroup>

<PropertyGroup Condition="$(MSBuildProjectName.EndsWith('.Tests'))">
Expand Down
10 changes: 5 additions & 5 deletions samples/HealthChecks.UI.Branding/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public static IHealthChecksBuilder AddPrometheusGatewayPublisher(
string? instance = null)
{
builder.Services
.AddHttpClient();

builder.Services
.AddHttpClient()
.AddSingleton<IHealthCheckPublisher>(sp => new PrometheusGatewayPublisher(() => sp.GetRequiredService<IHttpClientFactory>().CreateClient(), endpoint, job, instance));

return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public static IHealthChecksBuilder AddSignalRHub(
IEnumerable<string>? tags = default,
TimeSpan? timeout = default)
{
Func<HubConnection> hubConnectionBuilder = () =>
HubConnection hubConnectionBuilder() =>
new HubConnectionBuilder()
.WithUrl(url)
.Build();

return builder.Add(
new HealthCheckRegistration(
name ?? NAME,
sp => new SignalRHealthCheck(hubConnectionBuilder),
_ => new SignalRHealthCheck(hubConnectionBuilder),
failureStatus,
tags,
timeout));
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/HealthChecks.UI/Core/UIResourceMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IHealthCheckPublisher>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IHealthCheckPublisher>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IOptions<HealthCheckServiceOptions>>();
Expand All @@ -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<SqlConnection> beforeOpen = connection =>
void beforeOpen(SqlConnection connection)
{
invoked = true;
connection.ConnectionString.ShouldBe(connectionstring);
};
}
services.AddHealthChecks()
.AddSqlServer(connectionstring, configure: beforeOpen);

Expand All @@ -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<IOptions<HealthCheckServiceOptions>>();
Expand All @@ -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(_ =>
{
Expand Down

0 comments on commit 23c7dcd

Please sign in to comment.