Thursday, January 24, 2008

How to build NUnitASP container using HTML source

JHA site uses nested Master Page to host content, eg. PrivateBase is inside Site.Master

<%@ Master MasterPageFile="Site.Master" Inherits="ManulifeUSA.Common.Web.UI.UserControls.PrivateBase" %>

<asp:Content ContentPlaceHolderID="mainContentPlaceHolder">

<asp:PlaceHolder ID="rightPlaceHolderContainer" runat="Server">

Note that "rightPlaceHolderContainer" is nested inside "mainContentPlaceHolder" as well.

This structure will generate the following HTML sourcece in AddressChangePage.aspx as follows:

<input type="submit" id="ctl00_ctl00_mainContentPlaceHolder_rightPlaceHolder_btnUpdateAddress" />

Note that the id is the clue for constructing containers for NUnitASP testing, namely, ctl00 referes to SiteMaster, the 2nd ctl00 refers to PrivateBase, etc.
Since I have abstracted "ctl00_ctl00_mainContentPlaceHolder" into the following Test Container:

Public Class PrivateBaseTester
Inherits UserControlTester
Sub New(ByVal SiteID As String, ByVal PrivateBaseID As String, ByVal rightPlaceHolderID As String)
MyBase.New(rightPlaceHolderID, New UserControlTester("mainContentPlaceHolder",

New UserControlTester(PrivateBaseID, New UserControlTester(SiteID))))
End Sub
End Class


You would need to construct containers for btnUpdateAddress in the following manner:

Dim master As New PrivateBaseTester("ctl00", "ctl00", "rightPlaceHolder")

Dim btnUpdateAddress As New ButtonTester("btnUpdateAddress", master)

I hope this will help developers understand the approach to create container chains.

No comments: