Class NodeComposer<T>

Namespace: AutoFixture.Dsl
Assembly: AutoFixture.dll

Enables composition customization of a single type of specimen.

public class NodeComposer<T> : ICustomizationComposer<T>, IFactoryComposer<T>, IPostprocessComposer<T>, ISpecimenBuilderNode, ISpecimenBuilder, IEnumerable<ISpecimenBuilder>, IEnumerable

Type Parameters

T

The type of specimen.

Inheritance

objectNodeComposer<T>

Implements

ICustomizationComposer<T>, IFactoryComposer<T>, IPostprocessComposer<T>, ISpecimenBuilderNode, ISpecimenBuilder, IEnumerable<ISpecimenBuilder>, IEnumerable

Inherited Members

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Extension Methods

SpecimenFactory.Create<T>(ISpecimenBuilder), SpecimenFactory.Create<T>(IPostprocessComposer<T>), SpecimenFactory.CreateAnonymous<T>(IPostprocessComposer<T>), SpecimenFactory.CreateMany<T>(ISpecimenBuilder), SpecimenFactory.CreateMany<T>(IPostprocessComposer<T>), SpecimenFactory.CreateMany<T>(ISpecimenBuilder, int), SpecimenFactory.CreateMany<T>(IPostprocessComposer<T>, 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>), 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>), SpecimenBuilderNode.GraphEquals(ISpecimenBuilderNode, ISpecimenBuilderNode), SpecimenBuilderNode.GraphEquals(ISpecimenBuilderNode, ISpecimenBuilderNode, IEqualityComparer<ISpecimenBuilder>), CustomizationExtensions.ToCustomization(ISpecimenBuilder)

Constructors

NodeComposer(ISpecimenBuilder)

Initializes a new instance of the NodeComposer%601 class.

public NodeComposer(ISpecimenBuilder builder)

Parameters

builder ISpecimenBuilder

A builder to which specimen creation responsibilities are delegated.

Remarks

A new NodeComposer%601 instance with an appropriate initial builder can be easily produced by CreateComposer%60%601.

See Also

SpecimenBuilderNodeFactory.CreateComposer<T>(), NodeComposer<T>.Builder

Properties

Builder

Gets the encapsulated builder.

public ISpecimenBuilder Builder { get; }

Property Value

ISpecimenBuilder

See Also

NodeComposer<T>.NodeComposer(ISpecimenBuilder)

Methods

Compose()

Composes a new ISpecimenBuilder instance.

public ISpecimenBuilder Compose()

Returns

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.

public ISpecimenBuilderNode Compose(IEnumerable<ISpecimenBuilder> builders)

Parameters

builders IEnumerable<ISpecimenBuilder>

The builders to compose.

Returns

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.

public object Create(object request, ISpecimenContext context)

Parameters

request object

The request that describes what to create.

context ISpecimenContext

A context that can be used to create other specimens.

Returns

object

The requested specimen if possible; otherwise a NoSpecimen instance.

Remarks

The request can be any object, but will often be a `Type` or other `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.

public IPostprocessComposer<T> Do(Action<T> action)

Parameters

action Action<T>

The action to perform.

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 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.

public IPostprocessComposer<T> FromFactory(ISpecimenBuilder factory)

Parameters

factory ISpecimenBuilder

An ISpecimenBuilder that can create specimens of the appropriate type.

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 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%601` 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.

public IPostprocessComposer<T> FromFactory(Func<T> factory)

Parameters

factory Func<T>

A function that will be used to create the object. This will often be a constructor.

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 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.

public IPostprocessComposer<T> FromFactory<TInput>(Func<TInput, T> factory)

Parameters

factory Func<TInput, T>

A function that will be used to create the object. This will often be a constructor that takes a single constructor argument of type TInput.

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 which can be used to further customize the post-processing of created specimens.

Type Parameters

TInput

The type of input parameter to use when invoking factory.

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.

public IPostprocessComposer<T> FromFactory<TInput1, TInput2>(Func<TInput1, TInput2, T> factory)

Parameters

factory Func<TInput1, TInput2, T>

A function that will be used to create the object. This will often be a constructor that takes two constructor arguments of type TInput1 and TInput2.

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 which can be used to further customize the post-processing of created specimens.

Type Parameters

TInput1

The type of the first input parameter to use when invoking factory.

TInput2

The type of the second input parameter to use when invoking factory.

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.

public IPostprocessComposer<T> FromFactory<TInput1, TInput2, TInput3>(Func<TInput1, TInput2, TInput3, T> factory)

