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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Inside of one of my methods I have this:

string key = "close";
string script = "<script>...</script>";
((Page)HttpContext.Current.CurrentHandler).ClientScript.RegisterClientScriptBlock(typeof(string),key, script);

It seems complex to me. How could I mock the bold line?

Should I write 5 mock statements for each property or method :(?
HttpContext.Current
HttpContext.Current.CurrentHandler
Page.ClientScript
RegisterClientScriptBlock

Many thanks
asked by Ben (3k points)

11 Answers

0 votes
As far as I understand the purpose of the test, you want to verify that the client script is registered. Using Ivonna, I wouldn't mock anything, just execute the request and verify that the script appears on the page:

string script = "<script>...</script>";
var session = new TestSession();
string pageBody = session.ProcessRequest(new WebRequest("Default.aspx")).BodyAsString;

Assert.IsTrue(pageBody.Contains(script));


This is not very different from what you would do with WatiN or Selenium, except that you don't need a Web server running.

As for using the code suggested above, the results are unpredictable, since Ivonna mocks HttpContext internally and relies on the CurrentHandler property.

Artem
answered by ulu (1.7k points)
...