Class ProtoHttpRequestBuilder<TResponse, TBuilder>

Namespace
ProtoTest.Http
Assembly
ProtoTest.Http.dll

The state and fluent surface every HTTP-based request builder shares: the client, context, target, headers, authenticator resolution and base-address resolver, plus the hooks each protocol uses to record how its authentication and headers were configured. A protocol's request shape (a REST route, a GraphQL document) stays in the derived builder.

public abstract class ProtoHttpRequestBuilder<TResponse, TBuilder> where TResponse : ProtoHttpResponse where TBuilder : ProtoHttpRequestBuilder<TResponse, TBuilder>

Type Parameters

TResponse
TBuilder
Inheritance
ProtoHttpRequestBuilder<TResponse, TBuilder>
Derived
Inherited Members
Extension Methods

Constructors

ProtoHttpRequestBuilder(HttpClient, ProtoExecutionContext, string, ProtoProtocol, string?)

protected ProtoHttpRequestBuilder(HttpClient client, ProtoExecutionContext context, string targetName, ProtoProtocol protocol, string? clientEntityName = null)

Parameters

client HttpClient
context ProtoExecutionContext
targetName string
protocol ProtoProtocol
clientEntityName string

Properties

AuthenticatorFactory

The authenticator factory configured for this builder, if any.

protected Func<ProtoExecutionContext, IProtoHttpAuthenticator>? AuthenticatorFactory { get; set; }

Property Value

Func<ProtoExecutionContext, IProtoHttpAuthenticator>

BaseAddressResolver

The per-test base-address resolver, when the client registered one.

protected Func<ProtoExecutionContext, CancellationToken, ValueTask<Uri>>? BaseAddressResolver { get; set; }

Property Value

Func<ProtoExecutionContext, CancellationToken, ValueTask<Uri>>

Client

The client the request is sent over.

protected HttpClient Client { get; }

Property Value

HttpClient

ClientEntityName

The registry key of the client the request actually uses; the client entity's id.

protected string ClientEntityName { get; }

Property Value

string

Context

The test execution context requests and traces belong to.

protected ProtoExecutionContext Context { get; }

Property Value

ProtoExecutionContext

Headers

The configured headers; mutable so a derived builder can compose them directly.

protected Dictionary<string, string> Headers { get; }

Property Value

Dictionary<string, string>

Protocol

The protocol identity: names, trace source, observation kinds and coverage category.

protected ProtoProtocol Protocol { get; }

Property Value

ProtoProtocol

ResolvedAuthenticator

The authenticator an earlier request resolved, reused so it is created once.

protected IProtoHttpAuthenticator? ResolvedAuthenticator { get; set; }

Property Value

IProtoHttpAuthenticator

TargetName

The registered target name requests, observations and collectors agree on.

protected string TargetName { get; }

Property Value

string

Methods

ApplyAuthenticationAsync(HttpRequestMessage, ProtoTraceOperation?, CancellationToken)

Resolves and applies authentication for one request, caching the authenticator.

protected ValueTask<IProtoHttpAuthenticator?> ApplyAuthenticationAsync(HttpRequestMessage request, ProtoTraceOperation? operation, CancellationToken cancellationToken)

Parameters

request HttpRequestMessage
operation ProtoTraceOperation
cancellationToken CancellationToken

Returns

ValueTask<IProtoHttpAuthenticator>

Auth(IProtoHttpAuthenticator)

Applies the request's explicit authenticator; inherited authentication is replaced.

public TBuilder Auth(IProtoHttpAuthenticator authenticator)

Parameters

authenticator IProtoHttpAuthenticator

Returns

TBuilder

Auth<TAuthenticator>(params object[])

Applies an authenticator created through ProtoAuthenticatorFactory.

public TBuilder Auth<TAuthenticator>(params object[] constructorArgs) where TAuthenticator : class, IProtoHttpAuthenticator

Parameters

constructorArgs object[]

Returns

TBuilder

Type Parameters

TAuthenticator

Header(string, string)

public TBuilder Header(string name, string value)

Parameters

name string
value string

Returns

TBuilder

OnAuthenticationConfigured(string, Type?)

Records how authentication was configured; the protocol chooses attributes or events.

protected abstract void OnAuthenticationConfigured(string source, Type? authenticatorType)

Parameters

source string
authenticatorType Type

OnHeaderConfigured(string, bool)

Records a header configuration; isNewHeader is false on replacement.

protected virtual void OnHeaderConfigured(string name, bool isNewHeader)

Parameters

name string
isNewHeader bool

ResolveResponseOptions()

The response options this protocol registered.

protected ProtoHttpResponseOptions ResolveResponseOptions()

Returns

ProtoHttpResponseOptions

TraceConfiguration(string, string, IReadOnlyDictionary<string, string?>)

Writes a successful configuration event under the protocol's trace source.

protected void TraceConfiguration(string kind, string name, IReadOnlyDictionary<string, string?> attributes)

Parameters

kind string
name string
attributes IReadOnlyDictionary<string, string>

UseAuthenticatorFactory(Func<ProtoExecutionContext, IProtoHttpAuthenticator>?)

Adopts the authenticator factory a protocol's lifecycle hook resolved for the test, so the builder resolves the same authenticators for its named client. A protocol integration calls this when it composes its request builder.

public TBuilder UseAuthenticatorFactory(Func<ProtoExecutionContext, IProtoHttpAuthenticator>? authenticatorFactory)

Parameters

authenticatorFactory Func<ProtoExecutionContext, IProtoHttpAuthenticator>

The factory the protocol resolved, or null for none.

Returns

TBuilder

UseBaseAddressResolver(Func<ProtoExecutionContext, CancellationToken, ValueTask<Uri>>?)

Adopts the per-test base-address resolver the resolved client registered, when it has one; a request builder without one uses the client's own BaseAddress.

public TBuilder UseBaseAddressResolver(Func<ProtoExecutionContext, CancellationToken, ValueTask<Uri>>? baseAddressResolver)

Parameters

baseAddressResolver Func<ProtoExecutionContext, CancellationToken, ValueTask<Uri>>

The resolver the client resolution carries, or null for none.

Returns

TBuilder

WithoutAuth()

Disables inherited or class-level authentication for this request builder.

public TBuilder WithoutAuth()

Returns

TBuilder