chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hello mockers :) (I'm pretty new into this, so please bear with me if this is basic.)

I'm trying to test my UserControl.Page_Load(), and need to mock the Page property (inherited from System.Web.UI.UserControl). Snippets:
.
string allsites = Page.Request.QueryString["sites"];
.
.
if (!Page.ClientScript.IsStartupScriptRegistered(typeof(Page), "Startup"))
Page.ClientScript.RegisterStartupScript(typeof(Page), "SearchBoxStartup", jsStartup, true);

I've read about similar issues here at the forum, and have tried several suggestions with no luck. When I'm debugging my test, and debugging into the Page_Load, the Page property is always null.

Can anyone advice how to mock the Page property?
Thx in advance
JI
asked by janid1967 (600 points)

1 Answer

0 votes
Hi JI, and welcome to our forum.

You can fake the Page property to return a recursive fake - this way you know call chains beginning at the Page will not return null. Something like this:

var control = new MyControl();
Isolate.WhenCalled(() => control.Page).WillReturnRecursiveFake();

control.DoStuff(); // the page property and anything it accesses are faked here


Please let me know if this helps.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
...