Class TestTransformer<T>
A pass-through transformer for use in tests, examples, and benchmarks. Returns each item unchanged, with no transformation applied.
public class TestTransformer<T> : TransformerBase<T, T, Report>, ITransformWithProgressAndCancellationAsync<T, T, Report>, ITransformWithCancellationAsync<T, T>, ITransformWithProgressAsync<T, T, Report>, ITransformAsync<T, T> where T : notnull
Type Parameters
TThe type of item to transform.
- Inheritance
-
TransformerBase<T, T, Report>TestTransformer<T>
- Implements
-
ITransformWithProgressAndCancellationAsync<T, T, Report>ITransformWithCancellationAsync<T, T>ITransformWithProgressAsync<T, T, Report>ITransformAsync<T, T>
- Inherited Members
-
TransformerBase<T, T, Report>.CreateProgressReport()TransformerBase<T, T, Report>.IncrementCurrentItemCount()TransformerBase<T, T, Report>.IncrementCurrentSkippedItemCount()TransformerBase<T, T, Report>.ReportingIntervalTransformerBase<T, T, Report>.CurrentItemCountTransformerBase<T, T, Report>.CurrentSkippedItemCountTransformerBase<T, T, Report>.MaximumItemCountTransformerBase<T, T, Report>.SkipItemCount
Examples
var extractor = new TestExtractor<MyRecord>(items);
var transformer = new TestTransformer<MyRecord>();
var loader = new TestLoader<MyRecord>(collectItems: true);
await loader.LoadAsync(transformer.TransformAsync(extractor.ExtractAsync()));
Remarks
Useful when a pipeline requires a transformer in the chain but the test or benchmark is focused on the extractor or loader in isolation.
Set Wolfgang.Etl.Abstractions.TransformerBase<TSource, TDestination, TProgress>.SkipItemCount to skip the first N items before yielding. Set Wolfgang.Etl.Abstractions.TransformerBase<TSource, TDestination, TProgress>.MaximumItemCount to stop after yielding that many items.
Constructors
TestTransformer()
Initializes a new TestTransformer<T> using the default production timer.
public TestTransformer()
TestTransformer(IProgressTimer)
Initializes a new TestTransformer<T> with the supplied Wolfgang.Etl.Abstractions.IProgressTimer to drive progress callbacks.
protected TestTransformer(IProgressTimer timer)
Parameters
timerIProgressTimerThe timer used to drive progress callbacks. Inject a
ManualProgressTimerin tests to fire callbacks on demand.
Exceptions
- ArgumentNullException
timeris null.
Methods
CreateProgressReport()
Creates a progress report object of type TProgress.
protected override Report CreateProgressReport()
Returns
- Report
TProgress - A new instance of the progress report object.
CreateProgressTimer(IProgress<Report>)
Creates the Wolfgang.Etl.Abstractions.IProgressTimer used to drive progress callbacks. Override this method in a derived class to inject a custom timer (for example, a custom implementation that allows manual control in unit tests).
protected override IProgressTimer CreateProgressTimer(IProgress<Report> progress)
Parameters
progressIProgress<Report>The progress sink that will receive callbacks.
Returns
- IProgressTimer
A started Wolfgang.Etl.Abstractions.IProgressTimer instance.
TransformWorkerAsync(IAsyncEnumerable<T>, CancellationToken)
The worker method that performs the actual transformation.
protected override IAsyncEnumerable<T> TransformWorkerAsync(IAsyncEnumerable<T> items, CancellationToken token)
Parameters
itemsIAsyncEnumerable<T>IAsyncEnumerable<TSource> - A list of 0 or more items to be transformed
tokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
- IAsyncEnumerable<T>
IAsyncEnumerable<TDestination> - The result may be an empty sequence if no data is available or if the transformation fails.