Closed lonix1 closed 2 years ago
The Moq version differs from the NSubstitute version. When using the Moq version (DbContextMock), you're essentially creating a new Mock
NSubstitute works a little bit different as there we're inheriting from DbContext itself, so this version is probably disposable.
This being said, this library mocks everything, so in either variants, there's not much to clean up.
Sorry, I didn't mention I'm using NSubstitute. Thanks for the info.
Given your comment "...inheriting from DbContext itself", I'll assume it's good to dispose just to be sure - I imagine 1,000s of tests which aren't disposed, could be a problem, maybe, possibly.
What I'm interested to know - the real "heavy" resource in a context, which should be disposed, is the DbConnection. How is that represented - is it mocked / subclassed / etc.?
I don't have the resources to test this myself. If you have the time to test this, don't hesitate and report back. Meanwhile, I'll close this issue.
I would typically dispose any real context (in memory, sqlite, whatever) that I create in a test.
I'm not sure how this library's mock is implemented. Does it need to be disposed, or it is mocks-all-the-way-down?