Skip to content

Commit e8746f4

Browse files
authored
Renamed auto-data attributes (#3)
* Renamed auto arguments attribute * Renamed base auto data source attribute * Renamed class auto data attribute * Renamed member auto data attribute * Renamed base auto data-source attribute * Renamed auto data attribute * Refactored DataGeneratorMetadataHelper * Renamed dependency constraints tests to not reference xUnit 3 * Removed unused enumerable extensions * Removed redundant logo images * Removed unused value task extensions * Removed unused value task extensions * Refactored for clarity * Adjusted names of derived data source attributes * Renamed composite data source attribute * Renamed test types
1 parent 655911c commit e8746f4

File tree

62 files changed

+420
-577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+420
-577
lines changed

src/AutoFixture.TUnit/ArgumentsAutoDataAttribute.cs renamed to src/AutoFixture.TUnit/AutoArgumentsAttribute.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ namespace AutoFixture.TUnit;
99
/// </summary>
1010
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes",
1111
Justification = "This attribute is the root of a potential attribute hierarchy.")]
12-
public class ArgumentsAutoDataAttribute : AutoFixtureDataSourceAttribute
12+
public class AutoArgumentsAttribute : BaseDataSourceAttribute
1313
{
1414
/// <summary>
15-
/// Initializes a new instance of the <see cref="ArgumentsAutoDataAttribute" /> class.
15+
/// Initializes a new instance of the <see cref="AutoArgumentsAttribute" /> class.
1616
/// </summary>
1717
/// <param name="values">The data values to pass to the theory.</param>
18-
public ArgumentsAutoDataAttribute(params object?[] values)
18+
public AutoArgumentsAttribute(params object?[] values)
1919
: this(() => new Fixture(), values)
2020
{
2121
}
2222

2323
/// <summary>
24-
/// Initializes a new instance of the <see cref="ArgumentsAutoDataAttribute" /> class.
24+
/// Initializes a new instance of the <see cref="AutoArgumentsAttribute" /> class.
2525
/// </summary>
2626
/// <param name="fixtureFactory">The fixture factory.</param>
2727
/// <param name="values">The data values to pass to the theory.</param>
2828
/// <exception cref="ArgumentNullException"></exception>
29-
protected ArgumentsAutoDataAttribute(Func<IFixture> fixtureFactory, params object?[]? values)
29+
protected AutoArgumentsAttribute(Func<IFixture> fixtureFactory, params object?[]? values)
3030
{
3131
this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory));
3232
this.Values = values ?? [null];

src/AutoFixture.TUnit/ClassAutoDataAttribute.cs renamed to src/AutoFixture.TUnit/AutoClassDataSourceAttribute.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ namespace AutoFixture.TUnit;
1010
/// </summary>
1111
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes",
1212
Justification = "This attribute is the root of a potential attribute hierarchy.")]
13-
public class ClassAutoDataAttribute : AutoFixtureDataSourceAttribute
13+
public class AutoClassDataSourceAttribute : BaseDataSourceAttribute
1414
{
1515
/// <summary>
16-
/// Initializes a new instance of the <see cref="ClassAutoDataAttribute"/> class.
16+
/// Initializes a new instance of the <see cref="AutoClassDataSourceAttribute"/> class.
1717
/// </summary>
1818
/// <param name="sourceType">The type of the class that provides the data.</param>
1919
/// <param name="parameters">The parameters passed to the data provider class constructor.</param>
20-
public ClassAutoDataAttribute(Type sourceType, params object?[] parameters)
20+
public AutoClassDataSourceAttribute(Type sourceType, params object?[] parameters)
2121
: this(() => new Fixture(), sourceType, parameters)
2222
{
2323
}
2424

2525
/// <summary>
26-
/// Initializes a new instance of the <see cref="ClassAutoDataAttribute"/> class.
26+
/// Initializes a new instance of the <see cref="AutoClassDataSourceAttribute"/> class.
2727
/// </summary>
2828
/// <param name="fixtureFactory">The fixture factory that provides missing data from <paramref name="sourceType"/>.</param>
2929
/// <param name="sourceType">The type of the class that provides the data.</param>
@@ -38,7 +38,7 @@ public ClassAutoDataAttribute(Type sourceType, params object?[] parameters)
3838
/// The missing arguments for the test are being supplied from the Fixture instance.
3939
/// <code>
4040
/// [Test]
41-
/// [ClassAutoData(typeof(MyTestData))]
41+
/// [AutoClassDataSource(typeof(MyTestData))]
4242
/// public void ClassDataSuppliesExtraValues(int sum, int[] numbers, Person client)
4343
/// {
4444
/// var actual = numbers.Sum(x => x);
@@ -60,7 +60,7 @@ public ClassAutoDataAttribute(Type sourceType, params object?[] parameters)
6060
/// }
6161
/// </code>
6262
/// </example>
63-
protected ClassAutoDataAttribute(Func<IFixture> fixtureFactory, Type sourceType, params object?[] parameters)
63+
protected AutoClassDataSourceAttribute(Func<IFixture> fixtureFactory, Type sourceType, params object?[] parameters)
6464
{
6565
this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory));
6666
this.SourceType = sourceType ?? throw new ArgumentNullException(nameof(sourceType));

