U
Unit Test ASP.NET WebForm
Alright, so I'm trying to do the right thing and bring the concept of Unit
Testing into our ASP.NET Web Application, but we're running into walls left
and right. The biggest challenge we're facing right now involves unit
testing a .ASPX page where the assertion needs to evaluate a property of a
..ASCX user control included on this page. My thought was that we could
construct a PrivateObject the same way we do for a ASPX and be able to use
the po.GetProperty method to retrieve a property value at run-time for the
user control to test the assertion. However, we receive the
System.MissingMethodException exception when attempting to access this
property that is defined in the code-behind of the .ASCX control. Is it
possible to accomplish what I am trying or is some other method necessary?
Here is an example of the Test Method code:
<TestMethod()> _
<HostType("ASP.NET")> _
<UrlToTest("http://localhost/test/MyProspectsDetail.aspx")> _
<AspNetDevelopmentServerHost("C:\Projects\Test\Source", "/test")> _
Public Sub MyTest()
'System.Diagnostics.Debugger.Break()
Dim p As Page = TestContext.RequestedPage
Dim po As PrivateObject = New PrivateObject(p)
Dim mnu As UserControl =
p.Master.FindControl("cphSFA").FindControl("PageMenu")
Dim pp As PrivateObject = New PrivateObject(mnu)
pp.GetProperty("ItemEnabled", New Object())
'Additional code would normally follow here, but the exception is
encountered above and additional code wouldn't be reached, anyway. Also, no
assignment coded above intentionally to point out the exception, otherwise
the variable would just receive a value of "Nothing".
Assert.IsFalse(True, "Test")
End Sub
Any thoughts?
Testing into our ASP.NET Web Application, but we're running into walls left
and right. The biggest challenge we're facing right now involves unit
testing a .ASPX page where the assertion needs to evaluate a property of a
..ASCX user control included on this page. My thought was that we could
construct a PrivateObject the same way we do for a ASPX and be able to use
the po.GetProperty method to retrieve a property value at run-time for the
user control to test the assertion. However, we receive the
System.MissingMethodException exception when attempting to access this
property that is defined in the code-behind of the .ASCX control. Is it
possible to accomplish what I am trying or is some other method necessary?
Here is an example of the Test Method code:
<TestMethod()> _
<HostType("ASP.NET")> _
<UrlToTest("http://localhost/test/MyProspectsDetail.aspx")> _
<AspNetDevelopmentServerHost("C:\Projects\Test\Source", "/test")> _
Public Sub MyTest()
'System.Diagnostics.Debugger.Break()
Dim p As Page = TestContext.RequestedPage
Dim po As PrivateObject = New PrivateObject(p)
Dim mnu As UserControl =
p.Master.FindControl("cphSFA").FindControl("PageMenu")
Dim pp As PrivateObject = New PrivateObject(mnu)
pp.GetProperty("ItemEnabled", New Object())
'Additional code would normally follow here, but the exception is
encountered above and additional code wouldn't be reached, anyway. Also, no
assignment coded above intentionally to point out the exception, otherwise
the variable would just receive a value of "Nothing".
Assert.IsFalse(True, "Test")
End Sub
Any thoughts?