Can I instruct AutoFixture to fill also private properties, annotated with a specific attribute such as Ninject.Inject
, of all classes? The source seems to scan for public properties only: 1. This question provides a solution for specific MyClass
with private setter, but not for private property or all classes: 2.
I'm using Moq to mock the services and in the end I'd like to fill the properties with those mocks. The following setup works fine if I expose the MyService dependency as public
.
Some example code:
public class MyController {
[Inject]
private IMyService MyService { get; set; }
public void AMethodUsingMyService() {
MyService.DoSomething();
// ...
}
// ...
}
public class MyService : IMyService {
public void DoSomething()
{
// ...
}
// ...
}
public class MyControllerTest {
[Theory]
[AutoMoqData]
public void MyTest(MyController controller) {
controller.AMethodUsingMyService();
}
}
private
s (and it shouldnt as covered in 'Mark's answer). Really really don't do that – Phonicprivate
s works fine as long as you instruct Ninject to inject them (InjectNonPublic
). I agree with Mark's answer! – Penneypenni