src/AutoFixture.TUnit/AutoDataAttribute.cs renamed to src/AutoFixture.TUnit/AutoDataSourceAttribute.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@ namespace AutoFixture.TUnit;
99
/// </summary>
1010
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes",
1111
Justification = "This attribute is the root of a potential attribute hierarchy.")]
12-
public class AutoDataAttribute : AutoFixtureDataSourceAttribute
12+
public class AutoDataSourceAttribute : BaseDataSourceAttribute
1313
{
1414
/// <summary>
15-
/// Initializes a new instance of the <see cref="AutoDataAttribute" /> class.
15+
/// Initializes a new instance of the <see cref="AutoDataSourceAttribute" /> class.
1616
/// </summary>
1717
/// <remarks>
1818
/// <para>
1919
/// This constructor overload initializes the <see cref="Fixture" /> to an instance of
2020
/// <see cref="Fixture" />.
2121
/// </para>
2222
/// </remarks>
23-
public AutoDataAttribute()
23+
public AutoDataSourceAttribute()
2424
: this(() => new Fixture())
2525
{
2626
}
2727

2828
/// <summary>
29-
/// Initializes a new instance of the <see cref="AutoDataAttribute" /> class
29+
/// Initializes a new instance of the <see cref="AutoDataSourceAttribute" /> class
3030
/// with the supplied <paramref name="fixtureFactory" />. Fixture will be created
3131
/// on demand using the provided factory.
3232
/// </summary>
3333
/// <param name="fixtureFactory">The fixture factory used to construct the fixture.</param>
34-
protected AutoDataAttribute(Func<IFixture> fixtureFactory)
34+
protected AutoDataSourceAttribute(Func<IFixture> fixtureFactory)
3535
{
3636
this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory));
3737
}
-14 KB
Binary file not shown.

src/AutoFixture.TUnit/MemberAutoDataAttribute.cs renamed to src/AutoFixture.TUnit/AutoMemberDataSourceAttribute.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,49 @@ namespace AutoFixture.TUnit;
1313
/// </summary>
1414
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes",
1515
Justification = "This attribute is the root of a potential attribute hierarchy.")]
16-
public class MemberAutoDataAttribute : AutoFixtureDataSourceAttribute
16+
public class AutoMemberDataSourceAttribute : BaseDataSourceAttribute
1717
{
1818
/// <summary>
19-
/// Initializes a new instance of the <see cref="MemberAutoDataAttribute" /> class.
19+
/// Initializes a new instance of the <see cref="AutoMemberDataSourceAttribute" /> class.
2020
/// </summary>
2121
/// <param name="memberName">The name of the public static member on the test class that will provide the test data.</param>
2222
/// <param name="parameters">The parameters for the member (only supported for methods; ignored for everything else).</param>
23-
public MemberAutoDataAttribute(string memberName, params object?[] parameters)
23+
public AutoMemberDataSourceAttribute(string memberName, params object?[] parameters)
2424
: this(() => new Fixture(), memberType: null, memberName, parameters)
2525
{
2626
}
2727

2828
/// <summary>
29-
/// Initializes a new instance of the <see cref="MemberAutoDataAttribute" /> class.
29+
/// Initializes a new instance of the <see cref="AutoMemberDataSourceAttribute" /> class.
3030
/// </summary>
3131
/// <param name="memberType">The type declaring the source member.</param>
3232
/// <param name="memberName">The name of the public static member on the test class that will provide the test data.</param>
3333
/// <param name="parameters">The parameters for the member (only supported for methods; ignored for everything else).</param>
34-
public MemberAutoDataAttribute(Type? memberType, string memberName, params object?[] parameters)
34+
public AutoMemberDataSourceAttribute(Type? memberType, string memberName, params object?[] parameters)
3535
: this(() => new Fixture(), memberType, memberName, parameters)
3636
{
3737
}
3838

3939
/// <summary>
40-
/// Initializes a new instance of the <see cref="MemberAutoDataAttribute" /> class.
40+
/// Initializes a new instance of the <see cref="AutoMemberDataSourceAttribute" /> class.
4141
/// </summary>
4242
/// <param name="fixtureFactory">The fixture factory delegate.</param>
4343
/// <param name="memberName">The name of the public static member on the test class that will provide the test data.</param>
4444
/// <param name="parameters">The parameters for the member (only supported for methods; ignored for everything else).</param>
45-
protected MemberAutoDataAttribute(Func<IFixture> fixtureFactory, string memberName, params object?[] parameters)
45+
protected AutoMemberDataSourceAttribute(Func<IFixture> fixtureFactory, string memberName, params object?[] parameters)
4646
: this(fixtureFactory, memberType: null, memberName, parameters)
4747
{
4848
}
4949

5050
/// <summary>
51-
/// Initializes a new instance of the <see cref="MemberAutoDataAttribute" /> class.
51+
/// Initializes a new instance of the <see cref="AutoMemberDataSourceAttribute" /> class.
5252
/// </summary>
5353
/// <param name="fixtureFactory">The fixture factory delegate.</param>
5454
/// <param name="memberType">The type declaring the source member.</param>
5555
/// <param name="memberName">The name of the public static member on the test class that will provide the test data.</param>
5656
/// <param name="parameters">The parameters for the member (only supported for methods; ignored for everything else).</param>
5757
/// <exception cref="ArgumentNullException">Thrown when arguments are null.</exception>
58-
protected MemberAutoDataAttribute(Func<IFixture> fixtureFactory, Type? memberType, string memberName, params object?[]? parameters)
58+
protected AutoMemberDataSourceAttribute(Func<IFixture> fixtureFactory, Type? memberType, string memberName, params object?[]? parameters)
5959
{
6060
this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory));
6161
this.MemberName = memberName ?? throw new ArgumentNullException(nameof(memberName));

