I'm using the WebFormsMvp framework to do TDD while developing a DNN Module (DNN 6.1).
I'm following the most recent tutorials I can find, but have run into issues with DNN's ModuleInstanceContext class. E.g., if I try to call ModuleContext.EditUrl in my presenter, unit tests fail (running the module for real doesn't fail) because the ModuleInstanceContext has dependencies that resolve to a concrete instance of HttpContext and/or want to make actual Db calls (to fetch PortalAlias and the like).
Is there a best practice within the DNN community for unit testing when calls to methods on the ModuleInstanceContext are necessary?
In those cases, I've created an NavigationService
class which I initialize with the context in the presenter's constructor. For example:
public MyPresenter(IMyView view) : this(view, null) {}
internal MyPresenter(IMyView view, INavService navService) {
this.navService = navService ?? new DnnNavService(this.ModuleContext);
}
If I need to access the querystring from the navigation service, it's not initialized yet in the constructor, so I pass in a Lazy<NameValueCollection>
pointing to it instead.