Skip to content

Fixes issue with mocking#1198

Merged
waldekmastykarz merged 4 commits intodotnet:mainfrom
waldekmastykarz:fix-mocking
May 22, 2025
Merged

Fixes issue with mocking#1198
waldekmastykarz merged 4 commits intodotnet:mainfrom
waldekmastykarz:fix-mocking

Conversation

@waldekmastykarz
Copy link
Copy Markdown
Collaborator

Fixes issue with mocking where updating the response in one request, would replace it for all subsequent requests as well.

@waldekmastykarz waldekmastykarz requested a review from a team as a code owner May 21, 2025 12:46
@waldekmastykarz waldekmastykarz added the pr-bugfix Fixes a bug label May 21, 2025
@garrytrinder garrytrinder requested a review from Copilot May 21, 2025 13:26
Copy link
Copy Markdown
Contributor

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 ensures that each mock response is independently processed to prevent shared state across requests.

  • Clone the matched MockResponse before applying changes in the proxy plugin
  • Implement ICloneable on MockResponse using JSON serialization for deep copy

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
dev-proxy-plugins/Mocks/MockResponsePlugin.cs Clone matching mock response before calling ProcessMockResponseInternal to isolate per-request data
dev-proxy-abstractions/MockResponse.cs Add ICloneable implementation to enable deep copy of MockResponse via JSON serialization
Comments suppressed due to low confidence (1)

dev-proxy-plugins/Mocks/MockResponsePlugin.cs:183

  • Consider adding a unit test that modifies a cloned response to verify it doesn't affect subsequent requests, ensuring the clone isolation works as intended.
ProcessMockResponseInternal(e, clonedResponse);

Comment thread dev-proxy-abstractions/MockResponse.cs
Comment thread dev-proxy-abstractions/MockResponse.cs
Comment thread dev-proxy-abstractions/MockResponse.cs
@waldekmastykarz waldekmastykarz enabled auto-merge (squash) May 22, 2025 05:59
@waldekmastykarz waldekmastykarz merged commit 9c7ad5a into dotnet:main May 22, 2025
4 checks passed
@waldekmastykarz waldekmastykarz deleted the fix-mocking branch May 22, 2025 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants