Skip to content

Commit

Permalink
Fixed Sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasArdal committed Jan 15, 2024
1 parent ffbad77 commit bd098b9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
17 changes: 8 additions & 9 deletions src/Elmah.Io.Umbraco/ElmahIoNotificationMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ namespace Elmah.Io.Umbraco
[HealthCheckNotificationMethod("elmah.io")]
public class ElmahIoNotificationMethod : NotificationMethodBase
{
internal static string _assemblyVersion = typeof(ElmahIoNotificationMethod).Assembly.GetName().Version.ToString();
internal static string _umbracoAssemblyVersion = typeof(NotificationMethodBase).Assembly.GetName().Version.ToString();
private static string _assemblyVersion = typeof(ElmahIoNotificationMethod).Assembly.GetName().Version.ToString();
private static string _umbracoAssemblyVersion = typeof(NotificationMethodBase).Assembly.GetName().Version.ToString();
internal IHeartbeatsClient heartbeats;

private string apiKey;
private string logId;
private string heartbeatId;
private readonly string apiKey;
private readonly string logId;
private readonly string heartbeatId;

/// <summary>
/// Create a new instance of the notification method. This constructor should not be called manually but invoked
Expand All @@ -42,7 +42,6 @@ public ElmahIoNotificationMethod(IOptionsMonitor<HealthChecksSettings> healthChe
if (string.IsNullOrWhiteSpace(apiKey) || string.IsNullOrWhiteSpace(logId) || string.IsNullOrWhiteSpace(heartbeatId))
{
Enabled = false;
return;
}
}

Expand All @@ -52,7 +51,7 @@ public ElmahIoNotificationMethod(IOptionsMonitor<HealthChecksSettings> healthChe
/// </summary>
public override async Task SendAsync(HealthCheckResults results)
{
if (ShouldSend(results) == false)
if (!ShouldSend(results))
{
return;
}
Expand Down Expand Up @@ -82,11 +81,11 @@ public override async Task SendAsync(HealthCheckResults results)
});
}

private string UserAgent()
private static string UserAgent()
{
return new StringBuilder()
.Append(new ProductInfoHeaderValue(new ProductHeaderValue("Elmah.Io.Umbraco", _assemblyVersion)).ToString())
.Append(" ")
.Append(' ')
.Append(new ProductInfoHeaderValue(new ProductHeaderValue("Umbraco.Cms", _umbracoAssemblyVersion)).ToString())
.ToString();
}
Expand Down
32 changes: 18 additions & 14 deletions test/Elmah.Io.Umbraco.Test/ElmahIoNotificationMethodTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,35 @@ public class ElmahIoNotificationMethodTest
public void SetUp()
{
var options = Substitute.For<IOptionsMonitor<HealthChecksSettings>>();
var settings = new HealthChecksSettings();
settings.Notification = new HealthChecksNotificationSettings
var settings = new HealthChecksSettings
{
Enabled = true,
NotificationMethods = new Dictionary<string, HealthChecksNotificationMethodSettings>
Notification = new HealthChecksNotificationSettings
{
Enabled = true,
NotificationMethods = new Dictionary<string, HealthChecksNotificationMethodSettings>
{
"elmah.io", new HealthChecksNotificationMethodSettings
{
Verbosity = HealthCheckNotificationVerbosity.Summary,
Enabled = true,
Settings = new Dictionary<string, string>
"elmah.io", new HealthChecksNotificationMethodSettings
{
{ "apiKey", "API_KEY" },
{ "logId", "LOG_ID" },
{ "heartbeatId", "HEARTBEAT_ID" }
Verbosity = HealthCheckNotificationVerbosity.Summary,
Enabled = true,
Settings = new Dictionary<string, string>
{
{ "apiKey", "API_KEY" },
{ "logId", "LOG_ID" },
{ "heartbeatId", "HEARTBEAT_ID" }
}
}
}
}
}
};
options.CurrentValue.Returns(settings);
heartbeatsClient = Substitute.For<IHeartbeatsClient>();
sut = new ElmahIoNotificationMethod(options);
sut.heartbeats = heartbeatsClient;
sut = new ElmahIoNotificationMethod(options)
{
heartbeats = heartbeatsClient
};
}

[Test]
Expand Down Expand Up @@ -88,7 +92,7 @@ public override Task<IEnumerable<HealthCheckStatus>> GetStatus()
{
return Task.FromResult<IEnumerable<HealthCheckStatus>>(new List<HealthCheckStatus>
{
new HealthCheckStatus("Oh no")
new("Oh no")
{
ResultType = StatusResultType.Error
}
Expand Down

0 comments on commit bd098b9

Please sign in to comment.