Class ReplaceServiceAttribute<TService>

Namespace
ProtoTest.AspNetCore
Assembly
ProtoTest.AspNetCore.dll

Substitutes a service in the application under test for one test. The test runs against a dedicated server built with the replacement before it starts, so the run's shared server never sees the substitution and the next test starts clean. The test skips when the application is not hosted in-process, mirroring RequiresInProcessAttribute.

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public sealed class ReplaceServiceAttribute<TService> : ProtoAttribute, IProtoApplicationSkipCondition, IProtoSkipCondition where TService : class

Type Parameters

TService

The service contract the application resolves.

Inheritance
ReplaceServiceAttribute<TService>
Implements
Inherited Members
Extension Methods

Examples

[ReplaceService<ITestMessageService>(typeof(StubMessageService))]
public async Task Substituting_a_service_serves_the_replacement() { ... }

Constructors

ReplaceServiceAttribute(Type)

public ReplaceServiceAttribute(Type implementationType)

Parameters

implementationType Type

Properties

ImplementationType

The concrete replacement the container constructs for the test.

public Type ImplementationType { get; }

Property Value

Type

Reason

The reason reported when the test skips.

public string? Reason { get; init; }

Property Value

string

Server

The server to substitute on. When omitted, the test's selected application is used, falling back to Default - the same rule the server accessors resolve by.

public string? Server { get; init; }

Property Value

string

Methods

BeforeTestAsync(ProtoExecutionContext)

Executed asynchronously before the decorated test or class tests execute.

public override Task BeforeTestAsync(ProtoExecutionContext context)

Parameters

context ProtoExecutionContext

Returns

Task

GetSkipReason(ProtoHost)

Returns the reason to skip, or null when the test can run.

public string? GetSkipReason(ProtoHost host)

Parameters

host ProtoHost

Returns

string