Polly.Testing package provides utilities for testing resilience pipelines, allowing you to inspect the structure and configuration of your pipelines in unit tests.
Installation
Extension Methods
GetPipelineDescriptor
Retrieves a descriptor that describes the structure and strategies of a resilience pipeline.ResiliencePipeline
required
The pipeline instance to describe
ResiliencePipelineDescriptor containing information about the pipeline.
Example:
GetPipelineDescriptor<TResult>
Retrieves a descriptor for a generic resilience pipeline.ResiliencePipeline<TResult>
required
The generic pipeline instance to describe
ResiliencePipelineDescriptor containing information about the pipeline.
Example:
Descriptor Classes
ResiliencePipelineDescriptor
Describes the structure of a resilience pipeline.Properties
Strategies Gets the strategies the pipeline is composed of.- Type:
IReadOnlyList<ResilienceStrategyDescriptor>
Strategies[0].
- Type:
ResilienceStrategyDescriptor
- Type:
bool
ResilienceStrategyDescriptor
Provides information about an individual resilience strategy within a pipeline.Properties
Options Gets the options used by the resilience strategy, if any.- Type:
ResilienceStrategyOptions? - Default:
nullif the strategy was not created with options
- Type:
object
Testing Patterns
Verifying Pipeline Composition
Test that your pipeline contains the expected strategies in the correct order.Verifying Strategy Options
Test that strategies are configured with the correct options.Testing Generic Pipelines
Test generic pipelines that handle specific result types.Testing Reloadable Pipelines
Verify that pipelines registered with dynamic reloading are marked as reloadable.Testing Strategy Instance Types
Access the actual strategy instance for more detailed testing.Testing Multiple Strategies
Iterate through all strategies in a complex pipeline.Integration Testing
Combine testing utilities with integration tests:Best Practices
- Test Pipeline Structure: Always verify that your pipeline contains the expected strategies in the correct order.
- Verify Options: Check that strategies are configured with the correct options values.
-
Test Reloadability: If using dynamic reloading, verify that the
IsReloadableproperty istrue. -
Use Descriptive Strategy Names: Set the
Nameproperty on strategy options to make testing easier. - Combine with Integration Tests: Use descriptors to verify configuration, then test actual execution behavior.
- Type Safety: Use pattern matching or type checks to safely access specific option types.