Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions test/DemaConsulting.BuildMark.Tests/GitHubRepoConnectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public async Task GitHubRepoConnector_GetBuildInformationAsync_WithMultipleVersi

// Should have changelog link
Assert.IsNotNull(buildInfo.CompleteChangelogLink);
Assert.IsTrue(buildInfo.CompleteChangelogLink.TargetUrl.Contains("v1.1.0...v2.0.0"));
Assert.Contains("v1.1.0...v2.0.0", buildInfo.CompleteChangelogLink.TargetUrl);
}

/// <summary>
Expand All @@ -160,15 +160,15 @@ public async Task GitHubRepoConnector_GetBuildInformationAsync_WithPullRequests_
Merged: true,
MergeCommitSha: "commit3",
HeadRefOid: "feature-branch",
Labels: new List<string> { "feature", "enhancement" }),
Labels: ["feature", "enhancement"]),
new MockPullRequest(
Number: 100,
Title: "Fix critical bug",
Url: "https://github.com/test/repo/pull/100",
Merged: true,
MergeCommitSha: "commit2",
HeadRefOid: "bugfix-branch",
Labels: new List<string> { "bug" }))
Labels: ["bug"]))
.AddIssuesResponse()
.AddTagsResponse(
new MockTag("v1.1.0", "commit3"),
Expand All @@ -195,14 +195,14 @@ public async Task GitHubRepoConnector_GetBuildInformationAsync_WithPullRequests_
// PRs without linked issues are treated based on their labels
// PR 100 with "bug" label should be in bugs
Assert.IsNotNull(buildInfo.Bugs);
Assert.IsTrue(buildInfo.Bugs.Count >= 1, $"Expected at least 1 bug, got {buildInfo.Bugs.Count}");
Assert.IsGreaterThanOrEqualTo(1, buildInfo.Bugs.Count, $"Expected at least 1 bug, got {buildInfo.Bugs.Count}");
var bugPR = buildInfo.Bugs.FirstOrDefault(b => b.Index == 100);
Assert.IsNotNull(bugPR, "PR 100 should be categorized as a bug");
Assert.AreEqual("Fix critical bug", bugPR.Title);

// PR 101 with "feature" label should be in changes
Assert.IsNotNull(buildInfo.Changes);
Assert.IsTrue(buildInfo.Changes.Count >= 1, $"Expected at least 1 change, got {buildInfo.Changes.Count}");
Assert.IsGreaterThanOrEqualTo(1, buildInfo.Changes.Count, $"Expected at least 1 change, got {buildInfo.Changes.Count}");
var featurePR = buildInfo.Changes.FirstOrDefault(c => c.Index == 101);
Assert.IsNotNull(featurePR, "PR 101 should be categorized as a change");
Assert.AreEqual("Add new feature", featurePR.Title);
Expand All @@ -225,19 +225,19 @@ public async Task GitHubRepoConnector_GetBuildInformationAsync_WithOpenIssues_Id
Title: "Known bug in feature X",
Url: "https://github.com/test/repo/issues/201",
State: "OPEN",
Labels: new List<string> { "bug" }),
Labels: ["bug"]),
new MockIssue(
Number: 202,
Title: "Feature request for Y",
Url: "https://github.com/test/repo/issues/202",
State: "OPEN",
Labels: new List<string> { "feature" }),
Labels: ["feature"]),
new MockIssue(
Number: 203,
Title: "Fixed bug",
Url: "https://github.com/test/repo/issues/203",
State: "CLOSED",
Labels: new List<string> { "bug" }))
Labels: ["bug"]))
.AddTagsResponse(new MockTag("v1.0.0", "commit1"));

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

// Verify at least one known issue is present
var knownIssueTitles = buildInfo.KnownIssues.Select(i => i.Title).ToList();
Assert.IsTrue(knownIssueTitles.Any(t => t.Contains("Known bug") || t.Contains("Feature request")),
"Should have at least one of the open issues as a known issue");
var hasExpectedIssue = knownIssueTitles.Exists(t => t.Contains("Known bug") || t.Contains("Feature request"));
Assert.IsTrue(hasExpectedIssue, "Should have at least one of the open issues as a known issue");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public async Task MockRepoConnector_GetBuildInformationAsync_CategorizesChangesC
// - Issue #2 is a bug (type "bug")
// - Issue #3 is documentation (type "documentation")
var allItems = buildInfo.Changes.Concat(buildInfo.Bugs).ToList();
Assert.IsTrue(allItems.Any(), "Should have at least one change");
Assert.IsGreaterThan(0, allItems.Count, "Should have at least one change");

// Verify bugs only contain items with type "bug"
foreach (var bug in buildInfo.Bugs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public sealed class MockGitHubGraphQLHttpMessageHandler : HttpMessageHandler
/// <summary>
/// Dictionary mapping request patterns to response content.
/// </summary>
private readonly Dictionary<string, (string content, HttpStatusCode statusCode)> _responses = new();
private readonly Dictionary<string, (string content, HttpStatusCode statusCode)> _responses = [];

/// <summary>
/// Default response content to return when no pattern matches.
Expand Down Expand Up @@ -304,7 +304,7 @@ public MockGitHubGraphQLHttpMessageHandler AddPullRequestsResponse(
var prNodes = string.Join(",\n ",
pullRequests.Select(pr =>
{
var labelsJson = pr.Labels.Any()
var labelsJson = pr.Labels.Count > 0
? string.Join(",\n ", pr.Labels.Select(l => $@"{{ ""name"": ""{l}"" }}"))
: string.Empty;

Expand Down Expand Up @@ -364,7 +364,7 @@ public MockGitHubGraphQLHttpMessageHandler AddIssuesResponse(
var issueNodes = string.Join(",\n ",
issues.Select(issue =>
{
var labelsJson = issue.Labels.Any()
var labelsJson = issue.Labels.Count > 0
? string.Join(",\n ", issue.Labels.Select(l => $@"{{ ""name"": ""{l}"" }}"))
: string.Empty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal sealed class MockableGitHubRepoConnector : GitHubRepoConnector
/// <summary>
/// Mock responses for RunCommandAsync.
/// </summary>
private readonly Dictionary<string, string> _commandResponses = new();
private readonly Dictionary<string, string> _commandResponses = [];

/// <summary>
/// Mock HttpClient for GraphQL requests.
Expand Down