-
-
Notifications
You must be signed in to change notification settings - Fork 794
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
ArgumentNullException when verifying method call on EF Core mocked DbContext when the method has not been actually invoked but some DbSet setter has #741
Comments
Got bit by this bug in a recent unit test mocking the Remove() method attempting to verify that the "Remove()" method on an EF Core DbContext object was not called (Times.Never). Thanks @MichaelSagalovich for being so thorough in your reproduction of the issue! |
Btw. for those using EF Core, you might be better off using EF Core's in-memory database provider and testing against that, instead of mocking a live |
Thanks @stakx; in light of this issue our team will definitely consider using it instead. |
...by only showing the first 10 items of enumerables for certain safe collection types (arrays and `List<T>`). It cannot be generally assum- ed that `IEnumerable` actually work. I cannot easily add the test case provided in devlooped#741 to the regression test suite as it relies on EF Core, and the test project already uses EF, so we'd likely have type conflicts if both of them are referenced.
...by only showing the first 10 items of enumerables for certain safe collection types (arrays and `List<T>`). It cannot be generally assum- ed that `IEnumerable` actually work. I cannot easily add the test case provided in devlooped#741 to the regression test suite as it relies on EF Core, and the test project already uses EF, so we'd likely have type conflicts if both of them are referenced.
...by only showing the first 10 items of enumerables for certain safe collection types (arrays and `List<T>`). It cannot be generally assum- ed that `IEnumerable` actually work. I cannot easily add the test case provided in devlooped#741 to the regression test suite as it relies on EF Core, and the test project already uses EF, so we'd likely have type conflicts if both of them are referenced.
...by only showing the first 10 items of enumerables for certain safe collection types (arrays and `List<T>`). It cannot be generally assum- ed that `IEnumerable` actually work. I cannot easily add the test case provided in #741 to the regression test suite as it relies on EF Core, and the test project already uses EF, so we'd likely have type conflicts if both of them are referenced.
I reproduced the issue here, and probably that's enough to understand it: https://github.com/MichaelSagalovich/MoqEntityFrameworkIssueReproduction
Formal Steps:
Expected:
4. Descriptive message that no expected invocation has been made, listing all invocations actually made
Actual:
4. ArgumentNullException.
As far as I see, this is caused by Moq trying to 'textualize' all invocations and EF not being able to provide a textual description of its property if not properly configured.
Suggestion: handle exceptions in Invocation.ToString to ensure that a correct verification exception is thrown and an as valid as possible message is still displayed. The issue is wider than just EF Core mocking, as can happen in multiple similar situations.
The text was updated successfully, but these errors were encountered: