You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
System.NotSupportedException : Unsupported expression: x => x.TryGetValue<string>("Test", value)
Expected result:
System.NotSupportedException : Can't mock call to CacheExtensions.TryGetValue extension method.
The issue is that this extension method has same name and parameters set as the one from the interface and it's not clear what's wrong with Setup when just looking into the code.
The text was updated successfully, but these errors were encountered:
I agree that the suggested error message would be more helpful than the current one. Feel free to submit a PR. Extra points if the code generating the error message can be set up in such a way that we can easily extend it to also provide a descriptive error for other types of non-overridable methods (e.g. static or sealed methods).
After trying to implement it, I have found the Quard.IsOverridable(MethodInfo method, Expression expression) method and realized I didn't noticed a seccond line of the message with a hint.
So Actual result I have mentioned in the issue should be like this:
System.NotSupportedException: Unsupported expression: x => x.TryGetValue<string>("Test", value)
Extension methods (here: CacheExtensions.TryGetValue) may not be used in setup / verification expressions.
I am glad you found this out. I vaguely remembered that we already have a more precise exception message re: extension methods somewhere but I didn't realise it would show up in your scenario.
Steps to reproduce
Trying to mockick
IMemoryCache
like this:Actual result:
Expected result:
The issue is that this extension method has same name and parameters set as the one from the interface and it's not clear what's wrong with Setup when just looking into the code.
The text was updated successfully, but these errors were encountered: