I currently have a class called ExampleViewModelAttribute which derives from TestViewModelDataAttribute which is class derived from AutoDataAttribute class.
public class TestViewModelDataAttribute : AutoDataAttribute
{
public TestViewModelDataAttribute()
: this(new Fixture())
{
}
public TestViewModelDataAttribute(IFixture fixture)
: base(fixture)
{
Fixture.Customize(new ViewModelsCustomization());
Fixture.Inject(Fixture);
}
}
public class ExampleViewModelAutoDataAttribute : TestViewModelAutoDataAttribute
{
public ExampleViewModelAutoDataAttribute()
{
var someExampleMock = Fixture.Create<Mock<ISomeExampleMock>>();
Fixture.Inject(someExampleMock);
}
}
My problem, is I keep getting a warning "Fixture is created lazily for the performance efficiency, so this property is deprecated as it activates the fixture immediately. " + "If you need to customize the fixture, do that in the factory method passed to the constructor."
How can I fix this warning? I want to inject the mock classes in the fixture, I only got one answer that helps me fix the base class warning but I need to fix injecting the mock classes as well.
Fix for base class
public class TestViewModelDataAttribute : AutoDataAttribute
{
public TestViewModelDataAttribute() : base(() =>
{
var fixture = new Fixture().Customize(new CompositeCustomization(
new AutoMoqCustomization(),
new SupportMutableValueTypesCustomization()));
return fixture;
})
{
}
}
which I got from the following answer When setting up a custom AutoDataAttribute for auto mocking, what's the proper syntax to tell AutoFixture to ignore all recursive structures?
But since I use a property of Fixture in the derived class I still get errors. How should I fix this? Thanks