NSubstitute icon indicating copy to clipboard operation
NSubstitute copied to clipboard

Support property getters with `When..Do` syntax

Open dtchepak opened this issue 6 years ago • 1 comments

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.

dtchepak avatar Feb 03 '19 21:02 dtchepak