W
Wiktor Zychla [C# MVP]
I try to figure out how to write unit tests for asp.net. I am using the
Microsoft.VisualStudio.TestTools.UnitTesting.Web namespace with Visual
Studio 2008.
The simple case work as expected, for example:
Page page = TestContext.RequestPage;
Assert.IsTrue( page.Request.Url.ToString().EndsWith( "default.aspx" ) );
according to the documentation the PrivateObject class is a helper class for
invoking private methods like event handlers.
This works great:
Button b = (Button)page.FindControl( "Button1" );
PrivateObject po = new PrivateObject( page );
po.Invoke( "Button1_Click", b, EventArgs.Empty );
the problem occurs when the Button1_Click actually REDIRECTS to another
page.
void Button1_Click( object sender, EventArgs e )
{
// comment this call and there will be no problems with the test
Response.Redirect( "default2.aspx" );
}
in such case the tests fails with "The communication channel with ASP.NET
could not be configured." followed by some localized information from the
development server meaning that the "the service cannot be found".
has anyone observed such behaviour?
if this is so then how do we handle redirects in the test framework (this
would be one of fundamental requirements!)?
Regards,
Wiktor Zychla
Microsoft.VisualStudio.TestTools.UnitTesting.Web namespace with Visual
Studio 2008.
The simple case work as expected, for example:
Page page = TestContext.RequestPage;
Assert.IsTrue( page.Request.Url.ToString().EndsWith( "default.aspx" ) );
according to the documentation the PrivateObject class is a helper class for
invoking private methods like event handlers.
This works great:
Button b = (Button)page.FindControl( "Button1" );
PrivateObject po = new PrivateObject( page );
po.Invoke( "Button1_Click", b, EventArgs.Empty );
the problem occurs when the Button1_Click actually REDIRECTS to another
page.
void Button1_Click( object sender, EventArgs e )
{
// comment this call and there will be no problems with the test
Response.Redirect( "default2.aspx" );
}
in such case the tests fails with "The communication channel with ASP.NET
could not be configured." followed by some localized information from the
development server meaning that the "the service cannot be found".
has anyone observed such behaviour?
if this is so then how do we handle redirects in the test framework (this
would be one of fundamental requirements!)?
Regards,
Wiktor Zychla