Class AutoClassDataSourceAttribute
Namespace: AutoFixture.TUnit
Assembly: AutoFixture.TUnit.dll
Provides a data source for a data theory, with the data coming from a class that yields test cases in any shape supported by TUnit MethodDataSource (for example IEnumerable<object?[]>, IEnumerable<T>, or tuples), combined with auto-generated data specimens generated by AutoFixture.
public class AutoClassDataSourceAttribute : BaseDataSourceAttribute, IDataSourceAttribute, IDataSourceInheritance
object ← Attribute ← BaseDataSourceAttribute ← AutoClassDataSourceAttribute
Derived
AutoClassDataSourceAttribute<T>
Implements
IDataSourceAttribute, IDataSource
Inherited Members
BaseDataSourceAttribute.GetData(DataGeneratorMetadata), BaseDataSourceAttribute.GetDataRowsAsync(DataGeneratorMetadata), BaseDataSourceAttribute.SkipIfEmpty, BaseDataSourceAttribute.DeferEnumeration, Attribute.GetCustomAttributes(MemberInfo, Type), Attribute.GetCustomAttributes(MemberInfo, Type, bool), Attribute.GetCustomAttributes(MemberInfo), Attribute.GetCustomAttributes(MemberInfo, bool), Attribute.IsDefined(MemberInfo, Type), Attribute.IsDefined(MemberInfo, Type, bool), Attribute.GetCustomAttribute(MemberInfo, Type), Attribute.GetCustomAttribute(MemberInfo, Type, bool), Attribute.GetCustomAttributes(ParameterInfo), Attribute.GetCustomAttributes(ParameterInfo, Type), Attribute.GetCustomAttributes(ParameterInfo, Type, bool), Attribute.GetCustomAttributes(ParameterInfo, bool), Attribute.IsDefined(ParameterInfo, Type), Attribute.IsDefined(ParameterInfo, Type, bool), Attribute.GetCustomAttribute(ParameterInfo, Type), Attribute.GetCustomAttribute(ParameterInfo, Type, bool), Attribute.GetCustomAttributes(Module, Type), Attribute.GetCustomAttributes(Module), Attribute.GetCustomAttributes(Module, bool), Attribute.GetCustomAttributes(Module, Type, bool), Attribute.IsDefined(Module, Type), Attribute.IsDefined(Module, Type, bool), Attribute.GetCustomAttribute(Module, Type), Attribute.GetCustomAttribute(Module, Type, bool), Attribute.GetCustomAttributes(Assembly, Type), Attribute.GetCustomAttributes(Assembly, Type, bool), Attribute.GetCustomAttributes(Assembly), Attribute.GetCustomAttributes(Assembly, bool), Attribute.IsDefined(Assembly, Type), Attribute.IsDefined(Assembly, Type, bool), Attribute.GetCustomAttribute(Assembly, Type), Attribute.GetCustomAttribute(Assembly, Type, bool), Attribute.Equals(object?), Attribute.GetHashCode(), Attribute.Match(object?), Attribute.IsDefaultAttribute(), Attribute.TypeId, object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Constructors
AutoClassDataSourceAttribute(Type, params object?[])
Initializes a new instance of the AutoClassDataSourceAttribute class.
public AutoClassDataSourceAttribute(Type sourceType, params object?[] parameters)Parameters
sourceType Type
The type of the class that provides the data.
parameters object?[]
The parameters passed to the data provider class constructor.
AutoClassDataSourceAttribute(Func<IFixture>, Type, params object?[])
Initializes a new instance of the AutoClassDataSourceAttribute class.
protected AutoClassDataSourceAttribute(Func<IFixture> fixtureFactory, Type sourceType, params object?[] parameters)Parameters
fixtureFactory Func<IFixture>
The fixture factory that provides missing data from sourceType.
sourceType Type
The type of the class that provides the data.
parameters object?[]
The parameters passed to the data provider class constructor.
Examples
In the following example MyTestData is a class that provides test data, that would be complicated or probably impossible to provide using other options. The missing arguments for the test are being supplied from the Fixture instance.
[Test]
[AutoClassDataSource(typeof(MyTestData))]
public void ClassDataSuppliesExtraValues(int sum, int[] numbers, Person client)
{
var actual = numbers.Sum(x => x);
Assert.Equal(sum, actual);
Assert.NotNull(client);
}
private class MyTestData : IEnumerable<object?[]>
{
public IEnumerator<object?[]> GetEnumerator()
{
yield return [0, []];
yield return [4, [1, 2, 1]];
yield return [23, [0, 13, 15, -5]];
}
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
}
Properties
FixtureFactory
Gets the fixture factory that provides the missing data from SourceType.
public Func<IFixture> FixtureFactory { get; }Property Value
Func<IFixture>
Parameters
Gets the constructor parameters for SourceType.
public object?[] Parameters { get; }Property Value
object?[]
SourceType
Gets the type of the class that provides the data.
public Type SourceType { get; }Property Value
Methods
GetData(DataGeneratorMetadata)
Returns the test data provided by the source.
public override IAsyncEnumerable<Func<Task<object?[]?>>> GetData(DataGeneratorMetadata dataGeneratorMetadata)Parameters
dataGeneratorMetadata DataGeneratorMetadata
The metadata for the target method for which to provide the arguments.
Returns
IAsyncEnumerable<Func<Task<object?[]?>>>
Returns a sequence of argument collections, where each collection is an array of objects representing the arguments for a test method.