Class TestExtractor<T>

Namespace
Wolfgang.Etl.TestKit
Assembly
Wolfgang.Etl.TestKit.dll

An in-memory extractor for use in tests, examples, and benchmarks. Yields items from either an IEnumerable<T> or an IEnumerator<T>, depending on which constructor is used.

public class TestExtractor<T> : ExtractorBase<T, Report>, IExtractWithProgressAndCancellationAsync<T, Report>, IExtractWithCancellationAsync<T>, IExtractWithProgressAsync<T, Report>, IExtractAsync<T>

Type Parameters

T

The type of item to extract.

Inheritance
ExtractorBase<T, Report>
TestExtractor<T>
Implements
IExtractWithProgressAndCancellationAsync<T, Report>
IExtractWithCancellationAsync<T>
IExtractWithProgressAsync<T, Report>
IExtractAsync<T>
Inherited Members
ExtractorBase<T, Report>.ExtractAsync()
ExtractorBase<T, Report>.CreateProgressReport()
ExtractorBase<T, Report>.IncrementCurrentItemCount()
ExtractorBase<T, Report>.IncrementCurrentSkippedItemCount()
ExtractorBase<T, Report>.ReportingInterval
ExtractorBase<T, Report>.CurrentItemCount
ExtractorBase<T, Report>.CurrentSkippedItemCount
ExtractorBase<T, Report>.MaximumItemCount
ExtractorBase<T, Report>.SkipItemCount

Examples

// From a list:
var items = new List<int> { 1, 2, 3, 4, 5 };
var extractor = new TestExtractor<int>(items);

// From an on-the-fly generator — avoids allocating a million-item list:
static IEnumerator<int> Generate(int count)
{
    for (var i = 0; i < count; i++)
        yield return i;
}

var extractor = new TestExtractor<int>(Generate(1_000_000));

Remarks

Use the IEnumerable<T> constructor when your data is already materialized in a collection. The enumerable is re-evaluated on each call to ExtractAsync, so the extractor can be reused across multiple runs.

Use the IEnumerator<T> constructor when you need to generate large volumes of data on the fly (e.g. via a generator method with yield return) without materializing all items in memory at once. The caller owns the enumerator's lifetime — the extractor does not dispose it.

Constructors

TestExtractor(IEnumerable<T>)

Initializes a new TestExtractor<T> that yields items from the specified IEnumerable<T>.

public TestExtractor(IEnumerable<T> items)

Parameters

items IEnumerable<T>

The sequence of items to extract. The enumerable is evaluated lazily on each extraction run, so the same extractor instance can be reused.

Exceptions

ArgumentNullException

items is null.

TestExtractor(IEnumerator<T>)

Initializes a new TestExtractor<T> that yields items from the specified IEnumerator<T>.

public TestExtractor(IEnumerator<T> enumerator)

Parameters

enumerator IEnumerator<T>

The enumerator to draw items from. Useful for generator methods that produce large volumes of data on demand without allocating a full collection in memory. The caller is responsible for the enumerator's lifetime — the extractor does not dispose it.

Exceptions

ArgumentNullException

enumerator is null.

Methods

CreateProgressReport()

Creates a progress report of type TProgress. This gives the derived class the opportunity to implement a custom progress report that is specific to the extraction process.

protected override Report CreateProgressReport()

Returns

Report

Progress of type TProgress

ExtractWorkerAsync(CancellationToken)

This method is the core implementation of the extraction logic and should be overridden by derived classes.

protected override IAsyncEnumerable<T> ExtractWorkerAsync(CancellationToken token)

Parameters

token CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

IAsyncEnumerable<T>

IAsyncEnumerable<T> The result may be an empty sequence if no data is available or if the extraction fails.