Class InlineAutoDataAttribute

Namespace: AutoFixture.Xunit
Assembly: AutoFixture.Xunit.dll

Provides a data source for a data theory, with the data coming from inline values combined with auto-generated data specimens generated by AutoFixture.

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
[CLSCompliant(false)]
public class InlineAutoDataAttribute : CompositeDataAttribute

Inheritance

DataAttribute ← CompositeDataAttributeInlineAutoDataAttribute

Inherited Members

CompositeDataAttribute.GetData(MethodInfo, Type[]), CompositeDataAttribute.Attributes

Constructors

InlineAutoDataAttribute(params object[])

Initializes a new instance of the InlineAutoDataAttribute class.

public InlineAutoDataAttribute(params object[] values)

Parameters

values object[]

The data values to pass to the theory.

InlineAutoDataAttribute(DataAttribute, params object[])

Initializes a new instance of the InlineAutoDataAttribute class.

protected InlineAutoDataAttribute(DataAttribute autoDataAttribute, params object[] values)

Parameters

autoDataAttribute DataAttribute

An DataAttribute.

values object[]

The data values to pass to the theory.

Examples

In this example, TheAnswer is a Customization that changes all 32-bit integer values to 42. This behavior is encapsulated in MyCustomAutoDataAttribute, and transitively in MyCustomInlineAutoDataAttribute. A parameterized test demonstrates how it can be used.

[Theory]
[MyCustomInlineAutoData(1337)]
[MyCustomInlineAutoData(1337, 7)]
[MyCustomInlineAutoData(1337, 7, 42)]
public void CustomInlineDataSuppliesExtraValues(int x, int y, int z)
{
    Assert.Equal(1337, x);
    // y can vary, so we can't express any meaningful assertion for it.
    Assert.Equal(42, z);
}

private class MyCustomInlineAutoDataAttribute : InlineAutoDataAttribute
{
    public MyCustomInlineAutoDataAttribute(params object[] values) :
        base(new MyCustomAutoDataAttribute(), values)
    {
    }
}

private class MyCustomAutoDataAttribute : AutoDataAttribute
{
    public MyCustomAutoDataAttribute() :
        base(() => new Fixture().Customize(new TheAnswer()))
    {
    }

    private class TheAnswer : ICustomization
    {
        public void Customize(IFixture fixture)
        {
            fixture.Inject(42);
        }
    }
}

Remarks

This constructor overload exists to enable a derived attribute to supply a custom `DataAttribute` that again may contain custom behavior.

Properties

AutoDataAttribute

Gets the attribute used to automatically generate the remaining theory parameters, which are not fixed.

public DataAttribute AutoDataAttribute { get; }

Property Value

DataAttribute

Values

Gets the data values to pass to the theory.

public IEnumerable<object> Values { get; }

Property Value

IEnumerable<object>