TestContext.RequestedPage property
How can I return a specific page through the TextContext.RequestedPage property? Whenever I use the [UrlToTest()] attribute and include a specific page, the property returns null. Is there another way to specify which page to return through this property?
Any help at all would be incredibly appreciated!
Hello,
Did you specify all of the attributes, required for ASP.NET Unit tests?
E.g. those are needed for testing Web Development Server (Cassini):
[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("%PathToWebRoot%\\WebSite12", "/WebSite12")]
[UrlToTest("http://localhost/WebSite12")]
This will make your test execute inside the worker process of Web Development Server, thus being able to access all of the internal objects of your Web application.
Regards,
Boris
Or, if your web page is in local IIS, don't use the AspNetDevelopmentServerHost attribute. The key in either case is the HostType attribute, which specifies that the test should run in ASP.NET, giving it access to the page indicated in the UrlToTest.
For more information on ASP.NET unit tests, you can also see the documentation here.
Yes, I used all the attributes necessary except the AspNetDevelopmentServerHost attribute because, as you stated in your second reply, I am running the application on IIS. My problem isn't that the RequestedPage property comes back null but, rather, that I can't return a specific page.
It seems to be that I should be able to specify the RequestedPage property by simply including it in the UrlToTest attribute, but that actually doesn't seem to work. Any other ideas?
I actually found a workaround to this by using the testContext.RequestedPage.Response.Redirect() method to redirect the test to the page I want, and then return that page using Page = testContext.RequestedPage. In either case, there should be a better way. Whatcha think?