Skip to content

Commit 9c7ad5a

Browse files
Fixes issue with mocking (#1198)
1 parent 6e423ac commit 9c7ad5a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

dev-proxy-abstractions/MockResponse.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Text.Json;
6+
57
namespace DevProxy.Abstractions;
68

7-
public class MockResponse
9+
public class MockResponse: ICloneable
810
{
911
public MockResponseRequest? Request { get; set; }
1012
public MockResponseResponse? Response { get; set; }
13+
14+
public object Clone()
15+
{
16+
var json = JsonSerializer.Serialize(this);
17+
return JsonSerializer.Deserialize<MockResponse>(json) ?? new MockResponse();
18+
}
1119
}
1220

1321
public class MockResponseRequest

dev-proxy-plugins/Mocks/MockResponsePlugin.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ protected virtual Task OnRequestAsync(object? sender, ProxyRequestArgs e)
177177
var matchingResponse = GetMatchingMockResponse(request);
178178
if (matchingResponse is not null)
179179
{
180-
ProcessMockResponseInternal(e, matchingResponse);
180+
// we need to clone the response so that we're not modifying
181+
// the original that might be used in other requests
182+
var clonedResponse = (MockResponse)matchingResponse.Clone();
183+
ProcessMockResponseInternal(e, clonedResponse);
181184
state.HasBeenSet = true;
182185
return Task.CompletedTask;
183186
}

0 commit comments

Comments
 (0)