csla icon indicating copy to clipboard operation
csla copied to clipboard

Allow DbContextManager to manage existing DbContext

Open PushOrigin opened this issue 9 years ago • 3 comments

I have found it useful in unit tests to use Moq to mock DbContext. In order to make this work I added two additional DbContextManager.GetManager methods with signatures that take an existing DbContext rather than wrapping an ObjectContext.

I can submit a pull request with the changes if you think it would be useful to include this in DbContextManager. Let me know.

Here is the gist of what I added: https://gist.github.com/PushOrigin/43e21a5f9556a4a8a9ac5d4c7382877e

PushOrigin avatar Feb 28 '17 16:02 PushOrigin

I understand the value from a testing perspective.

My concern is opening the door to something that breaks composability. The primary (really only) value of the context manager family of types is that they abstract away the entire idea of opening a new connection/context or using a pre-existing one.

As soon as someone includes code that opens or uses an existing connection/context in their business app then they might as well not use the context manager helpers provided by CSLA, because they are obviously using some other mechanism to manage the creation and flow of their connection object.

rockfordlhotka avatar Mar 01 '17 03:03 rockfordlhotka

That makes sense. It fits my needs for now, just thought I'd offer it if it was useful.

I've been able to accomplish what I want so far although it's much easier to just create integration tests. I'm struggling with the balance between unit/integration testing. It seems like DbContext is right at the tipping point.

PushOrigin avatar Mar 01 '17 12:03 PushOrigin

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Aug 15 '22 00:08 github-actions[bot]