Skip to content

Commit 43a3c3c

Browse files
Fix Sonar code smell issues in test files (#93)
* Initial plan * Fix Sonar code smell issues Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> * Fix parameter order for Assert.IsGreaterThanOrEqualTo Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
1 parent 2548e9b commit 43a3c3c

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

test/DemaConsulting.BuildMark.Tests/GitHubRepoConnectorTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public async Task GitHubRepoConnector_GetBuildInformationAsync_WithMultipleVersi
136136

137137
// Should have changelog link
138138
Assert.IsNotNull(buildInfo.CompleteChangelogLink);
139-
Assert.IsTrue(buildInfo.CompleteChangelogLink.TargetUrl.Contains("v1.1.0...v2.0.0"));
139+
Assert.Contains("v1.1.0...v2.0.0", buildInfo.CompleteChangelogLink.TargetUrl);
140140
}
141141

142142
/// <summary>
@@ -160,15 +160,15 @@ public async Task GitHubRepoConnector_GetBuildInformationAsync_WithPullRequests_
160160
Merged: true,
161161
MergeCommitSha: "commit3",
162162
HeadRefOid: "feature-branch",
163-
Labels: new List<string> { "feature", "enhancement" }),
163+
Labels: ["feature", "enhancement"]),
164164
new MockPullRequest(
165165
Number: 100,
166166
Title: "Fix critical bug",
167167
Url: "https://github.com/test/repo/pull/100",
168168
Merged: true,
169169
MergeCommitSha: "commit2",
170170
HeadRefOid: "bugfix-branch",
171-
Labels: new List<string> { "bug" }))
171+
Labels: ["bug"]))
172172
.AddIssuesResponse()
173173
.AddTagsResponse(
174174
new MockTag("v1.1.0", "commit3"),
@@ -195,14 +195,14 @@ public async Task GitHubRepoConnector_GetBuildInformationAsync_WithPullRequests_
195195
// PRs without linked issues are treated based on their labels
196196
// PR 100 with "bug" label should be in bugs
197197
Assert.IsNotNull(buildInfo.Bugs);
198-
Assert.IsTrue(buildInfo.Bugs.Count >= 1, $"Expected at least 1 bug, got {buildInfo.Bugs.Count}");
198+
Assert.IsGreaterThanOrEqualTo(1, buildInfo.Bugs.Count, $"Expected at least 1 bug, got {buildInfo.Bugs.Count}");
199199
var bugPR = buildInfo.Bugs.FirstOrDefault(b => b.Index == 100);
200200
Assert.IsNotNull(bugPR, "PR 100 should be categorized as a bug");
201201
Assert.AreEqual("Fix critical bug", bugPR.Title);
202202

203203
// PR 101 with "feature" label should be in changes
204204
Assert.IsNotNull(buildInfo.Changes);
205-
Assert.IsTrue(buildInfo.Changes.Count >= 1, $"Expected at least 1 change, got {buildInfo.Changes.Count}");
205+
Assert.IsGreaterThanOrEqualTo(1, buildInfo.Changes.Count, $"Expected at least 1 change, got {buildInfo.Changes.Count}");
206206
var featurePR = buildInfo.Changes.FirstOrDefault(c => c.Index == 101);
207207
Assert.IsNotNull(featurePR, "PR 101 should be categorized as a change");
208208
Assert.AreEqual("Add new feature", featurePR.Title);
@@ -225,19 +225,19 @@ public async Task GitHubRepoConnector_GetBuildInformationAsync_WithOpenIssues_Id
225225
Title: "Known bug in feature X",
226226
Url: "https://github.com/test/repo/issues/201",
227227
State: "OPEN",
228-
Labels: new List<string> { "bug" }),
228+
Labels: ["bug"]),
229229
new MockIssue(
230230
Number: 202,
231231
Title: "Feature request for Y",
232232
Url: "https://github.com/test/repo/issues/202",
233233
State: "OPEN",
234-
Labels: new List<string> { "feature" }),
234+
Labels: ["feature"]),
235235
new MockIssue(
236236
Number: 203,
237237
Title: "Fixed bug",
238238
Url: "https://github.com/test/repo/issues/203",
239239
State: "CLOSED",
240-
Labels: new List<string> { "bug" }))
240+
Labels: ["bug"]))
241241
.AddTagsResponse(new MockTag("v1.0.0", "commit1"));
242242

243243
using var mockHttpClient = new HttpClient(mockHandler);
@@ -258,11 +258,11 @@ public async Task GitHubRepoConnector_GetBuildInformationAsync_WithOpenIssues_Id
258258
// Known issues are open issues that aren't linked to any changes in this release
259259
Assert.IsNotNull(buildInfo.KnownIssues);
260260
// Since we have no PRs, all open issues should be known issues
261-
Assert.IsTrue(buildInfo.KnownIssues.Count >= 1, $"Expected at least 1 known issue, got {buildInfo.KnownIssues.Count}");
261+
Assert.IsGreaterThanOrEqualTo(1, buildInfo.KnownIssues.Count, $"Expected at least 1 known issue, got {buildInfo.KnownIssues.Count}");
262262

263263
// Verify at least one known issue is present
264264
var knownIssueTitles = buildInfo.KnownIssues.Select(i => i.Title).ToList();
265-
Assert.IsTrue(knownIssueTitles.Any(t => t.Contains("Known bug") || t.Contains("Feature request")),
266-
"Should have at least one of the open issues as a known issue");
265+
var hasExpectedIssue = knownIssueTitles.Exists(t => t.Contains("Known bug") || t.Contains("Feature request"));
266+
Assert.IsTrue(hasExpectedIssue, "Should have at least one of the open issues as a known issue");
267267
}
268268
}

test/DemaConsulting.BuildMark.Tests/MockRepoConnectorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public async Task MockRepoConnector_GetBuildInformationAsync_CategorizesChangesC
147147
// - Issue #2 is a bug (type "bug")
148148
// - Issue #3 is documentation (type "documentation")
149149
var allItems = buildInfo.Changes.Concat(buildInfo.Bugs).ToList();
150-
Assert.IsTrue(allItems.Any(), "Should have at least one change");
150+
Assert.IsGreaterThan(0, allItems.Count, "Should have at least one change");
151151

152152
// Verify bugs only contain items with type "bug"
153153
foreach (var bug in buildInfo.Bugs)

test/DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/MockGitHubGraphQLHttpMessageHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public sealed class MockGitHubGraphQLHttpMessageHandler : HttpMessageHandler
9595
/// <summary>
9696
/// Dictionary mapping request patterns to response content.
9797
/// </summary>
98-
private readonly Dictionary<string, (string content, HttpStatusCode statusCode)> _responses = new();
98+
private readonly Dictionary<string, (string content, HttpStatusCode statusCode)> _responses = [];
9999

100100
/// <summary>
101101
/// Default response content to return when no pattern matches.
@@ -304,7 +304,7 @@ public MockGitHubGraphQLHttpMessageHandler AddPullRequestsResponse(
304304
var prNodes = string.Join(",\n ",
305305
pullRequests.Select(pr =>
306306
{
307-
var labelsJson = pr.Labels.Any()
307+
var labelsJson = pr.Labels.Count > 0
308308
? string.Join(",\n ", pr.Labels.Select(l => $@"{{ ""name"": ""{l}"" }}"))
309309
: string.Empty;
310310
@@ -364,7 +364,7 @@ public MockGitHubGraphQLHttpMessageHandler AddIssuesResponse(
364364
var issueNodes = string.Join(",\n ",
365365
issues.Select(issue =>
366366
{
367-
var labelsJson = issue.Labels.Any()
367+
var labelsJson = issue.Labels.Count > 0
368368
? string.Join(",\n ", issue.Labels.Select(l => $@"{{ ""name"": ""{l}"" }}"))
369369
: string.Empty;
370370

test/DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/MockableGitHubRepoConnector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal sealed class MockableGitHubRepoConnector : GitHubRepoConnector
3535
/// <summary>
3636
/// Mock responses for RunCommandAsync.
3737
/// </summary>
38-
private readonly Dictionary<string, string> _commandResponses = new();
38+
private readonly Dictionary<string, string> _commandResponses = [];
3939

4040
/// <summary>
4141
/// Mock HttpClient for GraphQL requests.

0 commit comments

Comments
 (0)