Skip to content

Commit a7529e5

Browse files
CopilotMalcolmnixon
andcommitted
Use Assert.ThrowsAsync pattern and make untested methods private
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
1 parent ada30fa commit a7529e5

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

src/DemaConsulting.BuildMark/RepoConnectors/GitHubRepoConnector.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private static async Task<GitHubData> FetchGitHubDataAsync(
240240
/// </summary>
241241
/// <param name="data">GitHub data.</param>
242242
/// <returns>Container with all lookup data structures.</returns>
243-
internal static LookupData BuildLookupData(GitHubData data)
243+
private static LookupData BuildLookupData(GitHubData data)
244244
{
245245
// Build a mapping from issue number to issue for efficient lookup.
246246
// This is used to look up issue details when we find linked issue IDs.
@@ -303,7 +303,7 @@ internal static LookupData BuildLookupData(GitHubData data)
303303
/// <param name="lookupData">Lookup data structures.</param>
304304
/// <returns>Tuple of (toVersion, toHash).</returns>
305305
/// <exception cref="InvalidOperationException">Thrown if version cannot be determined.</exception>
306-
internal static (Version toVersion, string toHash) DetermineTargetVersion(
306+
private static (Version toVersion, string toHash) DetermineTargetVersion(
307307
Version? version,
308308
string currentCommitHash,
309309
LookupData lookupData)
@@ -350,7 +350,7 @@ internal static (Version toVersion, string toHash) DetermineTargetVersion(
350350
/// <param name="toVersion">Target version.</param>
351351
/// <param name="lookupData">Lookup data structures.</param>
352352
/// <returns>Tuple of (fromVersion, fromHash).</returns>
353-
internal static (Version? fromVersion, string? fromHash) DetermineBaselineVersion(
353+
private static (Version? fromVersion, string? fromHash) DetermineBaselineVersion(
354354
Version toVersion,
355355
LookupData lookupData)
356356
{
@@ -728,7 +728,7 @@ private static async Task<IReadOnlyList<IssueInfo>> GetAllIssuesAsync(
728728
/// <param name="fromHash">Starting commit hash (exclusive - not included in results; null for start of history).</param>
729729
/// <param name="toHash">Ending commit hash (inclusive - included in results).</param>
730730
/// <returns>List of commits in range, excluding fromHash but including toHash.</returns>
731-
internal static List<Commit> GetCommitsInRange(IReadOnlyList<Commit> commits, string? fromHash, string toHash)
731+
private static List<Commit> GetCommitsInRange(IReadOnlyList<Commit> commits, string? fromHash, string toHash)
732732
{
733733
// Initialize collection and state tracking
734734
var result = new List<Commit>();
@@ -766,7 +766,7 @@ internal static List<Commit> GetCommitsInRange(IReadOnlyList<Commit> commits, st
766766
/// <param name="issue">GitHub issue.</param>
767767
/// <param name="index">Index for sorting.</param>
768768
/// <returns>ItemInfo instance.</returns>
769-
internal static ItemInfo CreateItemInfoFromIssue(IssueInfo issue, int index)
769+
private static ItemInfo CreateItemInfoFromIssue(IssueInfo issue, int index)
770770
{
771771
// Determine item type from issue labels
772772
var type = GetTypeFromLabels(issue.Labels);
@@ -785,7 +785,7 @@ internal static ItemInfo CreateItemInfoFromIssue(IssueInfo issue, int index)
785785
/// </summary>
786786
/// <param name="pr">GitHub pull request.</param>
787787
/// <returns>ItemInfo instance.</returns>
788-
internal static ItemInfo CreateItemInfoFromPullRequest(PullRequestInfo pr)
788+
private static ItemInfo CreateItemInfoFromPullRequest(PullRequestInfo pr)
789789
{
790790
// Determine item type from PR labels
791791
var type = GetTypeFromLabels(pr.Labels);
@@ -804,7 +804,7 @@ internal static ItemInfo CreateItemInfoFromPullRequest(PullRequestInfo pr)
804804
/// </summary>
805805
/// <param name="labels">List of issue labels.</param>
806806
/// <returns>Item type string.</returns>
807-
internal static string GetTypeFromLabels(IReadOnlyList<IssueLabelInfo> labels)
807+
private static string GetTypeFromLabels(IReadOnlyList<IssueLabelInfo> labels)
808808
{
809809
// Find first matching label type by checking label names against the type map
810810
var matchingType = labels
@@ -823,7 +823,7 @@ internal static string GetTypeFromLabels(IReadOnlyList<IssueLabelInfo> labels)
823823
/// </summary>
824824
/// <param name="labels">List of pull request labels.</param>
825825
/// <returns>Item type string.</returns>
826-
internal static string GetTypeFromLabels(IReadOnlyList<PullRequestLabelInfo> labels)
826+
private static string GetTypeFromLabels(IReadOnlyList<PullRequestLabelInfo> labels)
827827
{
828828
// Find first matching label type by checking label names against the type map
829829
var matchingType = labels
@@ -867,7 +867,7 @@ private async Task<string> GetGitHubTokenAsync()
867867
/// <param name="url">Git remote URL.</param>
868868
/// <returns>Tuple of (owner, repo).</returns>
869869
/// <exception cref="ArgumentException">Thrown if URL format is invalid.</exception>
870-
internal static (string owner, string repo) ParseGitHubUrl(string url)
870+
private static (string owner, string repo) ParseGitHubUrl(string url)
871871
{
872872
// Normalize URL by trimming whitespace
873873
url = url.Trim();
@@ -895,7 +895,7 @@ internal static (string owner, string repo) ParseGitHubUrl(string url)
895895
/// <param name="path">Path segment (e.g., "owner/repo.git").</param>
896896
/// <returns>Tuple of (owner, repo).</returns>
897897
/// <exception cref="ArgumentException">Thrown if path format is invalid.</exception>
898-
internal static (string owner, string repo) ParseOwnerRepo(string path)
898+
private static (string owner, string repo) ParseOwnerRepo(string path)
899899
{
900900
// Remove .git suffix if present
901901
if (path.EndsWith(".git", StringComparison.OrdinalIgnoreCase))
@@ -923,7 +923,7 @@ internal static (string owner, string repo) ParseOwnerRepo(string path)
923923
/// <param name="newTag">New tag name.</param>
924924
/// <param name="branchTagNames">Set of tag names on the current branch.</param>
925925
/// <returns>WebLink to GitHub compare page, or null if no baseline tag or if tags not found in branch.</returns>
926-
internal static WebLink? GenerateGitHubChangelogLink(string owner, string repo, string? oldTag, string newTag, HashSet<string> branchTagNames)
926+
private static WebLink? GenerateGitHubChangelogLink(string owner, string repo, string? oldTag, string newTag, HashSet<string> branchTagNames)
927927
{
928928
// Cannot generate comparison link without a baseline tag
929929
if (oldTag == null)

test/DemaConsulting.BuildMark.Tests/ProcessRunnerTests.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,11 @@ public async Task ProcessRunner_RunAsync_WithFailingCommand_ThrowsException()
155155
var command = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "cmd" : "sh";
156156
var arguments = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "/c exit 1" : "-c 'exit 1'";
157157

158-
// Act - Execute and capture exception
159-
InvalidOperationException? exception = null;
160-
try
161-
{
162-
await ProcessRunner.RunAsync(command, arguments);
163-
Assert.Fail("RunAsync should throw InvalidOperationException when command fails");
164-
}
165-
catch (InvalidOperationException ex)
166-
{
167-
exception = ex;
168-
}
169-
170-
// Assert - Verify exception was thrown and contains useful information
171-
Assert.IsNotNull(exception, "InvalidOperationException should have been thrown");
172-
Assert.IsTrue(exception.Message.Contains("failed with exit code"),
173-
"Exception message should include exit code information");
158+
// Act & Assert - Verify exception is thrown and inspect it
159+
var exception = await Assert.ThrowsAsync<InvalidOperationException>(
160+
async () => await ProcessRunner.RunAsync(command, arguments));
161+
162+
// Assert - Verify exception message contains useful information
163+
Assert.Contains("failed with exit code", exception.Message);
174164
}
175165
}

0 commit comments

Comments
 (0)