Class NodeComposer<T>
Enables composition customization of a single type of specimen.
Inheritance
Inherited Members
Namespace: AutoFixture.Dsl
Assembly: AutoFixture.dll
Syntax
public class NodeComposer<T> : ICustomizationComposer<T>, IFactoryComposer<T>, IPostprocessComposer<T>, ISpecimenBuilderNode, ISpecimenBuilder, IEnumerable<ISpecimenBuilder>, IEnumerable
Type Parameters
Name | Description |
---|---|
T | The type of specimen. |
Constructors
| Improve this Doc View SourceNodeComposer(ISpecimenBuilder)
Initializes a new instance of the NodeComposer<T> class.
Declaration
public NodeComposer(ISpecimenBuilder builder)
Parameters
Type | Name | Description |
---|---|---|
ISpecimenBuilder | builder | A builder to which specimen creation responsibilities are delegated. |
Remarks
A new NodeComposer<T> instance with an appropriate
initial builder
can be easily produced by
CreateComposer<T>().
See Also
Properties
| Improve this Doc View SourceBuilder
Gets the encapsulated builder.
Declaration
public ISpecimenBuilder Builder { get; }
Property Value
Type | Description |
---|---|
ISpecimenBuilder | The encapsulated builder. |
See Also
Methods
| Improve this Doc View SourceCompose()
Composes a new ISpecimenBuilder instance.
Declaration
public ISpecimenBuilder Compose()
Returns
Type | Description |
---|---|
ISpecimenBuilder | A new ISpecimenBuilder instance which can be used to produce specimens according to the behavior specified by previous method calls. |
Compose(IEnumerable<ISpecimenBuilder>)
Composes the supplied builders.
Declaration
public ISpecimenBuilderNode Compose(IEnumerable<ISpecimenBuilder> builders)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<ISpecimenBuilder> | builders | The builders to compose. |
Returns
Type | Description |
---|---|
ISpecimenBuilderNode | A ISpecimenBuilderNode instance. |
Remarks
Note to implementers:
The intent of this method is to compose the supplied
builders
into a new instance of the type
implementing ISpecimenBuilderNode. Thus, the
concrete return type is expected to the same type as the type
implementing the method. However, it is not considered a failure to
deviate from this idiom - it would just not be a mainstream
implementation.
The returned instance is normally expected to contain the builders supplied as an argument, but again this is not strictly required. The implementation may decide to filter the sequence or add to it during composition.
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.
Do(Action<T>)
Performs the specified action on a specimen.
Declaration
public IPostprocessComposer<T> Do(Action<T> action)
Parameters
Type | Name | Description |
---|---|---|
System.Action<T> | action | The action to perform. |
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
FromFactory(ISpecimenBuilder)
Specifies an ISpecimenBuilder that can create specimens of the appropriate type. Mostly for advanced scenarios.
Declaration
public IPostprocessComposer<T> FromFactory(ISpecimenBuilder factory)
Parameters
Type | Name | Description |
---|---|---|
ISpecimenBuilder | factory | An ISpecimenBuilder that can create specimens of the appropriate type. |
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
Remarks
This method is mostly intended for advanced scenarios where a more loosely coupled strategy is desired to create specimens, but the advantages of the strongly typed IPostprocessComposer<T> are still desired for post-processing.
One possible scenario is for post-processing of interfaces or abstract types where auto-mocking is desired to create the instance. This method makes it possible to supply an auto-mocking ISpecimenBuilder.
factory
must be able to create specimens of the requested type, or
exceptions may be thrown.
FromFactory(Func<T>)
Specifies that an anonymous object should be created in a particular way; often by using a constructor.
Declaration
public IPostprocessComposer<T> FromFactory(Func<T> factory)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T> | factory | A function that will be used to create the object. This will often be a constructor. |
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
FromFactory<TInput>(Func<TInput, T>)
Specifies that a specimen should be created in a particular way, using a single input parameter for the factory.
Declaration
public IPostprocessComposer<T> FromFactory<TInput>(Func<TInput, T> factory)
Parameters
Type | Name | Description |
---|---|---|
System.Func<TInput, T> | factory | A function that will be used to create the object. This will often be a constructor
that takes a single constructor argument of type |
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
Type Parameters
Name | Description |
---|---|
TInput | The type of input parameter to use when invoking |
FromFactory<TInput1, TInput2>(Func<TInput1, TInput2, T>)
Specifies that a specimen should be created in a particular way, using two input parameters for the construction.
Declaration
public IPostprocessComposer<T> FromFactory<TInput1, TInput2>(Func<TInput1, TInput2, T> factory)
Parameters
Type | Name | Description |
---|---|---|
System.Func<TInput1, TInput2, T> | factory | A function that will be used to create the object. This will often be a constructor
that takes two constructor arguments of type |
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
Type Parameters
Name | Description |
---|---|
TInput1 | The type of the first input parameter to use when invoking |
TInput2 | The type of the second input parameter to use when invoking |
FromFactory<TInput1, TInput2, TInput3>(Func<TInput1, TInput2, TInput3, T>)
Specifies that a specimen should be created in a particular way, using three input parameters for the construction.
Declaration
public IPostprocessComposer<T> FromFactory<TInput1, TInput2, TInput3>(Func<TInput1, TInput2, TInput3, T> factory)
Parameters
Type | Name | Description |
---|---|---|
System.Func<TInput1, TInput2, TInput3, T> | factory | A function that will be used to create the object. This will often be a constructor
that takes three constructor arguments of type |
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
Type Parameters
Name | Description |
---|---|
TInput1 | The type of the first input parameter to use when invoking |
TInput2 | The type of the second input parameter to use when invoking |
TInput3 | The type of the third input parameter to use when invoking |
FromFactory<TInput1, TInput2, TInput3, TInput4>(Func<TInput1, TInput2, TInput3, TInput4, T>)
Specifies that a specimen should be created in a particular way, using four input parameters for the construction.
Declaration
public IPostprocessComposer<T> FromFactory<TInput1, TInput2, TInput3, TInput4>(Func<TInput1, TInput2, TInput3, TInput4, T> factory)
Parameters
Type | Name | Description |
---|---|---|
System.Func<TInput1, TInput2, TInput3, TInput4, T> | factory | A function that will be used to create the object. This will often be a constructor
that takes three constructor arguments of type |
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
Type Parameters
Name | Description |
---|---|
TInput1 | The type of the first input parameter to use when invoking |
TInput2 | The type of the second input parameter to use when invoking |
TInput3 | The type of the third input parameter to use when invoking |
TInput4 | The type of the fourth input parameter to use when invoking |
FromSeed(Func<T, T>)
Specifies a function that defines how to create a specimen from a seed.
Declaration
public IPostprocessComposer<T> FromSeed(Func<T, T> factory)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T, T> | factory | The factory used to create specimens from seeds. |
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
GetEnumerator()
Declaration
public IEnumerator<ISpecimenBuilder> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<ISpecimenBuilder> |
OmitAutoProperties()
Disables auto-properties for a type of specimen.
Declaration
public IPostprocessComposer<T> OmitAutoProperties()
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
With<TProperty>(Expression<Func<T, TProperty>>)
Registers that a writable property or field should be assigned an anonymous value as part of specimen post-processing.
Declaration
public IPostprocessComposer<T> With<TProperty>(Expression<Func<T, TProperty>> propertyPicker)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<T, TProperty>> | propertyPicker | An expression that identifies the property or field that will should have a value assigned. |
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
Type Parameters
Name | Description |
---|---|
TProperty | The type of the property of field. |
With<TProperty>(Expression<Func<T, TProperty>>, TProperty)
Registers that a writable property or field should be assigned a specific value as part of specimen post-processing.
Declaration
public IPostprocessComposer<T> With<TProperty>(Expression<Func<T, TProperty>> propertyPicker, TProperty value)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<T, TProperty>> | propertyPicker | An expression that identifies the property or field that will have
|
TProperty | value | The value to assign to the property or field identified by
|
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
Type Parameters
Name | Description |
---|---|
TProperty | The type of the property of field. |
With<TProperty>(Expression<Func<T, TProperty>>, Func<TProperty>)
Registers that a writable property or field should be assigned generated value as a part of specimen post-processing.
Declaration
public IPostprocessComposer<T> With<TProperty>(Expression<Func<T, TProperty>> propertyPicker, Func<TProperty> valueFactory)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<T, TProperty>> | propertyPicker | An expression that identifies the property or field that will have |
System.Func<TProperty> | valueFactory | The factory of value to assign to the property or field identified by |
Returns
Type | Description |
---|---|
IPostprocessComposer<T> |
Type Parameters
Name | Description |
---|---|
TProperty |
With<TProperty, TInput>(Expression<Func<T, TProperty>>, Func<TInput, TProperty>)
Registers that a writable property or field should be assigned generated value as a part of specimen post-processing.
Declaration
public IPostprocessComposer<T> With<TProperty, TInput>(Expression<Func<T, TProperty>> propertyPicker, Func<TInput, TProperty> valueFactory)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<T, TProperty>> | propertyPicker | An expression that identifies the property or field that will have |
System.Func<TInput, TProperty> | valueFactory | The factory of value to assign to the property or field identified by |
Returns
Type | Description |
---|---|
IPostprocessComposer<T> |
Type Parameters
Name | Description |
---|---|
TProperty | |
TInput |
WithAutoProperties()
Enables auto-properties for a type of specimen.
Declaration
public IPostprocessComposer<T> WithAutoProperties()
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
WithAutoProperties(Boolean)
Controls whether auto-properties will be enabled or not.
Declaration
public NodeComposer<T> WithAutoProperties(bool enable)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | enable | Set to true to enable auto-properties. |
Returns
Type | Description |
---|---|
NodeComposer<T> | A new instance of NodeComposer<T> where
auto-properties are either enabled or disabled according to
|
Without<TProperty>(Expression<Func<T, TProperty>>)
Registers that a writable property should not be assigned any automatic value as part of specimen post-processing.
Declaration
public IPostprocessComposer<T> Without<TProperty>(Expression<Func<T, TProperty>> propertyPicker)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<T, TProperty>> | propertyPicker | An expression that identifies the property or field to be ignored. |
Returns
Type | Description |
---|---|
IPostprocessComposer<T> | An IPostprocessComposer<T> which can be used to further customize the post-processing of created specimens. |
Type Parameters
Name | Description |
---|---|
TProperty | The type of the property or field to ignore. |
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator |