Verify something for each item in a list
I am trying to write an extension method for Mock<T> to verify a call to every item in a list.
My extension:
public static void VerifyMultiple<T, TItem>(this Mock<T> value, Action<T, TItem> action, Times times, IEnumerable<TItem> items) where T : class { foreach (var item in items) { value.Verify(x => action(x, item), times); } }
Example call:
this._mockDAL.VerifyMultiple((x,i) => x.Save(i), Times.Once(), items);
But I get the error System.NotSupportedException: 'Unsupported expression: x'
I unfortunately do not know what is wrong with that call or why this exception is thrown Can somebody explain?
Make your action parameter an Expression<Action<T, TItem>> instead? That's the type Mock<T>.Verify receives and is that makes it possible to inspect which mock member invocation to verify.
Unfortunately I already tried that and it doesn't change anything.
Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.
Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.
This issue will now be closed since it has been labeled 'stale' without activity for 30 days.
