Skip to content

Commit bd098b9

Browse files
committed
Fixed Sonar issues
1 parent ffbad77 commit bd098b9

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

Diff for: src/Elmah.Io.Umbraco/ElmahIoNotificationMethod.cs

+8-9
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ namespace Elmah.Io.Umbraco
1616
[HealthCheckNotificationMethod("elmah.io")]
1717
public class ElmahIoNotificationMethod : NotificationMethodBase
1818
{
19-
internal static string _assemblyVersion = typeof(ElmahIoNotificationMethod).Assembly.GetName().Version.ToString();
20-
internal static string _umbracoAssemblyVersion = typeof(NotificationMethodBase).Assembly.GetName().Version.ToString();
19+
private static string _assemblyVersion = typeof(ElmahIoNotificationMethod).Assembly.GetName().Version.ToString();
20+
private static string _umbracoAssemblyVersion = typeof(NotificationMethodBase).Assembly.GetName().Version.ToString();
2121
internal IHeartbeatsClient heartbeats;
2222

23-
private string apiKey;
24-
private string logId;
25-
private string heartbeatId;
23+
private readonly string apiKey;
24+
private readonly string logId;
25+
private readonly string heartbeatId;
2626

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

@@ -52,7 +51,7 @@ public ElmahIoNotificationMethod(IOptionsMonitor<HealthChecksSettings> healthChe
5251
/// </summary>
5352
public override async Task SendAsync(HealthCheckResults results)
5453
{
55-
if (ShouldSend(results) == false)
54+
if (!ShouldSend(results))
5655
{
5756
return;
5857
}
@@ -82,11 +81,11 @@ public override async Task SendAsync(HealthCheckResults results)
8281
});
8382
}
8483

85-
private string UserAgent()
84+
private static string UserAgent()
8685
{
8786
return new StringBuilder()
8887
.Append(new ProductInfoHeaderValue(new ProductHeaderValue("Elmah.Io.Umbraco", _assemblyVersion)).ToString())
89-
.Append(" ")
88+
.Append(' ')
9089
.Append(new ProductInfoHeaderValue(new ProductHeaderValue("Umbraco.Cms", _umbracoAssemblyVersion)).ToString())
9190
.ToString();
9291
}

Diff for: test/Elmah.Io.Umbraco.Test/ElmahIoNotificationMethodTest.cs

+18-14
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,35 @@ public class ElmahIoNotificationMethodTest
1818
public void SetUp()
1919
{
2020
var options = Substitute.For<IOptionsMonitor<HealthChecksSettings>>();
21-
var settings = new HealthChecksSettings();
22-
settings.Notification = new HealthChecksNotificationSettings
21+
var settings = new HealthChecksSettings
2322
{
24-
Enabled = true,
25-
NotificationMethods = new Dictionary<string, HealthChecksNotificationMethodSettings>
23+
Notification = new HealthChecksNotificationSettings
2624
{
25+
Enabled = true,
26+
NotificationMethods = new Dictionary<string, HealthChecksNotificationMethodSettings>
2727
{
28-
"elmah.io", new HealthChecksNotificationMethodSettings
2928
{
30-
Verbosity = HealthCheckNotificationVerbosity.Summary,
31-
Enabled = true,
32-
Settings = new Dictionary<string, string>
29+
"elmah.io", new HealthChecksNotificationMethodSettings
3330
{
34-
{ "apiKey", "API_KEY" },
35-
{ "logId", "LOG_ID" },
36-
{ "heartbeatId", "HEARTBEAT_ID" }
31+
Verbosity = HealthCheckNotificationVerbosity.Summary,
32+
Enabled = true,
33+
Settings = new Dictionary<string, string>
34+
{
35+
{ "apiKey", "API_KEY" },
36+
{ "logId", "LOG_ID" },
37+
{ "heartbeatId", "HEARTBEAT_ID" }
38+
}
3739
}
3840
}
3941
}
4042
}
4143
};
4244
options.CurrentValue.Returns(settings);
4345
heartbeatsClient = Substitute.For<IHeartbeatsClient>();
44-
sut = new ElmahIoNotificationMethod(options);
45-
sut.heartbeats = heartbeatsClient;
46+
sut = new ElmahIoNotificationMethod(options)
47+
{
48+
heartbeats = heartbeatsClient
49+
};
4650
}
4751

4852
[Test]
@@ -88,7 +92,7 @@ public override Task<IEnumerable<HealthCheckStatus>> GetStatus()
8892
{
8993
return Task.FromResult<IEnumerable<HealthCheckStatus>>(new List<HealthCheckStatus>
9094
{
91-
new HealthCheckStatus("Oh no")
95+
new("Oh no")
9296
{
9397
ResultType = StatusResultType.Error
9498
}

0 commit comments

Comments
 (0)