Improve GitHubRepoConnector testability via virtual factory method#90
Conversation
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
src/DemaConsulting.BuildMark/RepoConnectors/GitHubRepoConnector.cs
Outdated
Show resolved
Hide resolved
test/DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/MockGraphQLHttpMessageHandler.cs
Outdated
Show resolved
Hide resolved
…ctChangesFromPullRequestsAsync Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
src/DemaConsulting.BuildMark/RepoConnectors/GitHubRepoConnector.cs
Outdated
Show resolved
Hide resolved
.../DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/MockGitHubGraphQLHttpMessageHandler.cs
Outdated
Show resolved
Hide resolved
.../DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/MockGitHubGraphQLHttpMessageHandler.cs
Outdated
Show resolved
Hide resolved
.../DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/MockGitHubGraphQLHttpMessageHandler.cs
Outdated
Show resolved
Hide resolved
.../DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/MockGitHubGraphQLHttpMessageHandler.cs
Outdated
Show resolved
Hide resolved
.../DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/MockGitHubGraphQLHttpMessageHandler.cs
Show resolved
Hide resolved
.../DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/GitHubRepoConnectorTestabilityTests.cs
Outdated
Show resolved
Hide resolved
.../DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/GitHubRepoConnectorTestabilityTests.cs
Outdated
Show resolved
Hide resolved
.../DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/GitHubRepoConnectorTestabilityTests.cs
Outdated
Show resolved
Hide resolved
.../DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/GitHubRepoConnectorTestabilityTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
…arate test files Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
.../DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/MockGitHubGraphQLHttpMessageHandler.cs
Outdated
Show resolved
Hide resolved
.../DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/MockGitHubGraphQLHttpMessageHandler.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
…wn issues Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
.../DemaConsulting.BuildMark.Tests/RepoConnectors/GitHub/MockGitHubGraphQLHttpMessageHandler.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Pull Request
Description
GitHubRepoConnector directly instantiates
GitHubGraphQLClient, preventing comprehensive testing without live API calls. This change introduces a virtual factory method for GraphQL client creation, enabling test classes to inject mock HttpClient instances with pre-configured responses.Changes
internal virtual GitHubGraphQLClient CreateGraphQLClient(string token)to GitHubRepoConnectorCollectChangesFromPullRequestsAsyncto receive the existinggraphqlClientas the first parameter instead of creating a duplicate instance, eliminating redundant instantiationMockGitHubGraphQLHttpMessageHandlerwith helper methods that accept strongly-typed records for comprehensive testing:AddCommitsResponse(IEnumerable<string>)- supports multiple commitsAddReleasesResponse(IEnumerable<MockRelease>)- supports multiple releases with strongly-typed MockRelease records (TagName, PublishedAt)AddTagsResponse(IEnumerable<MockTag>)- supports multiple tags with strongly-typed MockTag records (Name, TargetOid)AddPullRequestsResponse(IEnumerable<MockPullRequest>)- accepts PR data with full structure (Number, Title, Url, Merged, MergeCommitSha, HeadRefOid, Labels)AddIssuesResponse(IEnumerable<MockIssue>)- accepts issue data with full structure (Number, Title, Url, State, Labels)MockableGitHubRepoConnectorhelper class for consistent mocking across test filesGetBuildInformationAsyncwith fully mocked dataExample Usage
Type of Change
Related Issues
Addresses feature request to improve GitHubRepoConnector testing capabilities.
Pre-Submission Checklist
Before submitting this pull request, ensure you have completed the following:
Build and Test
dotnet build --configuration Releasedotnet test --configuration ReleaseCode Quality
dotnet format --verify-no-changesQuality Checks
Please run the following checks before submitting:
cspell "**/*.{md,cs}"markdownlint "**/*.md"yamllint '**/*.{yml,yaml}'Testing
Documentation
Additional Notes
All changes are internal and non-breaking. The virtual method approach allows testing without exposing internals via
InternalsVisibleTopattern already in use. Test suite expanded from 170 to 179 tests, all passing across .NET 8/9/10.The mock helper class significantly reduces boilerplate in tests by providing strongly-typed record structures (MockCommit, MockRelease, MockTag, MockPullRequest, MockIssue) for comprehensive GitHub GraphQL response mocking. These data structures are organized at the top of the file for better code organization and include all necessary fields to properly simulate real GitHub API responses, enabling tests to validate complex scenarios like version selection, PR categorization (bugs vs changes), and known issues identification. The
MockableGitHubRepoConnectoris now available as an internal reusable helper for any test that needs to mock GitHubRepoConnector behavior. Tests are properly organized with dedicated test files for the mock handler and comprehensive integration tests in the main GitHubRepoConnectorTests file.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.