Table of Contents

Class DataAttribute

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

Abstract attribute which represents a based implementation of IDataAttribute. Data source providers derive from this attribute and implement GetData(MethodInfo, DisposalTracker) to return the data for the theory.

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

Properties

Explicit

Sets a value that determines whether the data rows provided by this data provider should be considered explicit or not. If true, then the data rows will all be considered explicit; if false, then the data rows will all be considered not explicit; if unset, then the data rows will inherit their explicitness from Explicit.

public bool Explicit { get; set; }

Property Value

bool

ExplicitAsNullable

Gettable as a nullable value since .NET Framework does not permit attributes to have nullable value types for settable properties.

protected bool? ExplicitAsNullable { get; set; }

Property Value

bool?

Skip

Gets a skip reason for all the data rows provided by this data provider. If not null, then all rows will be skipped with the given reason; if null, then the rows will inherit their skip reason from Skip.

public string? Skip { get; set; }

Property Value

string

TestDisplayName

Gets the test display name for the test (replacing the default behavior, which would be to use DisplayName, or falling back to generating display names based on TestMethodDisplay and TestMethodDisplayOptions).

public string? TestDisplayName { get; set; }

Property Value

string

Timeout

Sets a value to determine if the data rows provided by this data provider should include a timeout (in milliseconds). If greater than zero, the data rows will have the given timeout; if zero or less, the data rows will not have a timeout; if unset, the data rows will inherit their timeout from Timeout.

public int Timeout { get; set; }

Property Value

int

TimeoutAsNullable

Gettable as a nullable value since .NET Framework does not permit attributes to have nullable value types for settable properties.

protected int? TimeoutAsNullable { get; set; }

Property Value

int?

Traits

Gets a set of traits for the associated data. The data is provided as an array of string values that are alternating keys and values (e.g., ["key1", "value1", "key2", "value2"]).

public string[]? Traits { get; set; }

Property Value

string[]

Remarks

This is structured as an array because attribute initializers don't support dictionaries. Note: Setting an odd number of values will throw away the unmatched key at the end of the list. If you seem to be missing your a key/value pair or have misaligned keys and values, make sure you have an even number of strings alternating between keys and values.

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 virtual 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 abstract 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 abstract bool SupportsDiscoveryEnumeration()

Returns

bool