Round #868

11 May 2026, 09:52· csharp· Meta-Llama-3.3-70B-Instruct· r15-firing-v3
Complexity
band 0
ZP / UO / OBS
7 / 0 / 3
Journey weight
745
Lightshift ΔL
+0.00

Prompt

Write an xUnit IClassFixture<T> that spins up a TestServer once per test class and exposes an HttpClient to the tests. Show one test using it.

Zero-point index (what the engine surfaced)

ZPI-ZPI-0025 | 2026-05-11T09:52:14Z Write an xUnit IClassFixture<T> that spins up a TestServer once per test class and exposes an HttpClient to the tests. Show one test using it. ZERO POINT — 7 entries (structural invariants) ● hsl(306.86, 100%, 15%) HttpClient [contract] ● hsl(205.59, 100%, 15%) IHttpClientFactory [contract] ● hsl(121.23, 100%, 15%) DelegatingHandler [contract] ● hsl(269.52, 100%, 15%) HttpMessageHandler [contract] ● hsl(163.13, 100%, 15%) IClassFixture<T> [contract] ● hsl(269.41, 100%, 15%) ICollectionFixture<T> [contract] ● hsl(231.79, 100%, 15%) IAsyncLifetime [contract] UNOBSERVED — 0 entries (implied truths) OBSERVED — 3 entries (explicit in request) ◉ hsl(7.18, 100%, 50%) class [feature] ◉ hsl(85.13, 100%, 50%) using [feature] ◉ hsl(234.87, 100%, 50%) using [feature] COMPLEXITY │ 10 entries │ spread: 228° │ band: LOW

Baseline response (no ZPI)

Here's an example implementation of an `IClassFixture<T>` that spins up a `TestServer` once per test class and exposes an `HttpClient` to the tests. ```csharp using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.AspNetCore.TestHost; using System.Net.Http; using Xunit; // Define the fixture class public class WebApiFixture : IDisposable { public TestServer Server { get; } public HttpClient Client { get; } public WebApiFixture() { // Create a new instance of the TestServer Server = new TestServer(new WebHostBuilder() .UseStartup<Startup>()); Client = Server.CreateClient(); } public void Dispose() { // Dispose the TestServer and HttpClient Client.Dispose(); Server.Dispose(); } } // Define the test class public class WebApiTests : IClassFixture<WebApiFixture> { private readonly WebApiFixture _fixture; public WebApiTests(WebApiFixture fixture) { _fixture = fixture; } [Fact] public async Task Get_HomePage_ReturnsOkResult() { // Arrange var client = _fixture.Client; // Act var response = await client.GetAsync("/"); // Assert response.EnsureSuccessStatusCode(); } } ``` In this example, the `WebApiFixture` class implements `IDisposable` to ensure that the `TestServer` and `HttpClient` are properly disposed of after each test class. The `WebApiTests` class uses the `IClassFixture<T>` interface to get an instance of the `WebApiFixture` class, which provides access to the `HttpClient` instance. Note that you'll need to replace `Startup` with the actual startup class of your ASP.NET Core application. Also, make sure to install the required NuGet packages: * `Microsoft.AspNetCore.Mvc.Testing` * `Microsoft.AspNetCore.TestHost` * `xunit` * `xunit.runner.visualstudio` (if you're using Visual Studio) You can install these packages using the NuGet Package Manager or by running the following commands in the Package Manager Console: ``` Install-Package Microsoft.AspNetCore.Mvc.Testing Install-Package Microsoft.AspNetCore.TestHost Install-Package xunit Install-Package xunit.runner.visualstudio ```

Enhanced response (with ZPI)

```csharp using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Xunit; public class CustomWebApplicationFactory : WebApplicationFactory<Startup> { protected override void ConfigureWebHost(IWebHostBuilder builder) { builder.UseEnvironment("Test"); } } public class TestServerFixture : IClassFixture<CustomWebApplicationFactory>, IDisposable { public HttpClient Client { get; private set; } public TestServerFixture(CustomWebApplicationFactory factory) { Client = factory.CreateClient(); } public void Dispose() { Client.Dispose(); } } public class MyTests : IClassFixture<TestServerFixture> { private readonly TestServerFixture _fixture; public MyTests(TestServerFixture fixture) { _fixture = fixture; } [Fact] public async Task Test_Get_HomePage() { // Arrange var client = _fixture.Client; // Act var response = await client.GetAsync("/"); // Assert response.EnsureSuccessStatusCode(); } } ``` This implementation utilizes xUnit's `IClassFixture<T>` to create a test fixture that spins up a `TestServer` once per test class. The `CustomWebApplicationFactory` class is used to configure the `TestServer`. The `TestServerFixture` class creates an instance of `HttpClient` using the `TestServer` and exposes it to the tests. The `MyTests` class demonstrates how to use the `TestServerFixture` to write a test that uses the `HttpClient` to make a GET request to the home page. Note that the `TestServerFixture` class implements `IDisposable` to ensure that the `HttpClient` is properly disposed of after the tests are completed. This implementation requires more text to fully explain the solution.

Grader chain

Each grader reads the same baseline + enhanced pair and casts an independent verdict. Disagreement is the framework's own signal — not noise to be averaged away.

V1samba/Meta-Llama-3.3-70B-Instruct
Better
V4qwen2.5-coder-3b-instruct
Better
V5openrouter/qwen/qwen3-235b-a22b-2507
Better
V7qwen2.5-coder-7b-instruct
Better
V8openai/gpt-4.1
Better
V9anthropic/claude-opus-4-7
Worse
V12openai/gpt-4o
Better

Comments

Our grader said what it said. What do you say? Comment as a guest below.

No comments yet. Be the first to say what you make of this round.

← back to all rounds