Fixture
Despite its complex architecture, AutoFixture exposes a very simple programming interface wrapped by the Fixture type.
A Fixture uses a graph of ISpecimenBuilders to serve requests to create auto-generated values (also known as Specimens or Anonymous Variables).
Developers can use its parameterless constructor to obtain an instance based on the default configuration. This configuration includes the wiring for the different parts of the framework and configurations for the most common types of the Base Class Library.
The IFixture interface
IFixture interfaceFixture implements the IFixture interface. The properties and methods of this interface are used to configure the specimens generation and the creation of the specimens via AutoFixture's fluent API.
Properties of IFixture
IFixtureIFixture exposes the following properties
Behaviors: a list of decorators whose execution wraps the execution of each builderCustomizations: a list of customizations that are used to create values before using default buildersResidueCollectors: a collection of builders to be used as fallback in case no default builder nor customization was able to serve the requestOmitAutoProperties: specifies whether properties should receive a value, default isfalse.RepeatCount: specifies the amount of items to be added when creating a collection, default is3.
Methods of IFixture
IFixtureBuild<T>(): initiates the creation of an instance of the given type ignoring all prior customizationsCustomize<T>(): customizes the creation algorithm for all instances of a given typeCustomize(): applies a customization to the currentFixture
The ISpecimenBuilder interface
ISpecimenBuilder interfaceOn top of IFixture, Fixture implements the ISpecimenBuilder interface. This interface exposes the Create method that is used by more user-friendly versions of this method. More information about the specimen builders and the Create method will follow.
Extension methods
On top of the methods above, several extension methods are defined on the IFixture type. These extension methods are all built on the basic operations exposed by IFixture. The most important ones will be presented in depth later on.
Here you can have a glance at the internal architecture of AutoFixture
Last updated
Was this helpful?