How to MOQ object in call chain?

249 Views Asked by At

Using Moq is there a way to mock an object that exists in the call chain of the system under test?

So in my test:

var x = mock.Create<ISystemUnderTest>();
var result = x.DoSomething();

Then in my system under test:

public Person User => return new Person(){ Name="Smithy" };

public string DoSomething(){
   var x = User.Name; // I want to use a mock instance here of User
}

Can I mock User when it's not being provided as a parameter? But just a member of the call chain?

0

There are 0 best solutions below