-
-
Notifications
You must be signed in to change notification settings - Fork 403
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
Enable unit testing of data portal operation methods #1736
Comments
If I have to test through the server-side |
In that case the easiest solution is probably to have people directly create and use a server-side data portal instance - just skip all the complexity of everything prior. Or even simpler, have a |
Completely agree. I think the right thing is to still go through the |
Yeah, but some other things happen in the client-side data portal too (like |
I guess :). Personally, I'm not that concerned about that, but that's my own view. If I test a controller, I don't necessarily care if any middleware was configured that may change things at runtime. I only care that I can create the controller (with anything passed in on the constructor if needed) and call the method. |
FWIW, when we're uniting testing our business classes, as assume Csla will do the right thing. We're already configuring a mock container as part of test initialization, and that mock container gets accessed through something like a service locator which is how we're currently resolving dependencies to our BOs (they do contianer.GetInstance for example). As long as we can tell Csla "use this thing to resolve dependencies" easily, that'd be enough I think. We generally want things go start via the DataPortal.Fetch/FetchAsync so we know everything works as it should. We'll test for things like IsNew is false after a fetch, to make sure we didn't goof and do something outside of a BypassPropertyChecks, for example. |
I too have been thinking about testability today. I was imagining that we might create a TestDataPortal class to help developers who use CSLA to test their code. TestDataPortal would implement the new IDataPortal and possibly IChildDataPortal interfaces and allow passing of parameters that are required into the underlying data access method. An alternative is two classes, the second of which implements IChildDataPortal. These test data portals would do the minimum possible amount of work. However, they do need to continue to support matching of parameters to the most appropriate of available data access methods, plus also providing some support for injection of parameters using the Inject attribute. We could perhaps offer the injection capability using a very lightweight DI that is compatible with testing, by accepting a collection of already instantiated objects as additional parameters. We want code that calls into the dataportal to be code-compatible, but as simple to use as possible, without the need to bootstrap a full DI container, so that it can be tested. I think that is easier now that DataPortal is instantiated, and implements an interface that is used by consuming code. The problem with the need to use DI for testing is that it makes it harder to cover different scenarios with the minimum of overhead. Having different tests receive different instances of DAL/repository objects, for example, is more difficult using a complex (and single) DI container. |
I think the existing CSLA 8+ DI and data portal features support testing adequately, and I'm closing this issue. |
From @JasonBock in gitter
Response:
I understand what you want, and I'm talking through the practicalities of making it happen.
The text was updated successfully, but these errors were encountered: