Class Fixture
Provides object creation services.
Inheritance
Inherited Members
Namespace: AutoFixture
Assembly: AutoFixture.dll
Syntax
public class Fixture : IFixture, ISpecimenBuilder, IEnumerable<ISpecimenBuilder>, IEnumerable
Constructors
| Improve this Doc View SourceFixture()
Initializes a new instance of the Fixture class.
Declaration
public Fixture()
Fixture(DefaultRelays)
Initializes a new instance of the Fixture class with the supplied engine parts.
Declaration
public Fixture(DefaultRelays engineParts)
Parameters
Type | Name | Description |
---|---|---|
DefaultRelays | engineParts |
Fixture(ISpecimenBuilder, MultipleRelay)
Initializes a new instance of the Fixture class with the supplied engine and a definition of what 'many' means.
Declaration
public Fixture(ISpecimenBuilder engine, MultipleRelay multiple)
Parameters
Type | Name | Description |
---|---|---|
ISpecimenBuilder | engine | The engine. |
MultipleRelay | multiple | The definition and implementation of 'many'. |
Properties
| Improve this Doc View SourceBehaviors
Gets the behaviors that are applied as Decorators around other parts of a Fixture. is invoked.
Declaration
public IList<ISpecimenBuilderTransformation> Behaviors { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IList<ISpecimenBuilderTransformation> |
Customizations
Gets the customizations that intercept the request handling by the core.
Declaration
public IList<ISpecimenBuilder> Customizations { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IList<ISpecimenBuilder> |
Remarks
Any ISpecimenBuilder in this list are invoked before predefined builders giving them a chance to intercept a request and resolve it.
Customize<T>(Func<ICustomizationComposer<T>, ISpecimenBuilder>) places resulting customizations in this list.
See Also
| Improve this Doc View SourceEngine
Gets the core engine of the Fixture instance.
Declaration
public ISpecimenBuilder Engine { get; }
Property Value
Type | Description |
---|---|
ISpecimenBuilder |
Remarks
This is the core engine that drives a Fixture instance. Even with no Customizations or ResidueCollectors, the Engine should be capably of resolving a wide range of different requests, based on conventions.
OmitAutoProperties
Gets or sets if writable properties should generally be assigned a value when generating an anonymous object.
Declaration
public bool OmitAutoProperties { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
RepeatCount
Gets or sets a number that controls how many objects are created when a Fixture creates more than one anonymous objects.
Declaration
public int RepeatCount { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
See Also
ResidueCollectors
Gets the residue collectors that can be used to handle requests that neither the Customizations nor the predefined builders could handle.
Declaration
public IList<ISpecimenBuilder> ResidueCollectors { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.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
| Improve this Doc View SourceBuild<T>()
Customizes the creation algorithm for a single object, effectively turning off all Customizations on the IFixture.
Declaration
public ICustomizationComposer<T> Build<T>()
Returns
Type | Description |
---|---|
ICustomizationComposer<T> | A ICustomizationComposer<T> that can be used to customize the creation algorithm before creating the object. |
Type Parameters
Name | Description |
---|---|
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 Create<T>(IPostprocessComposer<T>) 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.
Create(Object, ISpecimenContext)
Creates a new specimen based on a request.
Declaration
public object Create(object request, ISpecimenContext context)
Parameters
Type | Name | Description |
---|---|---|
System.Object | request | The request that describes what to create. |
ISpecimenContext | context | A context that can be used to create other specimens. |
Returns
Type | Description |
---|---|
System.Object | The requested specimen if possible; otherwise a NoSpecimen instance. |
Remarks
The request
can be any object, but will often be a
System.Type or other System.Reflection.MemberInfo instances.
Note to implementers: Implementations are expected to return a NoSpecimen instance if they can't satisfy the request.
Customize(ICustomization)
Applies a customization.
Declaration
public IFixture Customize(ICustomization customization)
Parameters
Type | Name | Description |
---|---|---|
ICustomization | customization | The customization to apply. |
Returns
Type | Description |
---|---|
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.
Declaration
public void Customize<T>(Func<ICustomizationComposer<T>, ISpecimenBuilder> composerTransformation)
Parameters
Type | Name | Description |
---|---|---|
System.Func<ICustomizationComposer<T>, ISpecimenBuilder> | composerTransformation | A function that customizes a given ICustomizationComposer<T> and returns the modified composer. |
Type Parameters
Name | Description |
---|---|
T | The type of object to customize. |
Remarks
The resulting ISpecimenBuilder is added to Customizations.
GetEnumerator()
Gets an enumerator over the internal specimen builders used to create objects.
Declaration
public IEnumerator<ISpecimenBuilder> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<ISpecimenBuilder> | An enumerator over the internal specimen builders used to create objects. |
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator |