Skip to content

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Jan 15, 2026

This PR improves error handling for HttpClient mocking by throwing a clear MockException when attempting to setup or verify an HttpClient that was not properly mocked with a mockable HttpMessageHandler.

Key Changes:

  • Replaced fallback logic that attempted to mock HttpClient directly with explicit exception throwing
  • Added validation to ensure ConstructorParameters array has elements before accessing
  • Added comprehensive test coverage for the error scenarios across all HTTP methods

@vbreuss vbreuss self-assigned this Jan 15, 2026
Copilot AI review requested due to automatic review settings January 15, 2026 16:58
@vbreuss vbreuss added the bug Something isn't working label Jan 15, 2026
Copy link

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

This PR improves error handling for HttpClient mocking by throwing a clear MockException when attempting to setup or verify an HttpClient that was not properly mocked with a mockable HttpMessageHandler.

Changes:

  • Replaced fallback logic that attempted to mock HttpClient directly with explicit exception throwing
  • Added validation to ensure ConstructorParameters array has elements before accessing
  • Added comprehensive test coverage for the error scenarios across all HTTP methods

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Source/Mockolate/Web/HttpClientExtensions.cs Removed unused CastToMockOrThrow helper method
Source/Mockolate/Web/HttpClientExtensions.Setup.Delete.cs Replaced fallback logic with exception throwing and added length check
Source/Mockolate/Web/HttpClientExtensions.Setup.Get.cs Replaced fallback logic with exception throwing and added length check
Source/Mockolate/Web/HttpClientExtensions.Setup.Patch.cs Replaced fallback logic with exception throwing and added length check
Source/Mockolate/Web/HttpClientExtensions.Setup.Post.cs Replaced fallback logic with exception throwing and added length check
Source/Mockolate/Web/HttpClientExtensions.Setup.Put.cs Replaced fallback logic with exception throwing and added length check
Source/Mockolate/Web/HttpClientExtensions.Verify.Delete.cs Replaced fallback logic with exception throwing and added length check
Source/Mockolate/Web/HttpClientExtensions.Verify.Get.cs Replaced fallback logic with exception throwing and added length check
Source/Mockolate/Web/HttpClientExtensions.Verify.Patch.cs Replaced fallback logic with exception throwing and added length check
Source/Mockolate/Web/HttpClientExtensions.Verify.Post.cs Replaced fallback logic with exception throwing and added length check
Source/Mockolate/Web/HttpClientExtensions.Verify.Put.cs Replaced fallback logic with exception throwing and added length check
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Setup.DeleteTests.cs Added tests for string and Uri overloads without mocked handler
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Setup.GetTests.cs Added tests for string and Uri overloads without mocked handler
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Setup.PatchTests.cs Added tests for string and Uri overloads without mocked handler
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Setup.PostTests.cs Added tests for string and Uri overloads without mocked handler
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Setup.PutTests.cs Added tests for string and Uri overloads without mocked handler
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Verify.DeleteTests.cs Added tests for string and Uri overloads without mocked handler
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Verify.GetTests.cs Added tests for string and Uri overloads without mocked handler
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Verify.PatchTests.cs Added tests for string and Uri overloads without mocked handler
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Verify.PostTests.cs Added tests for string and Uri overloads without mocked handler
Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Verify.PutTests.cs Added tests for string and Uri overloads without mocked handler

@vbreuss vbreuss enabled auto-merge (squash) January 15, 2026 16:59
@github-actions
Copy link

github-actions bot commented Jan 15, 2026

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz (Max: 3.26GHz), 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.102
[Host] : .NET 10.0.2 (10.0.2, 10.0.225.61305), X64 RyuJIT x86-64-v4

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.496 μs 0.0188 μs 0.0157 μs 0.1507 - 3.72 KB
Simple_Moq 130.626 μs 0.4718 μs 0.4182 μs 0.4883 0.2441 14.56 KB
Simple_NSubstitute 5.570 μs 0.0617 μs 0.0577 μs 0.3662 - 9.14 KB
Simple_FakeItEasy 5.746 μs 0.0625 μs 0.0554 μs 0.3281 - 8.12 KB

@github-actions
Copy link

github-actions bot commented Jan 15, 2026

Test Results

    8 files  ±  0      8 suites  ±0   2m 0s ⏱️ +19s
2 187 tests + 22  2 186 ✅ + 22  1 💤 ±0  0 ❌ ±0 
5 685 runs  +414  5 684 ✅ +414  1 💤 ±0  0 ❌ ±0 

Results for commit 532255d. ± Comparison against base commit 602f104.

♻️ This comment has been updated with latest results.

Copilot AI review requested due to automatic review settings January 15, 2026 17:34
Copy link

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 21 out of 21 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants