-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: throw MockException when HttpClient is not mockable
#367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: throw MockException when HttpClient is not mockable
#367
Conversation
There was a problem hiding this 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
HttpClientdirectly with explicit exception throwing - Added validation to ensure
ConstructorParametersarray 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 |
🚀 Benchmark ResultsDetails
|
There was a problem hiding this 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.
This PR improves error handling for
HttpClientmocking by throwing a clearMockExceptionwhen attempting to setup or verify anHttpClientthat was not properly mocked with a mockableHttpMessageHandler.Key Changes:
HttpClientdirectly with explicit exception throwingConstructorParametersarray has elements before accessing