Class DisposableTracker

Namespace: AutoFixture.Kernel
Assembly: AutoFixture.dll

Tracks all disposable specimens created by a decorated ISpecimenBuilder to be able to dispose them when signalled.

public class DisposableTracker : ISpecimenBuilderNode, ISpecimenBuilder, IEnumerable<ISpecimenBuilder>, IEnumerable, IDisposable

Inheritance

objectDisposableTracker

Implements

ISpecimenBuilderNode, ISpecimenBuilder, IEnumerable<ISpecimenBuilder>, IEnumerable, IDisposable

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Extension Methods

SpecimenFactory.Create<T>(ISpecimenBuilder), SpecimenFactory.CreateMany<T>(ISpecimenBuilder), SpecimenFactory.CreateMany<T>(ISpecimenBuilder, int), SpecimenCommand.Do<T>(ISpecimenBuilder, Action<T>), SpecimenCommand.Do<T1, T2>(ISpecimenBuilder, Action<T1, T2>), SpecimenCommand.Do<T1, T2, T3>(ISpecimenBuilder, Action<T1, T2, T3>), SpecimenCommand.Do<T1, T2, T3, T4>(ISpecimenBuilder, Action<T1, T2, T3, T4>), SpecimenQuery.Get<T, TResult>(ISpecimenBuilder, Func<T, TResult>), SpecimenQuery.Get<T1, T2, TResult>(ISpecimenBuilder, Func<T1, T2, TResult>), SpecimenQuery.Get<T1, T2, T3, TResult>(ISpecimenBuilder, Func<T1, T2, T3, TResult>), SpecimenQuery.Get<T1, T2, T3, T4, TResult>(ISpecimenBuilder, Func<T1, T2, T3, T4, TResult>), SpecimenBuilderNode.GraphEquals(ISpecimenBuilderNode, ISpecimenBuilderNode), SpecimenBuilderNode.GraphEquals(ISpecimenBuilderNode, ISpecimenBuilderNode, IEqualityComparer<ISpecimenBuilder>), CustomizationExtensions.ToCustomization(ISpecimenBuilder)

Remarks

The DisposableTracker examines all specimens created by a decorated `ISpecimenBuilder`. All specimens that implement `IDisposable` are tracked so that they can be deterministically disposed. This happens when `Dispose` is invoked on the instance.

Constructors

DisposableTracker(ISpecimenBuilder)

Initializes a new instance of the DisposableTracker class.

public DisposableTracker(ISpecimenBuilder builder)

Parameters

builder ISpecimenBuilder

The decorated builder.

Remarks

After initialization, builder is available through the `Builder` property.

Properties

Builder

Gets the decorated builder.

public ISpecimenBuilder Builder { get; }

Property Value

ISpecimenBuilder

Remarks

This property exposes the decorated builder originally supplied to the constructor.

See Also

DisposableTracker.DisposableTracker(ISpecimenBuilder)

Disposables

Gets the disposable specimens currently tracked by this instance.

public IEnumerable<IDisposable> Disposables { get; }

Property Value

IEnumerable<IDisposable>

Remarks

Items are added to this list by the `ISpecimenContext)` method.

Methods

Compose(IEnumerable<ISpecimenBuilder>)

Composes the supplied builders.

public virtual ISpecimenBuilderNode Compose(IEnumerable<ISpecimenBuilder> builders)

Parameters

builders IEnumerable<ISpecimenBuilder>

The builders to compose.

Returns

ISpecimenBuilderNode

A new ISpecimenBuilderNode instance containing builders as child nodes.

Create(object, ISpecimenContext)

Creates a new specimen based on a request.

public object Create(object request, ISpecimenContext context)

Parameters

request object

The request that describes what to create.

context ISpecimenContext

A context that can be used to create other specimens.

Returns

object

The specimen created by the decorated builder.

Remarks

This method delegates creation of specimens to the decorated `Builder`. However, before specimens are returned they are examined and tracked in the `Disposables` list if they implement `IDisposable`. They can subsequently be disposed by invoking the `Dispose` method on the instance.

Dispose()

Disposes all items in the Disposables list and removes them from the list.

public void Dispose()

Dispose(bool)

Disposes all items in the Disposables list and removes them from the list.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

GetEnumerator()

Returns an enumerator that iterates through the collection.

public IEnumerator<ISpecimenBuilder> GetEnumerator()

Returns

IEnumerator<ISpecimenBuilder>

A IEnumerator%601 that can be used to iterate through the collection.