Parameters

factory Func<TInput1, TInput2, TInput3, T>

A function that will be used to create the object. This will often be a constructor that takes three constructor arguments of type TInput1, TInput2 and TInput3.

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 which can be used to further customize the post-processing of created specimens.

Type Parameters

TInput1

The type of the first input parameter to use when invoking factory.

TInput2

The type of the second input parameter to use when invoking factory.

TInput3

The type of the third input parameter to use when invoking factory.

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.

public IPostprocessComposer<T> FromFactory<TInput1, TInput2, TInput3, TInput4>(Func<TInput1, TInput2, TInput3, TInput4, T> factory)

Parameters

factory Func<TInput1, TInput2, TInput3, TInput4, T>

A function that will be used to create the object. This will often be a constructor that takes three constructor arguments of type TInput1, TInput2, TInput3 and TInput4.

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 which can be used to further customize the post-processing of created specimens.

Type Parameters

TInput1

The type of the first input parameter to use when invoking factory.

TInput2

The type of the second input parameter to use when invoking factory.

TInput3

The type of the third input parameter to use when invoking factory.

TInput4

The type of the fourth input parameter to use when invoking factory.

FromSeed(Func<T, T>)

Specifies a function that defines how to create a specimen from a seed.

public IPostprocessComposer<T> FromSeed(Func<T, T> factory)

Parameters

factory Func<T, T>

The factory used to create specimens from seeds.

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 which can be used to further customize the post-processing of created specimens.

GetEnumerator()

public IEnumerator<ISpecimenBuilder> GetEnumerator()

Returns

IEnumerator<ISpecimenBuilder>

OmitAutoProperties()

Disables auto-properties for a type of specimen.

public IPostprocessComposer<T> OmitAutoProperties()

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 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.

public IPostprocessComposer<T> With<TProperty>(Expression<Func<T, TProperty>> propertyPicker)

Parameters

propertyPicker Expression<Func<T, TProperty>>

An expression that identifies the property or field that will should have a value assigned.

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 which can be used to further customize the post-processing of created specimens.

Type Parameters

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.

public IPostprocessComposer<T> With<TProperty>(Expression<Func<T, TProperty>> propertyPicker, TProperty value)

Parameters

propertyPicker Expression<Func<T, TProperty>>

An expression that identifies the property or field that will have value assigned.

value TProperty

The value to assign to the property or field identified by propertyPicker.

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 which can be used to further customize the post-processing of created specimens.

Type Parameters

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.

public IPostprocessComposer<T> With<TProperty>(Expression<Func<T, TProperty>> propertyPicker, Func<TProperty> valueFactory)

Parameters

propertyPicker Expression<Func<T, TProperty>>

An expression that identifies the property or field that will have valueFactory result assigned.

valueFactory Func<TProperty>

The factory of value to assign to the property or field identified by propertyPicker.

Returns

IPostprocessComposer<T>

Type Parameters

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.

public IPostprocessComposer<T> With<TProperty, TInput>(Expression<Func<T, TProperty>> propertyPicker, Func<TInput, TProperty> valueFactory)

Parameters

propertyPicker Expression<Func<T, TProperty>>

An expression that identifies the property or field that will have valueFactory result assigned.

valueFactory Func<TInput, TProperty>

The factory of value to assign to the property or field identified by propertyPicker.

Returns

IPostprocessComposer<T>

Type Parameters

TProperty

TInput

WithAutoProperties()

Enables auto-properties for a type of specimen.

public IPostprocessComposer<T> WithAutoProperties()

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 which can be used to further customize the post-processing of created specimens.

WithAutoProperties(bool)

Controls whether auto-properties will be enabled or not.

public NodeComposer<T> WithAutoProperties(bool enable)

Parameters

enable bool

Set to true to enable auto-properties.

Returns

NodeComposer<T>

A new instance of NodeComposer%601 where auto-properties are either enabled or disabled according to enable.

Without<TProperty>(Expression<Func<T, TProperty>>)

Registers that a writable property should not be assigned any automatic value as part of specimen post-processing.

public IPostprocessComposer<T> Without<TProperty>(Expression<Func<T, TProperty>> propertyPicker)

Parameters

propertyPicker Expression<Func<T, TProperty>>

An expression that identifies the property or field to be ignored.

Returns

IPostprocessComposer<T>

An IPostprocessComposer%601 which can be used to further customize the post-processing of created specimens.

Type Parameters

TProperty

The type of the property or field to ignore.