Class SpecimenFactory

Namespace: AutoFixture
Assembly: AutoFixture.dll

Creates anonymous variables from ISpecimenContext or ISpecimenBuilder instances.

public static class SpecimenFactory

Inheritance

objectSpecimenFactory

Inherited Members

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

Methods

Create<T>(ISpecimenContext)

Creates an anonymous variable of the requested type.

public static T Create<T>(this ISpecimenContext context)

Parameters

context ISpecimenContext

The context used to resolve the type request.

Returns

T

An anonymous object of type T.

Type Parameters

T

The type of object to create.

Create<T>(ISpecimenBuilder)

Creates an anonymous variable of the requested type.

public static T Create<T>(this ISpecimenBuilder builder)

Parameters

builder ISpecimenBuilder

The builder used to resolve the type request.

Returns

T

An anonymous object of type T.

Type Parameters

T

The type of object to create.

Create<T>(IPostprocessComposer<T>)

Creates an anonymous variable of the requested type.

public static T Create<T>(this IPostprocessComposer<T> composer)

Parameters

composer IPostprocessComposer<T>

The composer used to resolve the type request.

Returns

T

An anonymous object of type T.

Type Parameters

T

The type of object to create.

Remarks

The only purpose of this explicit overload is to support type inferencing.

CreateAnonymous<T>(ISpecimenContext)

Creates an anonymous variable of the requested type.

[Obsolete("Please move over to using Create<T>() as this method will be removed in the next release", true)]
public static T CreateAnonymous<T>(this ISpecimenContext context)

Parameters

context ISpecimenContext

The context used to resolve the type request.

Returns

T

An anonymous object of type T.

Type Parameters

T

The type of object to create.

Remarks

Obsolete: Please move over to using ISpecimenContext)?text=Create%3cT%3e() as this method will be removed in the next release.

CreateAnonymous<T>(IFixture)

Creates an anonymous variable of the requested type.

[Obsolete("For compatibility to AutoFixture version 2. This method will be removed, please move to using Create<T>()", true)]
public static T CreateAnonymous<T>(this IFixture fixture)

Parameters

fixture IFixture

The fixture used to resolve the type request.

Returns

T

An anonymous object of type T.

Type Parameters

T

The type of object to create.

CreateAnonymous<T>(IPostprocessComposer<T>)

Creates an anonymous variable of the requested type.

[Obsolete("Please move over to using Create<T>() as this method will be removed in the next release", true)]
public static T CreateAnonymous<T>(this IPostprocessComposer<T> composer)

Parameters

composer IPostprocessComposer<T>

The composer used to resolve the type request.

Returns

T

An anonymous object of type T.

Type Parameters

T

The type of object to create.

Remarks

Obsolete: "Please move over to using ISpecimenContext)?text=Create%7bT%7d as this method will be removed in the next release.

CreateMany<T>(ISpecimenBuilder)

Creates many anonymous objects.

public static IEnumerable<T> CreateMany<T>(this ISpecimenBuilder builder)

Parameters

builder ISpecimenBuilder

The builder used to resolve the type request.

Returns

IEnumerable<T>

A sequence of anonymous object of type T.

Type Parameters

T

The type of objects to create.

Remarks

The CreateMany implementation always returns a new instance of `IEnumerable%601`. Even if IEnumerable<T> is Frozen by the `IFixture)` method or explicitly assigned with the `IFixture%2c%60%600)` method, the CreateMany method returns a new, independent instance of IEnumerable<T>.

However, you can change this behavior, for example by applying the `MapCreateManyToEnumerable` customization.

CreateMany<T>(ISpecimenContext)

Creates many anonymous objects.

public static IEnumerable<T> CreateMany<T>(this ISpecimenContext context)

Parameters

context ISpecimenContext

The context used to resolve the type request.

Returns

IEnumerable<T>

A sequence of anonymous object of type T.

Type Parameters

T

The type of objects to create.

Remarks

The CreateMany implementation always returns a new instance of `IEnumerable%601`. Even if IEnumerable<T> is Frozen by the `IFixture)` method or explicitly assigned with the `IFixture%2c%60%600)` method, the CreateMany method returns a new, independent instance of IEnumerable<T>.

However, you can change this behavior, for example by applying the `MapCreateManyToEnumerable` customization.

CreateMany<T>(IPostprocessComposer<T>)

Creates many anonymous objects.

public static IEnumerable<T> CreateMany<T>(this IPostprocessComposer<T> composer)

Parameters

composer IPostprocessComposer<T>

The composer used to resolve the type request.

Returns

IEnumerable<T>

A sequence of anonymous object of type T.

Type Parameters

T

The type of objects to create.

Remarks

The CreateMany implementation always returns a new instance of `IEnumerable%601`. Even if IEnumerable<T> is Frozen by the `IFixture)` method or explicitly assigned with the `IFixture%2c%60%600)` method, the CreateMany method returns a new, independent instance of IEnumerable<T>.

However, you can change this behavior, for example by applying the `MapCreateManyToEnumerable` customization.

The only purpose of this explicit overload is to support type inferencing.

CreateMany<T>(ISpecimenBuilder, int)

Creates many anonymous objects.

public static IEnumerable<T> CreateMany<T>(this ISpecimenBuilder builder, int count)

Parameters

builder ISpecimenBuilder

The builder used to resolve the type request.

count int

The number of objects to create.

Returns

IEnumerable<T>

A sequence of anonymous objects of type T.

Type Parameters

T

The type of objects to create.

Remarks

The CreateMany implementation always returns a new instance of `IEnumerable%601`. Even if IEnumerable<T> is Frozen by the `IFixture)` method or explicitly assigned with the `IFixture%2c%60%600)` method, the CreateMany method returns a new, independent instance of IEnumerable<T>.

However, you can change this behavior, for example by applying the `MapCreateManyToEnumerable` customization.

CreateMany<T>(ISpecimenContext, int)

Creates many anonymous objects.

public static IEnumerable<T> CreateMany<T>(this ISpecimenContext context, int count)

Parameters

context ISpecimenContext

The context used to resolve the type request.

count int

The number of objects to create.

Returns

IEnumerable<T>

A sequence of anonymous objects of type T.

Type Parameters

T

The type of objects to create.

Remarks

The CreateMany implementation always returns a new instance of `IEnumerable%601`. Even if IEnumerable<T> is Frozen by the `IFixture)` method or explicitly assigned with the `IFixture%2c%60%600)` method, the CreateMany method returns a new, independent instance of IEnumerable<T>.

However, you can change this behavior, for example by applying the `MapCreateManyToEnumerable` customization.

CreateMany<T>(IPostprocessComposer<T>, int)

Creates many anonymous objects.

public static IEnumerable<T> CreateMany<T>(this IPostprocessComposer<T> composer, int count)

Parameters

composer IPostprocessComposer<T>

The composer used to resolve the type request.

count int

The number of objects to create.

Returns

IEnumerable<T>

A sequence of anonymous objects of type T.

Type Parameters

T

The type of objects to create.

Remarks

The CreateMany implementation always returns a new instance of `IEnumerable%601`. Even if IEnumerable<T> is Frozen by the `IFixture)` method or explicitly assigned with the `IFixture%2c%60%600)` method, the CreateMany method returns a new, independent instance of IEnumerable<T>.

However, you can change this behavior, for example by applying the `MapCreateManyToEnumerable` customization.

The only purpose of this explicit overload is to support type inferencing.