NSubstitute
NSubstitute copied to clipboard
Support property getters with `When..Do` syntax
As raised in #449, it would be useful to support property getters in When..Do:
// Current syntax:
sub.When(x => { _ = x.Prop; }).DoNotCallBase();
// Proposed:
sub.When(x => x.MyProp).DoNotCallBase();
From @zvirja's comment:
public static WhenCalled<TSubstitute> When<TSubstitute, TResult>(
this TSubstitute substitute, Func<TSubstitute, TResult> substituteCall)
where TSubstitute: class
{
return SubstituteExtensions.When(substitute, x => substituteCall(x));
}
Need to ensure this does not conflict with the existing WhenCalled<T> When<T>(this T substitute, Func<T, Task> substituteCall) overload of this method.