I am using AutoFixture with AutoMoq. I am trying to create a fake instance of a class that has a property with a getter, but without a setter. I expect AutoFixture to customize the layout so that it returns the given value, even if there is no customizer.
My code looks something like this:
var data = new List<Data>() { new Data() }; var userManager = fixture.Build<IRepository>()
Unfortunately, method āCā does not work in this case, because auto fixture says that Data does not have any setter, so I have to set the value after that by directly invoking the layout.
Is there any way auto fixture can do this on its own, so I don't need the last line of code?
Edit: I made a mistake, the sample code does not work. It should be
var data = new List<Data>() { new Data() }; var userManager = fixture.CreateAnonymous<IRepository>(); Mock.Get(userManager).Setup(x => x.Data).Returns(data)
However, it would be nice if there was a method with a fake instance.
source share