tags:

views:

144

answers:

1

I have a method that takes a System.Web.UI.Page as an input and returns some application specific details (what "type" of page it is, if certain items are in the query string, etc...). To run a unit test on this I was trying to create a System.Web.UI.Page item (in the code I am able to just send this.Page).

First Attempt: Serialization - I tried to serialize the page to a file and then deserialize to create the standard test page. Received many errors about not being able to serialize a Page. Is there anyway to write that object to a file?

Second Attempt: new Page() - I tried to just create the page and set the items I was interested in, but all the items I'm interested in appear to be read-only (no setter). Is there some way to create a System.Web.UI.Page programatically?

+1  A: 

Why not mock out the Page class using a mocking framework? This is exactly the kind of scenario mocking is used for. I personally like Moq.

Kevin Babcock
I probably just don't understand mocking frameworks, but I'm trying to test a method by creating an instance of the Page class to send to that method to test it. So I'm kind of trying to mock the page class instance, but it has to be of type Page, which is where I run into issues above.
ChrisHDog