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
TServiceThe 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
implementationTypeType
Properties
ImplementationType
The concrete replacement the container constructs for the test.
public Type ImplementationType { get; }
Property Value
Reason
The reason reported when the test skips.
public string? Reason { get; init; }
Property Value
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
Methods
BeforeTestAsync(ProtoExecutionContext)
Executed asynchronously before the decorated test or class tests execute.
public override Task BeforeTestAsync(ProtoExecutionContext context)
Parameters
contextProtoExecutionContext
Returns
GetSkipReason(ProtoHost)
Returns the reason to skip, or null when the test can run.
public string? GetSkipReason(ProtoHost host)
Parameters
hostProtoHost