Interface IFixture

Namespace: AutoFixture
Assembly: AutoFixture.dll

Provides object creation services.

public interface IFixture : ISpecimenBuilder

Implements

ISpecimenBuilder

Extension Methods

CollectionFiller.AddManyTo<T>(IFixture, ICollection<T>), CollectionFiller.AddManyTo<T>(IFixture, ICollection<T>, int), CollectionFiller.AddManyTo<T>(IFixture, ICollection<T>, Func<T>), SpecimenFactory.Create<T>(ISpecimenBuilder), SpecimenFactory.CreateAnonymous<T>(IFixture), 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>), FixtureFreezer.Freeze<T>(IFixture), FixtureFreezer.Freeze<T>(IFixture, Func<ICustomizationComposer<T>, ISpecimenBuilder>), 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>), FixtureRegistrar.Inject<T>(IFixture, T), FixtureRegistrar.Register<T>(IFixture, Func<T>), FixtureRegistrar.Register<TInput, T>(IFixture, Func<TInput, T>), FixtureRegistrar.Register<TInput1, TInput2, T>(IFixture, Func<TInput1, TInput2, T>), FixtureRegistrar.Register<TInput1, TInput2, TInput3, T>(IFixture, Func<TInput1, TInput2, TInput3, T>), FixtureRegistrar.Register<TInput1, TInput2, TInput3, TInput4, T>(IFixture, Func<TInput1, TInput2, TInput3, TInput4, T>), FixtureRepeater.Repeat<T>(IFixture, Func<T>), CustomizationExtensions.ToCustomization(ISpecimenBuilder)

Properties

Behaviors

Gets the behaviors that are applied as Decorators around other parts of a Fixture. is invoked.

IList<ISpecimenBuilderTransformation> Behaviors { get; }

Property Value

IList<ISpecimenBuilderTransformation>

Customizations

Gets the customizations that intercept the request handling by the core.

IList<ISpecimenBuilder> Customizations { get; }

Property Value

IList<ISpecimenBuilder>

Remarks

Any `ISpecimenBuilder` in this list are invoked before predefined builders giving them a chance to intercept a request and resolve it.

`ISpecimenBuilder%7d)` places resulting customizations in this list.

See Also

IFixture.Behaviors, IFixture.ResidueCollectors

OmitAutoProperties

Gets or sets if writable properties should generally be assigned a value when generating an anonymous object.

bool OmitAutoProperties { get; set; }

Property Value

bool

RepeatCount

Gets or sets a number that controls how many objects are created when a Fixture creates more than one anonymous objects.

int RepeatCount { get; set; }

Property Value

int

See Also

CollectionFiller.AddManyTo<T>(IFixture, ICollection<T>), CollectionFiller.AddManyTo<T>(IFixture, ICollection<T>, Func<T>), FixtureRepeater.Repeat<T>(IFixture, Func<T>)

ResidueCollectors

Gets the residue collectors that can be used to handle requests that neither the Customizations nor the predefined builders could handle.

IList<ISpecimenBuilder> ResidueCollectors { get; }

Property Value

IList<ISpecimenBuilder>

Remarks

These `ISpecimenBuilder` instances will be invoked if no previous builder could resolve a request. This gives you the opportunity to define fallback strategies to deal with unresolved requests.

Methods

Build<T>()

Customizes the creation algorithm for a single object, effectively turning off all Customizations on the IFixture.

ICustomizationComposer<T> Build<T>()

Returns

ICustomizationComposer<T>

A ICustomizationComposer%601 that can be used to customize the creation algorithm before creating the object.

Type Parameters

T

The type of object for which the algorithm should be customized.

Remarks

The Build method kicks off a Fluent API which is usually completed by invoking `IPostprocessComposer%7b%60%600%7d)` on the method chain.

Note that the Build method chain is best understood as a one-off Customization. It bypasses all Customizations on the `Fixture` instance. Instead, it allows fine-grained control when building a specific specimen. However, in most cases, adding a convention-based `ICustomization` is a better, more flexible option.

Customize(ICustomization)

Applies a customization.

IFixture Customize(ICustomization customization)

Parameters

customization ICustomization

The customization to apply.

Returns

IFixture

An IFixture where the customization is applied.

Remarks

Note to implementers: the returned `IFixture` is expected to have customization applied. Whether the return value is the same instance as the current instance, or a copy is unspecified.

Customize<T>(Func<ICustomizationComposer<T>, ISpecimenBuilder>)

Customizes the creation algorithm for all objects of a given type.

void Customize<T>(Func<ICustomizationComposer<T>, ISpecimenBuilder> composerTransformation)

Parameters

composerTransformation Func<ICustomizationComposer<T>, ISpecimenBuilder>

A function that customizes a given ICustomizationComposer%601 and returns the modified composer.

Type Parameters

T

The type of object to customize.

Remarks

The resulting `ISpecimenBuilder` is added to `Customizations`.