Class FailDependencyAttribute<TService>

Namespace
ProtoTest.AspNetCore
Assembly
ProtoTest.AspNetCore.dll

Fails a dependency of the application under test for one test, for the error paths: resolving the service throws instead of serving an instance. The test runs against a dedicated server built with the failure before it starts, so the run's shared server never sees it 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 FailDependencyAttribute<TService> : ProtoAttribute, IProtoApplicationSkipCondition, IProtoSkipCondition where TService : class

Type Parameters

TService

The service contract the application resolves.

Inheritance
FailDependencyAttribute<TService>
Implements
Inherited Members
Extension Methods

Examples

[FailDependency<ITestMessageService>]
public async Task A_failed_dependency_answers_500() { ... }

Properties

Reason

The reason reported when the test skips.

public string? Reason { get; init; }

Property Value

string

Server

The server to fail the dependency 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