Skip to content

Expose Request as public type to make assertions and response routing easier #334

Description

@dnperfors

Is your feature request related to a problem? Please describe.
From the beginning of TestableHttpClient, we support assertions using method chaining. This is very verbose and it kept asserting at every step, which doesn't give clear error messages.
In version 0.12 I introduced a RequestBuilder to build a request and assert the whole request at once. Although this avoids the multiple assertion problem, it is still verbose.

Describe the solution you'd like
In order to fix this verbosity, I propose to make the underlying Request class public so that it can be used and manipulated directly by the user.

Additional context
With the unions that are coming in C# 15, it should be easy to specify 'any' and 'none' values as well as exact values and patterns.

Design
The request should look something like this:

public sealed record Request
{
  public AnyOr<HttpMethod> Method { get; init; }
  public AnyOr<string> RequestUri { get; init; }
  public AnyOr<Version> Version { get; init; }
  public Headers Headers { get; init; }
  public Content Content { get; init; }
}

public sealed struct record Any;
public union AnyOr<T> (Any, T);
public union Headers(Any, Dictionary<string, Value>)
public union Content(Any, string)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions