AutoFakeItEasyDataAttribute populates complex objects with test data but customized fixture won't

86 Views Asked by At

I have a complex object several levels deep. Marking my Xunit theory with this custom attribute and passing the complex object to the method as a parameter populates all the properties with test data nicely.

[AttributeUsage(AttributeTargets.Method)]
public class AutoFakeItEasyDataAttribute : AutoDataAttribute
{
    public AutoFakeItEasyDataAttribute() : base(() 
        => new Fixture().Customize(new AutoFakeItEasyCustomization()))
    {
    }
}

/////////////////////////

[Theory]
[AutoFakeItEasyData]
public void TestSomething(MyComplexObject obj)
{
   // obj properties are all populated with faked data
}

But when I create a class with a fixture such as:

var fixture = new Fixture().Customize(new AutoFakeItEasyCustomization());

and call:

var obj = fixture.Create<MyComplexObject>();

The object's properties are all null. How can I get the fixture to populate the object automatically with test data like above without writing a custom factory?

0

There are 0 best solutions below