Skip to content

Add unit test infrastructure with xUnit, Moq, and coverlet#89

Merged
frasermolyneux merged 6 commits into
mainfrom
copilot/add-unit-tests-structure
Feb 7, 2026
Merged

Add unit test infrastructure with xUnit, Moq, and coverlet#89
frasermolyneux merged 6 commits into
mainfrom
copilot/add-unit-tests-structure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 7, 2026

Add Unit Test Infrastructure to XtremeIdiots.Portal.Web

Implementation Plan

  • Explore repository and reference project structure
  • Create XtremeIdiots.Portal.Web.Tests project
  • Configure test project with xUnit, Moq, and coverlet collector
  • Add test project to solution file
  • Create basic unit tests for ClaimsPrincipalExtensions
  • Create basic unit tests for IPAddressExtensions
  • Create basic unit tests for ProxyCheckService
  • Build and verify tests run successfully
  • Clean up and final verification
  • Address PR review feedback (round 1)
  • Address PR review feedback (round 2)
  • Address PR review feedback (round 3)

Summary

Successfully added unit test infrastructure to the XtremeIdiots.Portal.Web project with 40 passing tests across 3 test classes.

Changes Made (Latest Commit)

PR Review Feedback Addressed (Round 3):

  • ✅ Updated test project GUID in solution file from legacy C# project type GUID (FAE04EC0-301F-11D3-BF4B-00C04F79EFBC) to SDK-style GUID (9A19103F-16F7-4668-BE54-9A1E7A4F7556) for consistency with other projects and to avoid potential IDE/tooling quirks

Previous Changes (Round 2):

  • ✅ Refactored GetIpRiskDataAsync_WithHttpError_ReturnsErrorResult test to use using var statements instead of try-finally block for cleaner resource management

Previous Changes (Round 1):

  1. ✅ Aligned xUnit versions (2.9.3) with runner (2.8.2) to prevent test discovery issues
  2. ✅ Added PrivateAssets="all" to coverlet.collector and xunit.runner.visualstudio packages
  3. ✅ Removed x86/x64 solution configurations, keeping only Any CPU
  4. ✅ Fixed nullable reference warning in IPAddressExtensionsTests using null-forgiving operator
  5. ✅ Fixed disposable resource leaks in ProxyCheckServiceTests by properly disposing HttpResponseMessage and HttpClient

Tests Created

  1. ClaimsPrincipalExtensionsTests (13 tests)

    • Tests for Username, Email, XtremeIdiotsId extraction
    • Tests for UserProfileId and PhotoUrl claims
    • Tests for ClaimedGamesAndItems with various claim types
    • Tests for GetGameTypesForGameServers
  2. IPAddressExtensionsTests (17 tests)

    • Tests for FormatIPAddress with various parameters
    • Tests for null/empty IP address handling
    • Tests for risk score badge classes (high, medium, low, very low)
    • Tests for proxy/VPN flags
    • Tests for linking behavior
  3. ProxyCheckServiceTests (10 tests)

    • Constructor validation tests
    • Tests for empty/null IP address handling
    • Tests for cached results
    • Tests for missing API key scenario
    • Tests for HTTP error handling
    • Tests for ProxyCheckResult.GetRiskClass

Test Configuration

  • Framework: xUnit 2.9.3 (aligned with runner)
  • Runner: xunit.runner.visualstudio 2.8.2
  • Mocking: Moq 4.20.72
  • Coverage: coverlet.collector 6.0.4 (with PrivateAssets)
  • Target Framework: .NET 9.0 (net9.0)
  • Language Version: C# 13

Test Results

All tests pass successfully:

Total tests: 40
     Passed: 40
     Failed: 0
   Skipped: 0

💡 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.

Copilot AI and others added 2 commits February 7, 2026 15:37
Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com>
Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit tests implementation using Xunit and Moq Add unit test infrastructure with xUnit, Moq, and coverlet Feb 7, 2026
Copilot AI requested a review from frasermolyneux February 7, 2026 15:41
@frasermolyneux frasermolyneux marked this pull request as ready for review February 7, 2026 15:43
Copilot AI review requested due to automatic review settings February 7, 2026 15:43
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a dedicated unit test project to the Portal Web solution to establish a baseline regression safety net for extension methods and the ProxyCheckService, helping catch runtime breaks introduced by dependency updates.

Changes:

  • Added XtremeIdiots.Portal.Web.Tests project (net9.0) with xUnit, Moq, and coverlet collector, and referenced it from the web project.
  • Introduced initial unit test suites for claims principal extensions, IP address formatting extensions, and ProxyCheckService.
  • Added a README describing test structure and how to run tests/coverage.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/XtremeIdiots.Portal.Web.sln Adds the new test project to the solution and updates solution configurations.
src/XtremeIdiots.Portal.Web.Tests/XtremeIdiots.Portal.Web.Tests.csproj Introduces the test project configuration and test-related NuGet dependencies.
src/XtremeIdiots.Portal.Web.Tests/Extensions/ClaimsPrincipalExtensionsTests.cs Adds unit tests for claims extraction and game/server claim filtering.
src/XtremeIdiots.Portal.Web.Tests/Extensions/IPAddressExtensionsTests.cs Adds unit tests for HTML/IP formatting, badges, and link behavior.
src/XtremeIdiots.Portal.Web.Tests/Services/ProxyCheckServiceTests.cs Adds unit tests for ProxyCheckService behavior including caching and error paths.
src/XtremeIdiots.Portal.Web.Tests/README.md Documents how to run tests and the intended test structure/coverage areas.

Comment thread src/XtremeIdiots.Portal.Web.Tests/XtremeIdiots.Portal.Web.Tests.csproj Outdated
Comment thread src/XtremeIdiots.Portal.Web.sln Outdated
Comment thread src/XtremeIdiots.Portal.Web.sln Outdated
Comment thread src/XtremeIdiots.Portal.Web.Tests/Services/ProxyCheckServiceTests.cs Outdated
@frasermolyneux
Copy link
Copy Markdown
Owner

@copilot apply changes based on the comments in this thread

…s, simplify solution configs

Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/XtremeIdiots.Portal.Web.Tests/Services/ProxyCheckServiceTests.cs Outdated
@frasermolyneux
Copy link
Copy Markdown
Owner

@copilot apply changes based on the comments in this thread

…ally

Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/XtremeIdiots.Portal.Web.sln Outdated
…ects

Co-authored-by: frasermolyneux <34033625+frasermolyneux@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Feb 7, 2026

@frasermolyneux frasermolyneux merged commit 5a72dc7 into main Feb 7, 2026
15 checks passed
@frasermolyneux frasermolyneux deleted the copilot/add-unit-tests-structure branch February 7, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants