0

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?

W. Young
  • 357
  • 7
  • 18
  • I am unable to reproduce your issue. Can you provide a minimum reproducible example, with the listing for the type you're trying to generate? – Andrei Ivascu Apr 18 '23 at 09:03

0 Answers0