<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Unit Testing The MVC JsonResult</title><link>http://blogs.msdn.com/miah/archive/2009/02/25/unit-testing-the-mvc-jsonresult.aspx</link><description>One of my favorite features of ASP.NET MVC is the support for JSON . In MVC, an Action Method in a Controller can return a JsonResult. This really comes in handy when integrating with jQuery to provide AJAX-like functionality in an application. In this</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Anith &amp;raquo; Unit Testing The MVC JsonResult</title><link>http://blogs.msdn.com/miah/archive/2009/02/25/unit-testing-the-mvc-jsonresult.aspx#9443627</link><pubDate>Wed, 25 Feb 2009 09:16:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9443627</guid><dc:creator>Anith &amp;raquo; Unit Testing The MVC JsonResult</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.anith.com/?p=13384"&gt;http://www.anith.com/?p=13384&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Unit Testing The MVC JsonResult - Jeremiah.Clark</title><link>http://blogs.msdn.com/miah/archive/2009/02/25/unit-testing-the-mvc-jsonresult.aspx#9443738</link><pubDate>Wed, 25 Feb 2009 11:21:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9443738</guid><dc:creator>DotNetShoutout</dc:creator><description>&lt;p&gt;Thank you for submitting this cool story - Trackback from DotNetShoutout&lt;/p&gt;
</description></item><item><title>re: Unit Testing The MVC JsonResult</title><link>http://blogs.msdn.com/miah/archive/2009/02/25/unit-testing-the-mvc-jsonresult.aspx#9443817</link><pubDate>Wed, 25 Feb 2009 12:24:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9443817</guid><dc:creator>Andreas Ohlund</dc:creator><description>&lt;p&gt;Intersting post!&lt;/p&gt;
&lt;p&gt;If you use the testhelpers from MVCContrib you could also test using the following syntax:&lt;/p&gt;
&lt;p&gt; &amp;nbsp;var json = controller.FindRooms(new RoomRequirements { From = from, To = to })&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.AssertResultIs&amp;lt;JsonResult&amp;gt;()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.AssertPayloadIs&amp;lt;IList&amp;lt;Room&amp;gt;&amp;gt;();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Assert.That(json.Count, Is.EqualTo(2));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Assert.That(json[0].Number, Is.EqualTo(&amp;quot;201&amp;quot;));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Assert.That(json[0].Type, Is.EqualTo(&amp;quot;Single&amp;quot;));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Assert.That(json[0].Price, Is.EqualTo(1100.0));&lt;/p&gt;
</description></item><item><title>re: Unit Testing The MVC JsonResult</title><link>http://blogs.msdn.com/miah/archive/2009/02/25/unit-testing-the-mvc-jsonresult.aspx#9896634</link><pubDate>Fri, 18 Sep 2009 06:09:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9896634</guid><dc:creator>Charles Ouellet</dc:creator><description>&lt;p&gt;I found another way to achieve this...I find it much easier, I use the RouteValueDictionary, I created an extension method to the JsonResult:&lt;/p&gt;
&lt;p&gt; public static RouteValueDictionary AsRouteValueDictionary(this JsonResult jsonResult)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return new RouteValueDictionary(jsonResult.Data);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;Then, I can use it this way:&lt;/p&gt;
&lt;p&gt;var result = jsonResult.AsRouteValueDictionary();&lt;/p&gt;
&lt;p&gt;Assert.That(result[&amp;quot;Status&amp;quot;], Is.True);&lt;/p&gt;
</description></item></channel></rss>