JasperFx / marten

.NET Transactional Document DB and Event Store on PostgreSQL
https://martendb.io
MIT License
2.79k stars 441 forks source link

mock FirstOrDefaultAsync for unit test #3303

Closed brucesun closed 1 month ago

brucesun commented 1 month ago

hi, we was using marten 5 in our application and we have IMartenQueryable interface mocked so we can pass the code execution of documentSession.Query().FirstOrDefaultAsync() in the unit test. recently we trying to upgrade to marten 7, apparently FirstOrDefaultAsync is moved from IMartenQueryable interface into the extension method of MartenLinqQueryable which cannot be mocked.

is there any suggestion from marten development community on unit test mocking when moving to marten7? is there real need to move these methods out of IMartenQueryable interface, is it possible to move them back in future release for the ease of unit test?

thanks

jeremydmiller commented 1 month ago

Hey, please use Discord for questions instead of GitHub issues if you don't mind.

And I very, very strongly recommend against ever trying to mock the LINQ support in unit tests. Either do some kind of separation in code so you don't need that, or use integration tests.