Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<!-- Underscored Method_Scenario_Expectation test names are idiomatic; inline literal
arrays in assertions are fine in tests. -->
<NoWarn>$(NoWarn);CA1707;CA1861</NoWarn>
arrays in assertions are fine in tests. The DevProxy reference brings in the
VS threading analyzers, whose VSTHRD003/VSTHRD202 rules flag test methods that
await helpers or tasks they didn't start. -->
<NoWarn>$(NoWarn);CA1707;CA1861;VSTHRD003;VSTHRD202</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -37,6 +39,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DevProxy\DevProxy.csproj" />
<ProjectReference Include="..\DevProxy.Abstractions\DevProxy.Abstractions.csproj" />
<ProjectReference Include="..\DevProxy.Plugins\DevProxy.Plugins.csproj" />
<ProjectReference Include="..\DevProxy.Proxy.Kestrel\DevProxy.Proxy.Kestrel.csproj" />
Expand Down
21 changes: 19 additions & 2 deletions DevProxy.Integration.Tests/FakeOrigin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace DevProxy.Integration.Tests;
/// GET /big/{n} → 200, n bytes of 'A' (large finite body)
/// GET /json → 200 application/json, a 2-element array
/// GET /socket-b → WebSocket sends "rewritten"
/// * /abort → aborts the connection without a response
/// * /delay/{ms} → 200 "delayed" after {ms} milliseconds
/// </code>
/// </summary>
internal sealed class FakeOrigin : IAsyncDisposable
Expand All @@ -50,7 +52,11 @@ private FakeOrigin(WebApplication app, int port, System.Collections.Concurrent.C
_received = received;
}

public static async Task<FakeOrigin> StartAsync()
/// <param name="recordRequests">
/// Whether to record received requests in <see cref="ReceivedRequests"/>. Turn off for
/// high-volume tests, where the recording would grow memory with every request.
/// </param>
public static async Task<FakeOrigin> StartAsync(bool recordRequests = true)
{
var port = NetUtil.GetFreePort();
var builder = WebApplication.CreateEmptyBuilder(new WebApplicationOptions());
Expand All @@ -67,7 +73,10 @@ public static async Task<FakeOrigin> StartAsync()
var received = new System.Collections.Concurrent.ConcurrentQueue<ReceivedRequest>();
app.Use(async (ctx, next) =>
{
received.Enqueue(new ReceivedRequest(ctx.Request.Method, ctx.Request.Path + ctx.Request.QueryString));
if (recordRequests)
{
received.Enqueue(new ReceivedRequest(ctx.Request.Method, ctx.Request.Path + ctx.Request.QueryString));
}
await next().ConfigureAwait(false);
});

Expand Down Expand Up @@ -120,6 +129,14 @@ public static async Task<FakeOrigin> StartAsync()
new { id = 2, name = "beta" },
}));

app.Map("/abort", (HttpContext ctx) => ctx.Abort());

app.Map("/delay/{ms:int}", async (int ms, HttpContext ctx) =>
{
await Task.Delay(ms, ctx.RequestAborted).ConfigureAwait(false);
return Results.Text("delayed");
});

app.Map("/socket-b", async context =>
{
if (!context.WebSockets.IsWebSocketRequest)
Expand Down
Loading
Loading