src/AutoFixture.TUnit/AutoFixtureDataSourceAttribute.cs renamed to src/AutoFixture.TUnit/BaseDataSourceAttribute.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@ namespace AutoFixture.TUnit;
55
/// <summary>
66
/// Base class for data sources that provide AutoFixture test data for TUnit data driven tests.
77
/// </summary>
8-
public abstract class AutoFixtureDataSourceAttribute : NonTypedDataSourceGeneratorAttribute, IDataSource
8+
public abstract class BaseDataSourceAttribute : NonTypedDataSourceGeneratorAttribute, IDataSource
99
{
1010
/// <summary>
1111
/// Returns the test data provided by the source.
1212
/// </summary>
13-
/// <param name="dataGeneratorMetadata"></param>
14-
/// <returns></returns>
13+
/// <param name="dataGeneratorMetadata">
14+
/// The metadata for the target method for which to provide the arguments.
15+
/// </param>
16+
/// <returns>
17+
/// Returns a sequence of argument collections, where each collection
18+
/// is an array of objects representing the arguments for a test method.
19+
/// </returns>
1520
public abstract IEnumerable<object?[]?> GetData(DataGeneratorMetadata dataGeneratorMetadata);
1621

1722
/// <inheritdoc />
1823
public override IEnumerable<Func<object?[]>> GenerateDataSources(DataGeneratorMetadata dataGeneratorMetadata)
1924
{
20-
if (dataGeneratorMetadata is null)
21-
{
22-
throw new ArgumentNullException(nameof(dataGeneratorMetadata));
23-
}
25+
if (dataGeneratorMetadata is null) throw new ArgumentNullException(nameof(dataGeneratorMetadata));
2426

2527
return GetTestDataEnumerable();
2628

@@ -35,22 +37,15 @@ public abstract class AutoFixtureDataSourceAttribute : NonTypedDataSourceGenerat
3537
}
3638

3739
var enumerable = this.GetData(dataGeneratorMetadata)
38-
?? throw new InvalidOperationException("The source member yielded no test data.");
40+
?? throw new InvalidOperationException("The source member yielded no test data.");
3941

4042
foreach (var testData in enumerable)
4143
{
42-
if (testData is null)
43-
{
44-
throw new InvalidOperationException("The source member yielded a null test data.");
45-
}
46-
47-
if (testData.Length > parameters.Length)
48-
{
49-
throw new InvalidOperationException("The number of arguments provided exceeds the number of parameters.");
50-
}
44+
if (testData is null) throw new InvalidOperationException("The source member yielded a null test data.");
45+
if (testData.Length > parameters.Length) throw new InvalidOperationException("The number of arguments provided exceeds the number of parameters.");
5146

5247
yield return () => testData;
5348
}
5449
}
5550
}
56-
}
51+
}

src/AutoFixture.TUnit/CompositeDataAttribute.cs renamed to src/AutoFixture.TUnit/CompositeDataSourceAttribute.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@ namespace AutoFixture.TUnit;
88
/// </summary>
99
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes",
1010
Justification = "This attribute is the root of a potential attribute hierarchy.")]
11-
public class CompositeDataAttribute : AutoFixtureDataSourceAttribute
11+
public class CompositeDataSourceAttribute : BaseDataSourceAttribute
1212
{
13-
private readonly AutoFixtureDataSourceAttribute[] attributes;
13+
private readonly BaseDataSourceAttribute[] attributes;
1414

1515
/// <summary>
16-
/// Initializes a new instance of the <see cref="CompositeDataAttribute"/> class.
16+
/// Initializes a new instance of the <see cref="CompositeDataSourceAttribute"/> class.
1717
/// </summary>
1818
/// <param name="attributes">The attributes representing a data source for a data theory.</param>
19-
public CompositeDataAttribute(IEnumerable<AutoFixtureDataSourceAttribute> attributes)
20-
: this(attributes as AutoFixtureDataSourceAttribute[] ?? attributes.ToArray())
19+
public CompositeDataSourceAttribute(IEnumerable<BaseDataSourceAttribute> attributes)
20+
: this(attributes as BaseDataSourceAttribute[] ?? attributes.ToArray())
2121
{
2222
}
2323

2424
/// <summary>
25-
/// Initializes a new instance of the <see cref="CompositeDataAttribute"/> class.
25+
/// Initializes a new instance of the <see cref="CompositeDataSourceAttribute"/> class.
2626
/// </summary>
2727
/// <param name="attributes">The attributes representing a data source for a data theory.</param>
28-
public CompositeDataAttribute(params AutoFixtureDataSourceAttribute[] attributes)
28+
public CompositeDataSourceAttribute(params BaseDataSourceAttribute[] attributes)
2929
{
3030
this.attributes = attributes ?? throw new ArgumentNullException(nameof(attributes));
3131
}
3232

3333
/// <summary>
3434
/// Gets the attributes supplied through one of the constructors.
3535
/// </summary>
36-
public IReadOnlyList<AutoFixtureDataSourceAttribute> Attributes => Array.AsReadOnly(this.attributes);
36+
public IReadOnlyList<BaseDataSourceAttribute> Attributes => Array.AsReadOnly(this.attributes);
3737

3838
/// <inheritdoc />
3939
public override IEnumerable<object?[]> GetData(DataGeneratorMetadata dataGeneratorMetadata)

src/AutoFixture.TUnit/CustomizeAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace AutoFixture.TUnit;
44

55
/// <summary>
66
/// Base class for customizing parameters in methods decorated with
7-
/// <see cref="AutoDataAttribute"/>.
7+
/// <see cref="AutoDataSourceAttribute"/>.
88
/// </summary>
99
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)]
1010
public abstract class CustomizeAttribute : Attribute, IParameterCustomizationSource

src/AutoFixture.TUnit/FavorArraysAttribute.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace AutoFixture.TUnit;
55

66
/// <summary>
7-
/// An attribute that can be applied to parameters in an <see cref="AutoDataAttribute"/>-driven
7+
/// An attribute that can be applied to parameters in an <see cref="AutoDataSourceAttribute"/>-driven
88
/// Theory to indicate that the parameter value should be created using a constructor with one
99
/// or more array arguments, if applicable.
1010
/// </summary>
@@ -22,10 +22,7 @@ public sealed class FavorArraysAttribute : CustomizeAttribute
2222
/// </returns>
2323
public override ICustomization GetCustomization(ParameterInfo parameter)
2424
{
25-
if (parameter is null)
26-
{
27-
throw new ArgumentNullException(nameof(parameter));
28-
}
25+
if (parameter is null) throw new ArgumentNullException(nameof(parameter));
2926

3027
return new ConstructorCustomization(parameter.ParameterType, new ArrayFavoringConstructorQuery());
3128
}

src/AutoFixture.TUnit/FavorEnumerablesAttribute.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace AutoFixture.TUnit;
55

66
/// <summary>
7-
/// An attribute that can be applied to parameters in an <see cref="AutoDataAttribute"/>-driven
7+
/// An attribute that can be applied to parameters in an <see cref="AutoDataSourceAttribute"/>-driven
88
/// Theory to indicate that the parameter value should be created using a constructor with one
99
/// or more <see cref="IEnumerable{T}" /> arguments, if applicable.
1010
/// </summary>
@@ -22,10 +22,7 @@ public sealed class FavorEnumerablesAttribute : CustomizeAttribute
2222
/// </returns>
2323
public override ICustomization GetCustomization(ParameterInfo parameter)
2424
{
25-
if (parameter == null)
26-
{
27-
throw new ArgumentNullException(nameof(parameter));
28-
}
25+
if (parameter is null) throw new ArgumentNullException(nameof(parameter));
2926

3027
return new ConstructorCustomization(parameter.ParameterType, new EnumerableFavoringConstructorQuery());
3128
}

0 commit comments

Comments
 (0)