DNN Blog

Feb 25

Posted by: Philip Beadle
Monday, February 25, 2008 12:00 AM  RssIcon

When you are developing a DNN module you have access to a bunch of properties in the core framework such as UserID, ModuleID and LocalResourceFile.  When you start developing modules using Test Driven Development (TDD) you still need access to these properties which means we need to be able to access them from  the presenter class.

The presenter class has a construct like this

        Public Sub New(ByVal _View As IViewTestDrivenDNNModule)
            View = _View

            Controller = New TestDrivenDNNModuleController
        End Sub

which means that the View we access in the presenter class only has the properties specified in the interface for the View.  We can access the LocalResourceFile if the DotNetNuke.UI.Modules.IModuleControl is inherited but since the PortalModuleBase class does not have an interface we cannot access the other properties we need. 

So I made a few changes to the core to experiment with an Interface for the PortalModuleBase. Firstly I created a new interface called IPortalModuleBase

    Public Interface IPortalModuleBase
        ReadOnly Property ModuleID() As Integer
        ReadOnly Property UserID() As Integer
    End Interface
 
Then the PortalModuleBase class implements the new interface
 
    Public Class PortalModuleBase
        Inherits UserControlBase
        Implements IModuleControl
        Implements IPortalModuleBase
 
        Public ReadOnly Property ModuleId() As Integer Implements IPortalModuleBase.ModuleID
 
And lastly the interface for our module inherits both of the IPortalModuleBase and IModuleControl interfaces like this
 
    Public Interface IViewTestDrivenDNNModule
        Inherits DotNetNuke.UI.Modules.IPortalModuleBase
        Inherits DotNetNuke.UI.Modules.IModuleControl
 
This allows easy access to the properties we need in the presenter class like this
colTestDrivenDNNModules = objTestDrivenDNNModules.GetTestDrivenDNNModules(View.ModuleID)

Previously I had just added new properties to the IViewTestDrivenDNNModule interface and pulled the values through from the ViewTestDrivenDNNModule partial class. This however was inelegant and led to having properties such as ModuleId1!! This new solution is far more useable and very easy to implement.

Doing this will allow much easier development of TDD DNN modules.

Tags:
Categories:
Location: Blogs Parent Separator Philip Beadle

5 comment(s) so far...


Re: TDD DNN Modules - Some changes to the core

Phil,

Excellent work. Do you plan to make these changes to the official core, or will these need to be made as a post fetch the core step.

It would seem that the core could have this interface added and kept in synch with the class version.

Keep us posted on your progress.

Thanks, Jim

By jbonnie on   Tuesday, February 26, 2008 7:04 AM

Re: TDD DNN Modules - Some changes to the core

Hi Jim,
My plan is to figure out exactly what needs to be changed in the core to firstly make modules testable and then put a case forward to have the changes implemented. You're right in that this change will not affect all the existing modules out there as they only use the PortalModuleBase anyway not my new interface.

By philip.beadle on   Tuesday, February 26, 2008 7:06 AM

Re: TDD DNN Modules - Some changes to the core

My plan is going well :) We dont need to change anything, the new IModuleControl interface exposes everything we need. Ill post a new blog soon about this.

By philip.beadle on   Tuesday, February 26, 2008 8:16 PM

Re: TDD DNN Modules - Some changes to the core

Sweet - this will make for a nice code camp presentation.

By jbonnie on   Thursday, February 28, 2008 6:22 AM

Re: TDD DNN Modules - Some changes to the core

Funny you should say that Im just writing up an abstract for Code Camp Oz.

By philip.beadle on   Thursday, February 28, 2008 6:25 AM
Attend A Webinar
Try An Online Demo
Download DotNetNuke Professional Edition Trial
Have Someone Contact Me

Like Us on Facebook Join our Network on LinkedIn Follow DNN Corporate on Twitter Follow DNN on Twitter

Advertisers

Sponsors

DotNetNuke Corporation

DotNetNuke Corp. is the steward of the DotNetNuke open source project, the most widely adopted Web Content Management Platform for building web sites and web applications on Microsoft .NET. Organizations use DotNetNuke to quickly develop and deploy interactive and dynamic web sites, intranets, extranets and web applications. The DotNetNuke platform is available in a free Community and subscription-based Professional and Enterprise Editions with an Elite Support option. DotNetNuke Corp. also operates Snowcovered.com where users purchase third party apps for the platform.