Fixture Class Structure

The Fixture class specializes the AutoFixture kernel as shown on this illustration:
FixtureStructure.png
When you create a Fixture instance using the default constructor it creates a set of Specimen Builders called the engine parts, corresponding to the middle block of the illustration. These Specimen Builders contain logic that handles well-known primitive types such as integers and strings, as well as a set of components that use Reflection to create instances of complex types by invoke their constructors.

Customizations

In a default Fixture, the Customizations collection is empty, but we can use it to customize the Fixture instance by adding ISpecimenBuilder instances. Since the kernel uses the first specimen created by an ISpecimenBuilder, adding a Specimen Builder to the Customization collection intercepts the default engine parts, allowing the customization to get a shot at each request before the default engine parts handle it.

The Customize<T> method of Fixture itself uses this structure to customize the instance.

Residue Collectors

There are requests that a Fixture instance cannot satisfy. As an example, a request for an interface type cannot be satisfied because an interface has no public constructors. Added an ISpecimenBuilder instance to the ResidueCollectors collection gives that Specimen Builder a chance to handle such residue before Fixture throws an exception. The optional AutoMoq extension, for instance, is implemented with a custom Residue Collector that handle requests for interfaces by returning a mock of that interface.

Behaviors

A Behavior is simply a Decorator that can monitor or intercept requests and specimens going in and out of the Fixture instance. Tracing and Recursion Guarding are implemented as Behaviors.

Last edited Oct 13, 2010 at 1:22 PM by ploeh, version 5

Comments

No comments yet.