Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify something for each item in a list #1354

Open
Flatscha opened this issue Jul 27, 2023 · 2 comments
Open

Verify something for each item in a list #1354

Flatscha opened this issue Jul 27, 2023 · 2 comments
Labels

Comments

@Flatscha
Copy link

I am trying to write an extension method for Mock 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?

@kzu kzu added the question label Aug 4, 2023
@kzu
Copy link
Contributor

kzu commented Aug 4, 2023

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.

@Flatscha
Copy link
Author

Flatscha commented Aug 5, 2023

Unfortunately I already tried that and it doesn't change anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants