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
I my one of the Controller method I am creating Session Object. How do I test it using type mock.
I sholuld be able to set some value in Session["SessionLogin"] from test.

How do I do this? :)

----Code -

public ActionResult CreateSession(
{
if(Session["SessionLogin"] !=null )
Session.Remove("SessionLogin");

Session["SessionLogin"] = "LogionObject";

return View("SomeView");
}
--Code--
asked by sudhir (3.5k points)

4 Answers

0 votes
Hello
For above code testing , I am using static class MvcMockHelper which is available online avaliable at http://blog.typemock.com/2008/03/testin ... emock.html.

How can I make use of this Helper calls for testing Request, Session, servervariable objects?

I hope somebody wil help. :)
answered by sudhir (3.5k points)
0 votes
Hi,

Not sure I understand you correctly.
Faking an indexer with the Isolator is just like faking return value of a method:

Isolate.WhenCalled(() => Foo.Session["SessionLogin"]).WillReturn("abc");


Can you please post here more details about what you are trying to test?
answered by ohad (35.5k points)
0 votes
Hello,
I have someting like follllowing in controller.

--------Code---
public ActionResult CreateSession(
{
string strUserOption ="";

if (Request.Form["payOption"] != null)
strUserOption = Request.Form["payOption"].ToString();

if(strUserOption.length >0)
{
if(Session["SessionLogin"] !=null )
Session.Remove("SessionLogin");
else
Session["SessionLogin"] = "LogionObject";
}
return View("SomeView");


}
--------Code---

My question is , how do i set "Request.Form["payOption"] " and "Session["SessionLogin"]" values in unit test.
answered by sudhir (3.5k points)
0 votes
Sudhir,

The way Ohad suggested you do it should work. Did you try:
Isolate.WhenCalled(() => Request.Form["payOption").WillReturn("abc");
Isolate.WhenCalled(() => Request.Form["SessionLogin").WillReturn("def");


Please let me know if this works for you.

Doron
Typemock Support
answered by igal (5.7k points)
...