Table of Contents

Class MemberDataAttributeBase

Namespace
Xunit.v3
Assembly
xunit.v3.core.dll

Provides a base class for attributes that will provide member data.

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public abstract class MemberDataAttributeBase : DataAttribute, IDataAttribute
Inheritance
MemberDataAttributeBase
Implements
Derived
Inherited Members

Constructors

MemberDataAttributeBase(string, object?[])

Provides a base class for attributes that will provide member data.

protected MemberDataAttributeBase(string memberName, object?[] arguments)

Parameters

memberName string

The name of the public static member on the test class that will provide the test data It is recommended to use the nameof operator to ensure compile-time safety, e.g., nameof(SomeMemberName).

arguments object[]

The arguments to be passed to the member (only supported for methods; ignored for everything else)

Properties

Arguments

Gets or sets the arguments passed to the member. Only supported for static methods.

public object?[] Arguments { get; }

Property Value

object[]

DisableDiscoveryEnumeration

Returns true if the data attribute wants to skip enumerating data during discovery. This will cause the theory to yield a single test case for all data, and the data discovery will be during test execution instead of discovery.

public bool DisableDiscoveryEnumeration { get; set; }

Property Value

bool

MemberName

Gets the member name.

public string MemberName { get; }

Property Value

string

MemberType

Gets or sets the type to retrieve the member from. If not set, then the member will be retrieved from the unit test class.

public Type? MemberType { get; set; }

Property Value

Type

Methods

ConvertDataRow(object)

Converts an item yielded by the data attribute to an ITheoryDataRow, for return from GetData(MethodInfo, DisposalTracker). Items yielded will typically be object[], ITheoryDataRow, or System.Runtime.CompilerServices.ITuple, but this override will allow derived attribute types to support additional data items. If the data item cannot be converted, this method will throw ArgumentException.

protected override ITheoryDataRow ConvertDataRow(object dataRow)

Parameters

dataRow object

An item yielded from the data member.

Returns

ITheoryDataRow

An ITheoryDataRow suitable for return from GetData(MethodInfo, DisposalTracker).

Exceptions

ArgumentException

Thrown when dataRow does not point to a valid data row (must be compatible with object[] or ITheoryDataRow).

GetData(MethodInfo, DisposalTracker)

Returns the data to be used to test the theory.

public override ValueTask<IReadOnlyCollection<ITheoryDataRow>> GetData(MethodInfo testMethod, DisposalTracker disposalTracker)

Parameters

testMethod MethodInfo

The test method the data attribute is attached to

disposalTracker DisposalTracker

The disposal tracker used to dispose the data

Returns

ValueTask<IReadOnlyCollection<ITheoryDataRow>>

SupportsDiscoveryEnumeration()

Returns true if the data attribute supports enumeration during discovery; false otherwise. Data attributes with expensive computational costs and/or randomized data sets should return false.

public override bool SupportsDiscoveryEnumeration()

Returns

bool