<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Tell don&#039;t ask</title>
	<atom:link href="http://telldontask.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://telldontask.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Wed, 11 Jan 2012 12:22:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='telldontask.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Tell don&#039;t ask</title>
		<link>http://telldontask.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://telldontask.wordpress.com/osd.xml" title="Tell don&#039;t ask" />
	<atom:link rel='hub' href='http://telldontask.wordpress.com/?pushpress=hub'/>
		<item>
		<title>ASP.NET and JQuery MVC Menu Part 3 (AJAX)</title>
		<link>http://telldontask.wordpress.com/2010/07/26/asp-net-and-jquery-mvc-menu-part-3-ajax/</link>
		<comments>http://telldontask.wordpress.com/2010/07/26/asp-net-and-jquery-mvc-menu-part-3-ajax/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 09:09:49 +0000</pubDate>
		<dc:creator>telldontask</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://telldontask.wordpress.com/2010/07/26/asp-net-and-jquery-mvc-menu-part-3-ajax/</guid>
		<description><![CDATA[Other posts in this series: Part 1 Part 2 Aaron has very kindly sent me an extension to the original code for creating a simple menu for ASP.NET MVC sites. His version employs the Microsoft AJAX library to “ajaxify” the links on the menu. The main part of his code handles getting a List Item [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=102&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h5>Other posts in this series:</h5>
<ul>
<li><a href="https://telldontask.wordpress.com/2009/04/24/asp-net-and-jquery-mvc-menu-part-1/" target="_blank">Part 1</a> </li>
<li><a href="https://telldontask.wordpress.com/2009/10/05/asp-net-and-jquery-mvc-menu-part-2/" target="_blank">Part 2</a> </li>
</ul>
<p>Aaron has very kindly sent me an extension to the original code for creating a simple menu for ASP.NET MVC sites. His version employs the Microsoft AJAX library to “ajaxify” the links on the menu.</p>
<p>The main part of his code handles getting a List Item containing an AJAX link.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f5faa0cf-b45e-430c-8be9-c920fc93fc20" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#000000;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">static</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">class</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">Extention</span></li>
<li>    <span style="color:#ffffff;">{</span></li>
<li>        <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">static</span><span style="color:#ffffff;"> TagBuilder GetNavItem(</span><span style="color:#cc7832;">this</span><span style="color:#ffffff;"> AjaxHelper ajax, MolineSoftware.SLAudit.Navigation navItem)</span></li>
<li>        <span style="color:#ffffff;">{</span></li>
<li>            <span style="color:#ffffff;">MvcHtmlString htmlTemplate = </span><span style="color:#cc7832;">null</span><span style="color:#ffffff;">;</span></li>
<li><span style="color:#ffffff;"> </span></li>
<li>            <span style="color:#ffffff;"></span><span style="color:#cc7832;">if</span><span style="color:#ffffff;"> (navItem.Route == </span><span style="color:#cc7832;">null</span><span style="color:#ffffff;">)</span></li>
<li>            <span style="color:#ffffff;">{</span></li>
<li>                <span style="color:#ffffff;">htmlTemplate = </span></li>
<li>                    <span style="color:#ffffff;">ajax.ActionLink(navItem.LinkText, navItem.ActionName, navItem.Controller,</span></li>
<li>                                    <span style="color:#ffffff;"></span><span style="color:#cc7832;">new</span><span style="color:#ffffff;"> AjaxOptions</span></li>
<li>                                        <span style="color:#ffffff;">{</span></li>
<li>                                            <span style="color:#ffffff;">UpdateTargetId = navItem.UpdateTargetId,</span></li>
<li>                                            <span style="color:#ffffff;">OnSuccess = navItem.OnSuccess,</span></li>
<li>                                            <span style="color:#ffffff;">OnBegin = navItem.OnBegin</span></li>
<li>                                        <span style="color:#ffffff;">});</span></li>
<li>            <span style="color:#ffffff;">}</span></li>
<li>            <span style="color:#ffffff;"></span><span style="color:#cc7832;">else</span></li>
<li>            <span style="color:#ffffff;">{</span></li>
<li>                <span style="color:#ffffff;">htmlTemplate = </span></li>
<li>                    <span style="color:#ffffff;">ajax.ActionLink(navItem.LinkText, navItem.ActionName, navItem.Controller, navItem.Route,</span></li>
<li>                                    <span style="color:#ffffff;"></span><span style="color:#cc7832;">new</span><span style="color:#ffffff;"> AjaxOptions</span></li>
<li>                                        <span style="color:#ffffff;">{</span></li>
<li>                                            <span style="color:#ffffff;">UpdateTargetId = navItem.UpdateTargetId,</span></li>
<li>                                            <span style="color:#ffffff;">OnSuccess = navItem.OnSuccess,</span></li>
<li>                                            <span style="color:#ffffff;">OnBegin = navItem.OnBegin</span></li>
<li>                                        <span style="color:#ffffff;">});</span></li>
<li>            <span style="color:#ffffff;">}</span></li>
<li><span style="color:#ffffff;"> </span></li>
<li>            <span style="color:#ffffff;"></span><span style="color:#cc7832;">var</span><span style="color:#ffffff;"> builder = </span><span style="color:#cc7832;">new</span><span style="color:#ffffff;"> TagBuilder(</span><span style="color:#a5c25c;">&quot;li&quot;</span><span style="color:#ffffff;">);</span></li>
<li><span style="color:#ffffff;"> </span></li>
<li>            <span style="color:#ffffff;"></span><span style="color:#cc7832;">if</span><span style="color:#ffffff;"> (IsCurrentAction(ajax, navItem.ActionName, navItem.Controller))</span></li>
<li>                <span style="color:#ffffff;">builder.MergeAttribute(</span><span style="color:#a5c25c;">&quot;class&quot;</span><span style="color:#ffffff;">, </span><span style="color:#a5c25c;">&quot;current&quot;</span><span style="color:#ffffff;">);</span></li>
<li><span style="color:#ffffff;"> </span></li>
<li>            <span style="color:#ffffff;">builder.InnerHtml = htmlTemplate.ToHtmlString();</span></li>
<li>            <span style="color:#ffffff;"></span><span style="color:#cc7832;">return</span><span style="color:#ffffff;"> builder;</span></li>
<li>        <span style="color:#ffffff;">}</span></li>
<li><span style="color:#ffffff;"> </span></li>
<li>        <span style="color:#ffffff;"></span><span style="color:#cc7832;">static</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">bool</span><span style="color:#ffffff;"> IsCurrentAction(AjaxHelper ajax, </span><span style="color:#cc7832;">string</span><span style="color:#ffffff;"> actionName, </span><span style="color:#cc7832;">string</span><span style="color:#ffffff;"> controllerName)</span></li>
<li>        <span style="color:#ffffff;">{</span></li>
<li>            <span style="color:#ffffff;"></span><span style="color:#cc7832;">string</span><span style="color:#ffffff;"> currentControllerName = (</span><span style="color:#cc7832;">string</span><span style="color:#ffffff;">) ajax.ViewContext.RouteData.Values[</span><span style="color:#a5c25c;">&quot;controller&quot;</span><span style="color:#ffffff;">];</span></li>
<li>            <span style="color:#ffffff;"></span><span style="color:#cc7832;">string</span><span style="color:#ffffff;"> currentActionName = (</span><span style="color:#cc7832;">string</span><span style="color:#ffffff;">) ajax.ViewContext.RouteData.Values[</span><span style="color:#a5c25c;">&quot;action&quot;</span><span style="color:#ffffff;">];</span></li>
<li><span style="color:#ffffff;"> </span></li>
<li>            <span style="color:#ffffff;"></span><span style="color:#cc7832;">if</span><span style="color:#ffffff;"> (currentControllerName.Equals(controllerName, StringComparison.CurrentCultureIgnoreCase) &amp;&amp;</span></li>
<li>                <span style="color:#ffffff;">currentActionName.Equals(actionName, StringComparison.CurrentCultureIgnoreCase))</span></li>
<li>            <span style="color:#ffffff;">{</span></li>
<li>                <span style="color:#ffffff;"></span><span style="color:#cc7832;">return</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">true</span><span style="color:#ffffff;">;</span></li>
<li>            <span style="color:#ffffff;">}</span></li>
<li>            <span style="color:#ffffff;"></span><span style="color:#cc7832;">return</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">false</span><span style="color:#ffffff;">;</span></li>
<li>        <span style="color:#ffffff;">}</span></li>
<li>    <span style="color:#ffffff;">}</span></li>
<li><span style="color:#ffffff;">}</span></li>
</ol></div>
</p></div>
</p></div>
<p>You will notice the use of a class called Navigation (to build the actual link).</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d36901e3-048d-4d16-9f6d-d92272418aad" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#000000;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">class</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">Navigation</span></li>
<li><span style="color:#ffffff;">{</span></li>
<li>    <span style="color:#da4832;">#region</span><span style="color:#ffffff;"> | Public Properties |</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> Gets or Sets the ID</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">virtual</span><span style="color:#ffffff;"> </span><span style="color:#2b91af;">Int32</span><span style="color:#ffffff;"> Id { </span><span style="color:#cc7832;">get</span><span style="color:#ffffff;">; </span><span style="color:#cc7832;">set</span><span style="color:#ffffff;">; }</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> Gets or Sets the Display for the link</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">virtual</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">String</span><span style="color:#ffffff;"> LinkText { </span><span style="color:#cc7832;">get</span><span style="color:#ffffff;">; </span><span style="color:#cc7832;">set</span><span style="color:#ffffff;">; }</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> Gets or Sets the ActionName.</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">virtual</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">String</span><span style="color:#ffffff;"> ActionName { </span><span style="color:#cc7832;">get</span><span style="color:#ffffff;">; </span><span style="color:#cc7832;">set</span><span style="color:#ffffff;">; }</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> Gets or Sets the Controller</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">virtual</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">String</span><span style="color:#ffffff;"> Controller { </span><span style="color:#cc7832;">get</span><span style="color:#ffffff;">; </span><span style="color:#cc7832;">set</span><span style="color:#ffffff;">; }</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> Gets or sets the Active flag.</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">virtual</span><span style="color:#ffffff;"> </span><span style="color:#2b91af;">Boolean</span><span style="color:#ffffff;"> Active { </span><span style="color:#cc7832;">get</span><span style="color:#ffffff;">; </span><span style="color:#cc7832;">set</span><span style="color:#ffffff;">; }</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> Gets or sets the JavaScript function to call after the page is successfully updated.</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">virtual</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">String</span><span style="color:#ffffff;"> OnSuccess { </span><span style="color:#cc7832;">get</span><span style="color:#ffffff;">; </span><span style="color:#cc7832;">set</span><span style="color:#ffffff;">; }</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> Gets or sets the name of the JavaScript function to call immediately before the page is updated.</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">virtual</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">String</span><span style="color:#ffffff;"> OnBegin { </span><span style="color:#cc7832;">get</span><span style="color:#ffffff;">; </span><span style="color:#cc7832;">set</span><span style="color:#ffffff;">; }</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> Gets or sets the ID of the DOM element to update by using the response from the server.</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">virtual</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">String</span><span style="color:#ffffff;"> UpdateTargetId { </span><span style="color:#cc7832;">get</span><span style="color:#ffffff;">; </span><span style="color:#cc7832;">set</span><span style="color:#ffffff;">; }</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> Gets or Sets the </span><span style="color:#808080;">&lt;see cref=&quot;RouteValueDictionary&quot;/&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;"> </span><span style="color:#808080;">&lt;/summary&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">virtual</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">object</span><span style="color:#ffffff;"> Route { </span><span style="color:#cc7832;">get</span><span style="color:#ffffff;">; </span><span style="color:#cc7832;">set</span><span style="color:#ffffff;">; }</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#da4832;">#endregion</span></li>
<li><span style="color:#ffffff;">}</span></li>
</ol></div>
</p></div>
</p></div>
<p>We can then create a collection of these navigation items…</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:534b9777-e842-4f5c-bced-5ce43d06acb8" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#000000;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#cc7832;">namespace</span><span style="color:#ffffff;"> MolineSoftware.SLAudit</span></li>
<li><span style="color:#ffffff;">{</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">class</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">NavigationList</span><span style="color:#ffffff;"> : </span><span style="color:#ffc66d;">List</span><span style="color:#ffffff;">&lt;</span><span style="color:#ffc66d;">Navigation</span><span style="color:#ffffff;">&gt;</span></li>
<li>    <span style="color:#ffffff;">{</span></li>
<li>        <span style="color:#da4832;">#region</span><span style="color:#ffffff;"> | Constructor |</span></li>
<li>&nbsp;</li>
<li>        <span style="color:#da4832;">#endregion</span></li>
<li>&nbsp;</li>
<li>        <span style="color:#ffffff;"></span><span style="color:#808080;">///</span><span style="color:#008000;">Returns a NavigationList of items ** TESTING ONLY</span></li>
<li>        <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">NavigationList</span><span style="color:#ffffff;"> GetTestList()</span></li>
<li>        <span style="color:#ffffff;">{</span></li>
<li>            <span style="color:#ffffff;"></span><span style="color:#ffc66d;">NavigationList</span><span style="color:#ffffff;"> list = </span><span style="color:#cc7832;">new</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">NavigationList</span><span style="color:#ffffff;">();</span></li>
<li>&nbsp;</li>
<li>            <span style="color:#ffffff;">list.Add(</span><span style="color:#cc7832;">new</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">Navigation</span></li>
<li>                         <span style="color:#ffffff;">{</span></li>
<li>                             <span style="color:#ffffff;">Active = </span><span style="color:#cc7832;">true</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">Controller = </span><span style="color:#a5c25c;">&quot;Home&quot;</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">OnBegin = </span><span style="color:#a5c25c;">&quot;SetLoading&quot;</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">OnSuccess = </span><span style="color:#a5c25c;">&quot;handleUpdate&quot;</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">Id = 1,</span></li>
<li>                             <span style="color:#ffffff;">LinkText = </span><span style="color:#a5c25c;">&quot;Home&quot;</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">ActionName = </span><span style="color:#a5c25c;">&quot;Index&quot;</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">UpdateTargetId = </span><span style="color:#a5c25c;">&quot;output-data&quot;</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">Route = </span><span style="color:#cc7832;">new</span><span style="color:#ffffff;"> {serverName = </span><span style="color:#a5c25c;">&quot;MyServer&quot;}</span><span style="color:#ffffff;"> </span><span style="color:#808080;">//Example setting the route object</span></li>
<li>                         <span style="color:#ffffff;">});</span></li>
<li>&nbsp;</li>
<li>&nbsp;</li>
<li>            <span style="color:#ffffff;">list.Add(</span><span style="color:#cc7832;">new</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">Navigation</span></li>
<li>                         <span style="color:#ffffff;">{</span></li>
<li>                             <span style="color:#ffffff;">Active = </span><span style="color:#cc7832;">true</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">Controller = </span><span style="color:#a5c25c;">&quot;Home&quot;</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">OnBegin = </span><span style="color:#a5c25c;">&quot;SetLoading&quot;</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">OnSuccess = </span><span style="color:#a5c25c;">&quot;handleUpdate&quot;</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">Id = 2,</span></li>
<li>                             <span style="color:#ffffff;">LinkText = </span><span style="color:#a5c25c;">&quot;About&quot;</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">ActionName = </span><span style="color:#a5c25c;">&quot;About&quot;</span><span style="color:#ffffff;">,</span></li>
<li>                             <span style="color:#ffffff;">UpdateTargetId = </span><span style="color:#a5c25c;">&quot;output-data&quot;</span></li>
<li>                         <span style="color:#ffffff;">});</span></li>
<li>            <span style="color:#ffffff;"></span><span style="color:#cc7832;">return</span><span style="color:#ffffff;"> list;</span></li>
<li>        <span style="color:#ffffff;">}</span></li>
<li>    <span style="color:#ffffff;">}</span></li>
</ol></div>
</p></div>
</p></div>
<p>Finally we can use this code (assuming model is an instance of our NavigationList class) to render the menu.</p>
</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:be0954d1-8486-493c-b971-fcd768b12f65" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#000000;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#ffffff;"></span><span style="background:#000000;color:#6897bb;">&lt;%</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">foreach</span><span style="color:#ffffff;"> (</span><span style="color:#cc7832;">var</span><span style="color:#ffffff;"> menu </span><span style="color:#cc7832;">in</span><span style="color:#ffffff;"> Model </span><span style="color:#cc7832;">as</span><span style="color:#ffffff;"> MolineSoftware.SLAudit.</span><span style="color:#ffc66d;">NavigationList</span><span style="color:#ffffff;">) { </span><span style="background:#000000;color:#6897bb;">%&gt;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="background:#000000;color:#6897bb;">&lt;%</span><span style="color:#ffffff;">= Ajax.GetNavItem(menu)</span><span style="background:#000000;color:#6897bb;">%&gt;</span><span style="color:#ffffff;"> </span></li>
<li><span style="color:#ffffff;"></span><span style="background:#000000;color:#6897bb;">&lt;%</span><span style="color:#ffffff;"> } </span><span style="background:#000000;color:#6897bb;">%&gt;</span></li>
</ol></div>
</p></div>
</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/telldontask.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/telldontask.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/telldontask.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/telldontask.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/telldontask.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/telldontask.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/telldontask.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/telldontask.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/telldontask.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/telldontask.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/telldontask.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/telldontask.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/telldontask.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/telldontask.wordpress.com/102/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=102&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://telldontask.wordpress.com/2010/07/26/asp-net-and-jquery-mvc-menu-part-3-ajax/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b6cf9c1a25c7a667c1592e513624bea1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">telldontask</media:title>
		</media:content>
	</item>
		<item>
		<title>Upgrading to ASP.NET MVC 2/.net 4</title>
		<link>http://telldontask.wordpress.com/2010/07/13/upgrading-to-asp-net-mvc-2-net-4/</link>
		<comments>http://telldontask.wordpress.com/2010/07/13/upgrading-to-asp-net-mvc-2-net-4/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 08:26:22 +0000</pubDate>
		<dc:creator>telldontask</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://telldontask.wordpress.com/2010/07/13/upgrading-to-asp-net-mvc-2-net-4/</guid>
		<description><![CDATA[We have recently upgraded a few projects to .net 4 (and MVC 2) and have invariably hit one particular error message. We are using the Spark view engine, and having upgraded the project to MVC 2 would see this error… Dynamic view compilation failed. (0,0): warning CS1701: Assuming assembly reference &#8216;System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&#8242; matches [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=101&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We have recently upgraded a few projects to .net 4 (and MVC 2) and have invariably hit one particular error message.</p>
<p>We are using the Spark view engine, and having upgraded the project to MVC 2 would see this error…</p>
<p><em>Dynamic view compilation failed. (0,0): warning CS1701: Assuming assembly reference &#8216;System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&#8242; matches &#8216;System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&#8242;, you may need to supply runtime policy</em></p>
<p>Google helped us find <a href="http://stackoverflow.com/questions/1805779/using-asp-net-mvc-2-features-with-the-spark-view-engine" target="_blank">this post</a>, which explains that any referenced assemblies which in turn reference MVC 1 could be causing this issue.</p>
<p>After a prolonged process of checking and upgrading various assemblies, we eventually discovered that we needed to update our _Global.spark file.</p>
<p>This file (for those who haven’t used it) is a useful place to put anything which all the spark pages in your project need to include.</p>
<p>Ours looked like this…</p>
<p><em>&lt;use namespace=&quot;Microsoft.Web.Mvc&quot; /&gt;     <br />&lt;use namespace=&quot;MvcContrib&quot; /&gt;      <br />&lt;use namespace=&quot;MvcContrib.UI&quot; /&gt;      <br />&lt;use namespace=&quot;MvcContrib.UI.Pager&quot; /&gt;      <br />&lt;use namespace=&quot;MvcContrib.FluentHtml&quot; /&gt;      <br />&lt;use namespace=&quot;System&quot; /&gt;      <br />&lt;use namespace=&quot;System.Data&quot; /&gt;      <br />&lt;use namespace=&quot;System.Collections.Generic&quot; /&gt;      <br />&lt;use namespace=&quot;System.Web.Mvc&quot; /&gt;      <br />&lt;use namespace=&quot;System.Web.Mvc.Html&quot; /&gt;      <br />&lt;use namespace=&quot;Autoclimate.Framework.Extensions&quot; /&gt;      <br />&lt;use namespace=&quot;Catalogue.Web.Code&quot; /&gt;      <br />&lt;use namespace=&quot;xVal.Html&quot; /&gt;</em></p>
<p>We’d upgraded most of these to the latest versions, except for xVal. Removing xVal from this list fixed the problem. As it happens we were no longer using xVal (in the spark pages) so we didn’t need it in there anyway.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/telldontask.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/telldontask.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/telldontask.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/telldontask.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/telldontask.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/telldontask.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/telldontask.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/telldontask.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/telldontask.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/telldontask.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/telldontask.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/telldontask.wordpress.com/101/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/telldontask.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/telldontask.wordpress.com/101/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=101&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://telldontask.wordpress.com/2010/07/13/upgrading-to-asp-net-mvc-2-net-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b6cf9c1a25c7a667c1592e513624bea1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">telldontask</media:title>
		</media:content>
	</item>
		<item>
		<title>Posting an Array of Complex types using JQuery, JSON to ASP.NET MVC</title>
		<link>http://telldontask.wordpress.com/2010/05/26/posting-an-array-of-complex-types-using-jquery-json-to-asp-net-mvc/</link>
		<comments>http://telldontask.wordpress.com/2010/05/26/posting-an-array-of-complex-types-using-jquery-json-to-asp-net-mvc/#comments</comments>
		<pubDate>Wed, 26 May 2010 13:34:03 +0000</pubDate>
		<dc:creator>telldontask</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://telldontask.wordpress.com/2010/05/26/posting-an-array-of-complex-types-using-jquery-json-to-asp-net-mvc/</guid>
		<description><![CDATA[I recently hit a requirement to take an array of objects and post them to an asp.net mvc action using JQuery’s ajax functionality. I had to do a bit of Googling to work out how to do this so figured I’d document what I found. The main two parts to this are getting JQuery to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=92&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently hit a requirement to take an array of objects and post them to an asp.net mvc action using JQuery’s ajax functionality.</p>
<p>I had to do a bit of Googling to work out how to do this so figured I’d document what I found.</p>
<p>The main two parts to this are getting JQuery to spit out JSON data and ASP.NET MVC to deserialize that data into a strongly typed generic list.</p>
<h3>Javascript (JQuery)</h3>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6200b525-8cf3-403d-bb4e-06c7c54289ad" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#000000;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#ffffff;">$(</span><span style="color:#a5c250;">&#039;#saveChanges&#039;</span><span style="color:#ffffff;">).click(</span><span style="color:#cc7832;">function</span><span style="color:#ffffff;"> () {</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">var</span><span style="color:#ffffff;"> rules = </span><span style="color:#cc7832;">new</span><span style="color:#ffffff;"> Array();</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;">$(</span><span style="color:#a5c250;">&#039;#assignedRules table.ruleTable tbody tr&#039;</span><span style="color:#ffffff;">).each(</span><span style="color:#cc7832;">function</span><span style="color:#ffffff;"> (i) {</span></li>
<li>        <span style="color:#ffffff;"></span><span style="color:#cc7832;">var</span><span style="color:#ffffff;"> subRuleCode = $(</span><span style="color:#a5c250;">&#039;#subRuleCode&#039;</span><span style="color:#ffffff;">, </span><span style="color:#cc7832;">this</span><span style="color:#ffffff;">).val();</span></li>
<li>        <span style="color:#ffffff;"></span><span style="color:#cc7832;">var</span><span style="color:#ffffff;"> productGroupId = $(</span><span style="color:#a5c250;">&#039;#productGroupId&#039;</span><span style="color:#ffffff;">, </span><span style="color:#cc7832;">this</span><span style="color:#ffffff;">).val();</span></li>
<li>        <span style="color:#ffffff;">rules.push(</span><span style="color:#cc7832;">new</span><span style="color:#ffffff;"> Rule(subRuleCode, productGroupId));</span></li>
<li>    <span style="color:#ffffff;">});</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">var</span><span style="color:#ffffff;"> postData = JSON.stringify(rules);</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;">$.ajax({</span></li>
<li>        <span style="color:#ffffff;">url: </span><span style="color:#a5c250;">&#039;/rule/SaveUserRules&#039;</span><span style="color:#ffffff;">,</span></li>
<li>        <span style="color:#ffffff;">data: postData,</span></li>
<li>        <span style="color:#ffffff;">contentType: </span><span style="color:#a5c250;">&#039;application/json&#039;</span><span style="color:#ffffff;">,</span></li>
<li>        <span style="color:#ffffff;">dataType: </span><span style="color:#a5c250;">&#039;json&#039;</span><span style="color:#ffffff;">,</span></li>
<li>        <span style="color:#ffffff;">type: </span><span style="color:#a5c250;">&#039;post&#039;</span><span style="color:#ffffff;">,</span></li>
<li>        <span style="color:#ffffff;">success: onRulesSaved,</span></li>
<li>        <span style="color:#ffffff;">error: </span><span style="color:#cc7832;">function</span><span style="color:#ffffff;"> (data, textStatus) { alert(textStatus); }</span></li>
<li>    <span style="color:#ffffff;">}</span></li>
<li>    <span style="color:#ffffff;">);</span></li>
<li><span style="color:#ffffff;">});</span></li>
</ol></div>
</p></div>
</p></div>
<p>This javascript</p>
<ul>
<li>creates a new array </li>
<li>iterates over some table rows and grabs a couple of hidden field values for each row </li>
<li>stores the hidden field values in a javascript class called Rule </li>
<li>pushes the Rule instance into the array </li>
<li>calls JSON.stringify to construct a valid JSON string from our array of Rules </li>
<li>posts the JSON string to our destination URL </li>
</ul>
<p>As you can see, this script effectively translates a table of values, to an array of Rules which are then sent as JSON to our target URL.</p>
<p>The <strong>stringify</strong> function uses the script available from <a href="http://www.json.org/json2.js" target="_blank">here</a>.</p>
<p>The Rule javascript class is simple enough…</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cf053970-509d-45ae-9a9e-39f6fbbcbf42" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#000000;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#cc7832;">function</span><span style="color:#ffffff;"> Rule(subRuleCode, productGroupId) {</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">this</span><span style="color:#ffffff;">.SubRule = subRuleCode;</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">this</span><span style="color:#ffffff;">.ProductGroupId = productGroupId;</span></li>
<li><span style="color:#ffffff;">}</span></li>
</ol></div>
</p></div>
</p></div>
<h3>MVC Action</h3>
<p>The next trick is to get the MVC action to accept the array and turn it into a strongly typed generic list.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9d9cc1b2-bc46-4c3e-aeb4-f13a37c21e73" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#000000;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#ffffff;">[</span><span style="color:#ffc66d;">AcceptVerbs</span><span style="color:#ffffff;">(</span><span style="color:#ffc66d;">HttpVerbs</span><span style="color:#ffffff;">.Post)]</span></li>
<li><span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">JsonResult</span><span style="color:#ffffff;"> SaveUserRules(</span><span style="color:#ffc66d;">List</span><span style="color:#ffffff;">&lt;</span><span style="color:#ffc66d;">Rule</span><span style="color:#ffffff;">&gt; usersRules)</span></li>
<li><span style="color:#ffffff;">{</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#808080;">// do something here</span></li>
<li><span style="color:#ffffff;">}</span></li>
</ol></div>
</p></div>
</p></div>
<p>As you can see we simply specify our generic list as the parameter for our action (which accepts HTTP Posts only).</p>
<h3>JSON Model Binder</h3>
<p>The final piece in the jigsaw is to tell MVC how to bind the JSON data to this generic list of Rules.</p>
<p>I found the code to create a simple JSON model binder <a href="http://lozanotek.com/blog/archive/2010/04/16/simple_json_model_binder.aspx" target="_blank">here</a>.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6fe8095c-5994-46fd-916c-8a7fda7be5f4" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#000000;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">class</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">JsonModelBinder</span><span style="color:#ffffff;"> : </span><span style="color:#ffc66d;">DefaultModelBinder</span></li>
<li><span style="color:#ffffff;">{</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">public</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">override</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">object</span><span style="color:#ffffff;"> BindModel(</span><span style="color:#ffc66d;">ControllerContext</span><span style="color:#ffffff;"> controllerContext, </span><span style="color:#ffc66d;">ModelBindingContext</span><span style="color:#ffffff;"> bindingContext)</span></li>
<li>    <span style="color:#ffffff;">{</span></li>
<li>        <span style="color:#ffffff;"></span><span style="color:#cc7832;">if</span><span style="color:#ffffff;"> (!IsJSONRequest(controllerContext))</span></li>
<li>        <span style="color:#ffffff;">{</span></li>
<li>            <span style="color:#ffffff;"></span><span style="color:#cc7832;">return</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">base</span><span style="color:#ffffff;">.BindModel(controllerContext, bindingContext);</span></li>
<li>        <span style="color:#ffffff;">}</span></li>
<li>&nbsp;</li>
<li>        <span style="color:#ffffff;"></span><span style="color:#808080;">// get the JSON data that&#039;s been posted</span></li>
<li>        <span style="color:#ffffff;"></span><span style="color:#cc7832;">var</span><span style="color:#ffffff;"> request = controllerContext.HttpContext.Request;</span></li>
<li>        <span style="color:#ffffff;"></span><span style="color:#cc7832;">var</span><span style="color:#ffffff;"> jsonStringData = </span><span style="color:#cc7832;">new</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">StreamReader</span><span style="color:#ffffff;">(request.InputStream).ReadToEnd();</span></li>
<li>&nbsp;</li>
<li>        <span style="color:#ffffff;"></span><span style="color:#cc7832;">return</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">new</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">JavaScriptSerializer</span><span style="color:#ffffff;">()</span></li>
<li>            <span style="color:#ffffff;">.Deserialize(jsonStringData, bindingContext.ModelMetadata.ModelType);</span></li>
<li>    <span style="color:#ffffff;">}</span></li>
<li>&nbsp;</li>
<li>    <span style="color:#ffffff;"></span><span style="color:#cc7832;">static</span><span style="color:#ffffff;"> </span><span style="color:#cc7832;">bool</span><span style="color:#ffffff;"> IsJSONRequest(</span><span style="color:#ffc66d;">ControllerContext</span><span style="color:#ffffff;"> controllerContext)</span></li>
<li>    <span style="color:#ffffff;">{</span></li>
<li>        <span style="color:#ffffff;"></span><span style="color:#cc7832;">var</span><span style="color:#ffffff;"> contentType = controllerContext.HttpContext.Request.ContentType;</span></li>
<li>        <span style="color:#ffffff;"></span><span style="color:#cc7832;">return</span><span style="color:#ffffff;"> contentType.Contains(</span><span style="color:#a5c25c;">&quot;application/json&quot;</span><span style="color:#ffffff;">);</span></li>
<li>    <span style="color:#ffffff;">}</span></li>
<li><span style="color:#ffffff;">}</span></li>
</ol></div>
</p></div>
</p></div>
<p>Now all you have to do is register this as the default model binder. Because it inherits the DefaultBinder, and only kicks in if the request type is application/json this shouldn’t break any non-json model binding.</p>
</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a461f506-7865-46d8-8b9a-d565b8c62704" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#000000;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#ffffff;"></span><span style="color:#cc7832;">void</span><span style="color:#ffffff;"> AddModelBinders()</span></li>
<li><span style="color:#ffffff;">{</span></li>
<li>    <span style="color:#ffffff;"></span><span style="color:#ffc66d;">ModelBinders</span><span style="color:#ffffff;">.Binders.DefaultBinder = </span><span style="color:#cc7832;">new</span><span style="color:#ffffff;"> </span><span style="color:#ffc66d;">JsonModelBinder</span><span style="color:#ffffff;">();</span></li>
<li><span style="color:#ffffff;">}</span></li>
</ol></div>
</p></div>
</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/telldontask.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/telldontask.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/telldontask.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/telldontask.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/telldontask.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/telldontask.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/telldontask.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/telldontask.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/telldontask.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/telldontask.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/telldontask.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/telldontask.wordpress.com/92/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/telldontask.wordpress.com/92/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/telldontask.wordpress.com/92/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=92&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://telldontask.wordpress.com/2010/05/26/posting-an-array-of-complex-types-using-jquery-json-to-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b6cf9c1a25c7a667c1592e513624bea1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">telldontask</media:title>
		</media:content>
	</item>
		<item>
		<title>MSpec AutoMocking</title>
		<link>http://telldontask.wordpress.com/2010/03/17/mspec-automocking/</link>
		<comments>http://telldontask.wordpress.com/2010/03/17/mspec-automocking/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 13:14:33 +0000</pubDate>
		<dc:creator>telldontask</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://telldontask.wordpress.com/?p=90</guid>
		<description><![CDATA[If you&#8217;ve read my previous posts on using Machine.Specifications and Rhino AutoMocker, you&#8217;ll know I&#8217;m a fan of both frameworks. James Broome has released a really useful extension for MSpec which pulls MSpec and Mocking together in one easy to use package. http://jamesbroo.me/introducing-machinespecificationsautomocking/ It&#8217;s well worth checking out.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=90&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<p>If you&#8217;ve read my previous posts on using Machine.Specifications and Rhino AutoMocker, you&#8217;ll know I&#8217;m a fan of both frameworks.</p>
<p>James Broome has released a really useful extension for MSpec which pulls MSpec and Mocking together in one easy to use package.</p>
<p><a href="http://jamesbroo.me/introducing-machinespecificationsautomocking/">http://jamesbroo.me/introducing-machinespecificationsautomocking/</a></p>
<p>It&#8217;s well worth checking out.</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/telldontask.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/telldontask.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/telldontask.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/telldontask.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/telldontask.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/telldontask.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/telldontask.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/telldontask.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/telldontask.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/telldontask.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/telldontask.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/telldontask.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/telldontask.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/telldontask.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=90&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://telldontask.wordpress.com/2010/03/17/mspec-automocking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b6cf9c1a25c7a667c1592e513624bea1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">telldontask</media:title>
		</media:content>
	</item>
		<item>
		<title>BDD with MSpec and Rhino Auto Mocks (part 3)</title>
		<link>http://telldontask.wordpress.com/2009/11/29/bdd-with-mspec-and-rhino-auto-mocks-part-3/</link>
		<comments>http://telldontask.wordpress.com/2009/11/29/bdd-with-mspec-and-rhino-auto-mocks-part-3/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 19:09:38 +0000</pubDate>
		<dc:creator>telldontask</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[MSpecs]]></category>
		<category><![CDATA[RhinoMocks]]></category>
		<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://telldontask.wordpress.com/2009/11/29/bdd-with-mspec-and-rhino-auto-mocks-part-3/</guid>
		<description><![CDATA[In part 1 and part 2 we covered setting up MSpec, writing our specifications and then implementing one of those specifications. So far we’ve covered very simple tests for code which has no external dependencies and does very little. Now we’ll turn our attention to those tests which (on the face of it) are more [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=78&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://telldontask.wordpress.com/2009/11/10/bdd-with-mspec-and-rhino-auto-mocks/" target="_blank">part 1</a> and <a href="http://telldontask.wordpress.com/2009/11/19/bdd-with-mspec-and-rhino-auto-mocks-part-2/" target="_blank">part 2</a> we covered setting up MSpec, writing our specifications and then implementing one of those specifications.</p>
<p>So far we’ve covered very simple tests for code which has no external dependencies and does very little. Now we’ll turn our attention to those tests which (on the face of it) are more complicated and cover code which relies on data access, email services etc.</p>
<p>Lets tackle the the “when asked for products matching search term” specification.</p>
<h3>Establishing Context</h3>
<p>As before, we’ll start by establishing the context for this test, and to cut down on duplication, I’ve moved the basic context setup to its own class.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6f1a0148-23af-43b1-ad59-ecc1f1b771b3" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">concern_for_product_controller</span></li>
<li style="background:#f3f3f3;">{</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">static</span> <span style="color:#2b91af;">ProductController</span> _controller;</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#2b91af;">Establish</span> context =</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt; { _controller = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ProductController</span>(); };</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>Now we can make all of the Product Controller tests inherit this class.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b3531085-20ce-4b1a-af91-85ca3a5ba647" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li>[<span style="color:#2b91af;">Subject</span>(<span style="color:#a31515;">&quot;Product Search&quot;</span>)]</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">when_asked_for_products_matching_search_term</span> : <span style="color:#2b91af;">concern_for_product_controller</span></li>
<li>{</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;<span style="color:#2b91af;">It</span> should_retrieve_a_list_of_products_with_titles_containing_the_search_term;</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#2b91af;">It</span> should_return_the_list_of_products_to_the_user;</li>
<li style="background:#f3f3f3;">}</li>
</ol></div>
</p></div>
</p></div>
<p>To implement the specification “should retrieve a list of products…” we want to simply check that the controller asks for a list of products from wherever we’re hoping to get our data from.</p>
<p>In the spirit of writing tests first we haven’t got any kind of data access layer yet so now we decide we need a <strong>Product Repository</strong>.</p>
<h3>Rhino AutoMocker</h3>
<p>To help test our repository we can introduce <strong>Rhino AutoMocker</strong> to the equation. Rhino AutoMocker is included as part of an <strong>AutoMocking</strong> library distributed with <strong>StructureMap</strong>.</p>
<p>To use it in your project, simply <a href="http://sourceforge.net/projects/structuremap/files/structuremap/StructureMap%202.5.3/StructureMap_2.5.3.zip/download" target="_blank">download StructureMap</a> and reference <strong>StructureMap.AutoMocking</strong> and <strong>Rhino.Mocks </strong>in your project.</p>
<p>We need to wire up the automocker so we can use it in our tests. To that end we’ll change our base class.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5b28e86c-8544-4350-b8bc-8d520497d9da" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">concern_for_product_controller</span></li>
<li style="background:#f3f3f3;">{</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">static</span> <span style="color:#2b91af;">ProductController</span> _controller;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;<span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">static</span> <span style="color:#2b91af;">IProductRepository</span> _productRepository;</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff;">static</span> <span style="color:#2b91af;">RhinoAutoMocker</span>&lt;<span style="color:#2b91af;">ProductController</span>&gt; mocker;</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#2b91af;">Establish</span> context =</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mocker = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">RhinoAutoMocker</span>&lt;<span style="color:#2b91af;">ProductController</span>&gt;();</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;_controller = mocker.ClassUnderTest;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;_productRepository = mocker.Get&lt;<span style="color:#2b91af;">IProductRepository</span>&gt;();</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;};</li>
<li style="background:#f3f3f3;">}</li>
</ol></div>
</p></div>
</p></div>
<p>So what’s going on here?</p>
<ol>
<li>We’ve introduced an instance of the AutoMocker for our Product Controller. </li>
<li>To make life easier we’ve introduced a field which references the AutoMocker’s “class under test” (in this case our Product Controller). </li>
<li>We’ve asked AutoMocker for an instance of IProductRepository and also referenced this as a handy field (which we can use in our tests). </li>
</ol>
<p>Now we can turn our attention back to the test.</p>
<h3>Setting Expectations</h3>
</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:11c02993-b9ad-430d-8ed0-824f1e105787" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">static</span> <span style="color:#2b91af;">ActionResult</span> _result;</li>
<li style="background:#f3f3f3;">&#160;</li>
<li>&#160;<span style="color:#2b91af;">Because</span> of =</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;() =&gt; { _result = _controller.Search(<span style="color:#a31515;">&quot;test&quot;</span>); };</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">&#160;<span style="color:#2b91af;">It</span> should_retrieve_a_list_of_products_with_titles_containing_the_search_term =</li>
<li>&#160;&#160;&#160;&#160;&#160;() =&gt; _productRepository.AssertWasCalled(x =&gt; x.FindProducts(<span style="color:#a31515;">&quot;test&quot;</span>));</li>
</ol></div>
</p></div>
</p></div>
</p>
<ol>
<li>We call a new overloaded version of our controller’s <strong>Search </strong>method (which accepts a string search term). </li>
<li>Then we perform a simple check to assert that the <strong>FindProducts</strong> method was called on <strong>IProductRepository</strong>. </li>
</ol>
<p>Finally, we want to check what gets sent back to the view. For now we’ll simply check the name of the view being returned (and that the result is a view).</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ba3df834-63f7-41bd-8023-b47d04824b44" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#2b91af;">It</span> should_return_the_list_of_products_to_the_user =</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;() =&gt; _result.is_a_view_and().ViewName.ShouldEqual(<span style="color:#a31515;">&quot;SearchResults&quot;</span>);</li>
</ol></div>
</p></div>
</p></div>
<p>As I’ve gone along here I’ve implemented just enough to have the test compile.</p>
<h5>IProductRepository</h5>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:076a8d62-186d-413a-8e32-7dc15618b77e" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">interface</span> <span style="color:#2b91af;">IProductRepository</span></li>
<li style="background:#f3f3f3;">{</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#2b91af;">IList</span>&lt;<span style="color:#2b91af;">Product</span>&gt; FindProducts(<span style="color:#0000ff;">string</span> searchTerm);</li>
<li style="background:#f3f3f3;">}</li>
</ol></div>
</p></div>
</p></div>
<h5>ProductController</h5>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a2d2fb68-73b2-4e7b-a86c-e59cd86e4057" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">public</span> <span style="color:#2b91af;">ActionResult</span> Search(<span style="color:#0000ff;">string</span> searchTerm)</li>
<li style="background:#f3f3f3;">{</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff;">throw</span> <span style="color:#0000ff;">new</span> NotImplementedException();</li>
<li style="background:#f3f3f3;">}</li>
</ol></div>
</p></div>
</p></div>
<p>At this point we want to make the test pass so let’s do that.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9525f71e-488a-44fb-8fc1-0b7eecbbd49f" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">readonly</span> <span style="color:#2b91af;">IProductRepository</span> _productRepository;</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li><span style="color:#0000ff;">public</span> ProductController(<span style="color:#2b91af;">IProductRepository</span> productRepository)</li>
<li style="background:#f3f3f3;">{</li>
<li>&#160;&#160;&#160;&#160;_productRepository = productRepository;</li>
<li style="background:#f3f3f3;">}</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">public</span> <span style="color:#2b91af;">ActionResult</span> Search(<span style="color:#0000ff;">string</span> searchTerm)</li>
<li>{</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;<span style="color:#0000ff;">return</span> View(<span style="color:#a31515;">&quot;SearchResults&quot;</span>, _productRepository.FindProducts(searchTerm));</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>Now our MSpec tests will pass.</p>
<p>When we run the tests, AutoMocker will generate a mocked version of our IProductRepository which our test uses to assert which methods were called. By letting AutoMocker generate our mocks we cut down on a lot of boilerplate code but don’t really loose anything in terms of flexibility and control (we can manually add mocks if we don’t want AutoMocker handling them for us).</p>
<h3>Stubs</h3>
<p>Now lets say we want to check that the list of products retrieved from the repository is actually sent back with the view.</p>
<p>For this, we can set up the automocked IProductRepository to return a specific list of products which we can then check are sent back to the user.</p>
<p>Lets start by telling automocker to stub the <strong>Search</strong> method and return a new list of products.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:11ef5865-c2e0-411f-b430-874c8ea9e33d" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#2b91af;">Establish</span> context =</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;() =&gt;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;_products = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">Product</span>&gt;();</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;_productRepository.Stub(x =&gt; x.FindProducts(<span style="color:#a31515;">&quot;test&quot;</span>)).Return(_products);</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;};</li>
</ol></div>
</p></div>
</p></div>
<ol>
<li>We’ve added an <strong>Establish Context</strong> to our test (this will be used in conjunction with the one in our base class) </li>
<li>We’ve said that when the <strong>FindProducts</strong> method is called with the parameter “<strong>test”</strong> then a new generic list of Product will be returned </li>
</ol>
<p>Now we’ll change the implementation of the spec to check that this same list of products is returned with the view. Whilst we’re at it we’ll move the test for the view’s name into it’s own specification.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a33ac588-c516-4ea2-8c4a-7584ceae71a8" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#2b91af;">It</span> should_return_the_list_of_products_to_the_user =</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;() =&gt; _result.is_a_view_and().ViewData.Model.ShouldEqual(_products);</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;"><span style="color:#2b91af;">It</span> should_return_the_search_results_page_to_the_user =</li>
<li>&#160;&#160;&#160;&#160;() =&gt; _result.is_a_view_and().ViewName.ShouldEqual(<span style="color:#a31515;">&quot;SearchResults&quot;</span>);</li>
</ol></div>
</p></div>
</p></div>
<h3>Putting it all together</h3>
<p>So finally, our completed test implementation now looks like this…</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:af6309b1-4c23-4127-8b43-5ec7dbc43b2b" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li>[<span style="color:#2b91af;">Subject</span>(<span style="color:#a31515;">&quot;Product Search&quot;</span>)]</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">when_asked_for_products_matching_search_term</span> : <span style="color:#2b91af;">concern_for_product_controller</span></li>
<li>{</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;<span style="color:#0000ff;">static</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">Product</span>&gt; _products;</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff;">static</span> <span style="color:#2b91af;">ActionResult</span> _result;</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#2b91af;">Establish</span> context =</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;{</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;_products = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">Product</span>&gt;();</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;_productRepository.Stub(x =&gt; x.FindProducts(<span style="color:#a31515;">&quot;test&quot;</span>)).Return(_products);</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;};</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;<span style="color:#2b91af;">Because</span> of =</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt; { _result = _controller.Search(<span style="color:#a31515;">&quot;test&quot;</span>); };</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#2b91af;">It</span> should_retrieve_a_list_of_products_with_titles_containing_the_search_term =</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt; _productRepository.AssertWasCalled(x =&gt; x.FindProducts(<span style="color:#a31515;">&quot;test&quot;</span>));</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;<span style="color:#2b91af;">It</span> should_return_the_list_of_products_to_the_user =</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt; _result.is_a_view_and().ViewData.Model.ShouldEqual(_products);</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#2b91af;">It</span> should_return_the_search_results_page_to_the_user =</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt; _result.is_a_view_and().ViewName.ShouldEqual(<span style="color:#a31515;">&quot;SearchResults&quot;</span>);</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>Hopefully these posts have demonstrated how well MSpec and Rhino AutoMocker can work together. The key is that the tests are easy to maintain and clearly state the criteria by which to judge whether the code under test is valid. </p>
<p>These criteria are stated as human understandable specifications which can be agreed with your users before writing any code. RhinoAutoMocker makes mocking and stubbing very straightforward and helps you to defer making decisions until the <a href="http://www.codinghorror.com/blog/archives/000705.html" target="_blank">last responsible moment</a>.</p>
<p>You will find the source code for this sample project on <a href="http://github.com/jonhilt/MSpec-Example" target="_blank">GitHub</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/telldontask.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/telldontask.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/telldontask.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/telldontask.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/telldontask.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/telldontask.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/telldontask.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/telldontask.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/telldontask.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/telldontask.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/telldontask.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/telldontask.wordpress.com/78/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/telldontask.wordpress.com/78/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/telldontask.wordpress.com/78/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=78&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://telldontask.wordpress.com/2009/11/29/bdd-with-mspec-and-rhino-auto-mocks-part-3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b6cf9c1a25c7a667c1592e513624bea1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">telldontask</media:title>
		</media:content>
	</item>
		<item>
		<title>BDD with MSpec and Rhino Auto Mocks (part 2)</title>
		<link>http://telldontask.wordpress.com/2009/11/19/bdd-with-mspec-and-rhino-auto-mocks-part-2/</link>
		<comments>http://telldontask.wordpress.com/2009/11/19/bdd-with-mspec-and-rhino-auto-mocks-part-2/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 22:07:07 +0000</pubDate>
		<dc:creator>telldontask</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[MSpecs]]></category>
		<category><![CDATA[RhinoMocks]]></category>

		<guid isPermaLink="false">http://telldontask.wordpress.com/2009/11/19/bdd-with-mspec-and-rhino-auto-mocks-part-2/</guid>
		<description><![CDATA[In part 1, we looked at setting up MSpec and writing our first specifications. Now we get on to the all important implementation stage. We ended up with these basic specifications by the end of part 1. using Machine.Specifications; &#160; namespace MSpecExample.Tests.Controllers { &#160;&#160;&#160;&#160;[Subject(&#34;Product Search&#34;)] &#160;&#160;&#160;&#160;public class when_product_search_page_requested &#160;&#160;&#160;&#160;{ &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;It should_return_product_search_page; &#160;&#160;&#160;&#160;} &#160; &#160;&#160;&#160;&#160;[Subject(&#34;Product Search&#34;)] [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=65&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://telldontask.wordpress.com/2009/11/10/bdd-with-mspec-and-rhino-auto-mocks/" target="_blank">part 1</a>, we looked at setting up MSpec and writing our first specifications.</p>
<p>Now we get on to the all important implementation stage.</p>
<p>We ended up with these basic specifications by the end of part 1.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1ca757a8-93ed-4f22-9aab-fcf36de68814" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">using</span> Machine.Specifications;</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li><span style="color:#0000ff;">namespace</span> MSpecExample.Tests.Controllers</li>
<li style="background:#f3f3f3;">{</li>
<li>&#160;&#160;&#160;&#160;[Subject(<span style="color:#a31515;">&quot;Product Search&quot;</span>)]</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">when_product_search_page_requested</span></li>
<li>&#160;&#160;&#160;&#160;{</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;It should_return_product_search_page;</li>
<li>&#160;&#160;&#160;&#160;}</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;[Subject(<span style="color:#a31515;">&quot;Product Search&quot;</span>)]</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">when_asked_for_products_matching_search_term</span></li>
<li>&#160;&#160;&#160;&#160;{</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;It should_retrieve_a_list_of_products_with_titles_containing_the_search_term;</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;It should_return_the_list_of_products_to_the_user;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;}</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;[Subject(<span style="color:#a31515;">&quot;Product Search&quot;</span>)]</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">when_empty_search_term_entered</span></li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;{</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;It should_return_an_error_message;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;}</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>Lets start by implementing the first one (when product search page requested).</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:40976112-f779-4d8e-b6be-373e7f02af6d" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li>[Subject(<span style="color:#a31515;">&quot;Product Search&quot;</span>)]</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">when_product_search_page_requested</span></li>
<li>{</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;<span style="color:#0000ff;">static</span> ProductController _controller;</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;Establish context =</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt; {</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;_controller = <span style="color:#0000ff;">new</span> ProductController();</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;};</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;It should_return_product_search_page;</li>
<li style="background:#f3f3f3;">}</li>
</ol></div>
</p></div>
</p></div>
<p>On first glance, the wacky syntax here might put people off. However, once you start writing these tests you tend to see past it to the specs and the tests themselves. </p>
<p>We start by establishing the context for our test, what we need for this test to actually run. In this case it’s the product controller that we’re testing, and so it makes sense to instantiate the product controller and assign it to a field for use within our tests.</p>
<p>Next we need to actually do something, perform the action which we are testing. In this case we’re talking about the user visiting the “product search page” so I will set up the test to call an action on the product controller called <strong>Search</strong>.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2a2be4e6-e972-4754-a1f5-605d18c80bb0" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li>[Subject(<span style="color:#a31515;">&quot;Product Search&quot;</span>)]</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">when_product_search_page_requested</span></li>
<li>{</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;<span style="color:#0000ff;">static</span> ProductController _controller;</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff;">static</span> ActionResult _result;</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;Establish context =</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt; { _controller = <span style="color:#0000ff;">new</span> ProductController(); };</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;Because of =</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt; { _result = _controller.Search(); };</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;It should_return_product_search_page;</li>
<li style="background:#f3f3f3;">}</li>
</ol></div>
</p></div>
</p></div>
<p>Note how we have created a <strong>Because</strong> statement. In BDD terms this is the behaviour we are testing. As with the controller I store the result of calling this action in a field so we can use it elsewhere in the test.</p>
<p>At this point I should point out that in the spirit of TDD, I am only doing enough at this point to make this compile. So our <strong>Product Controller</strong> currently looks like this.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e85091b4-8a78-413e-be69-2c6244098c57" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">ProductController</span> : Controller</li>
<li style="background:#f3f3f3;">{</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff;">public</span> ActionResult Search()</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;{</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff;">throw</span> <span style="color:#0000ff;">new</span> NotImplementedException();</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;}</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>Jumping back to our test, lets test that the behaviour under test (search) does what we expect.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:84e8b6cb-0426-40ff-9ad6-2365b5c42445" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li>[Subject(<span style="color:#a31515;">&quot;Product Search&quot;</span>)]</li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">when_product_search_page_requested</span></li>
<li>{</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;<span style="color:#0000ff;">static</span> ProductController _controller;</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff;">static</span> ActionResult _result;</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;Establish context =</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt; { _controller = <span style="color:#0000ff;">new</span> ProductController(); };</li>
<li>&nbsp;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;Because of =</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt; { _result = _controller.Search(); };</li>
<li style="background:#f3f3f3;">&nbsp;</li>
<li>&#160;&#160;&#160;&#160;It should_return_product_search_page =</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;() =&gt; { _result.is_a_view_and().ViewName.ShouldEqual(<span style="color:#a31515;">&quot;Search&quot;</span>); };</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>Using an extension method (thank you <a href="http://tinyurl.com/nl5jte" target="_blank">James Broome</a> and <a href="http://tinyurl.com/y9uccrh" target="_blank">JP Boodhoo</a>) we can simultaneously check that our result is a view and also get a typed reference to the result (as a ViewResult).</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5219127d-924b-44d2-b08f-5e4116387f47" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">TestExtensions</span></li>
<li style="background:#f3f3f3;">{</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> ViewResult is_a_view_and(<span style="color:#0000ff;">this</span> ActionResult result)</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;{</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff;">return</span> result <span style="color:#0000ff;">as</span> ViewResult;</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;}</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>Now we make the test pass.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0810fea1-77d7-4c22-b466-06f3c9b9f169" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">ProductController</span> : Controller</li>
<li style="background:#f3f3f3;">{</li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff;">public</span> ActionResult Search()</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;{</li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff;">return</span> View(<span style="color:#a31515;">&quot;Search&quot;</span>);</li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;}</li>
<li>}</li>
</ol></div>
</p></div>
</p></div>
<p>Finally we run MSpec and marvel at the results <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><a href="http://telldontask.files.wordpress.com/2009/11/image3.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://telldontask.files.wordpress.com/2009/11/image_thumb3.png?w=598&#038;h=240" width="598" height="240" /></a></p>
<p>We still have several not implemented specs, but the one we have implemented now appears as a simple line of text. If there were any problems with the test (if it failed) we would see a red error message by the failing specification.</p>
<p>In <a href="http://telldontask.wordpress.com/2009/11/29/bdd-with-mspec-and-rhino-auto-mocks-part-3/" target="_blank">part 3</a> we’ll look at more complex controller actions and introduce Rhino Auto Mocker.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/telldontask.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/telldontask.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/telldontask.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/telldontask.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/telldontask.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/telldontask.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/telldontask.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/telldontask.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/telldontask.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/telldontask.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/telldontask.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/telldontask.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/telldontask.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/telldontask.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=65&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://telldontask.wordpress.com/2009/11/19/bdd-with-mspec-and-rhino-auto-mocks-part-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b6cf9c1a25c7a667c1592e513624bea1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">telldontask</media:title>
		</media:content>

		<media:content url="http://telldontask.files.wordpress.com/2009/11/image_thumb3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>BDD with MSpec and Rhino Auto Mocks (part 1)</title>
		<link>http://telldontask.wordpress.com/2009/11/10/bdd-with-mspec-and-rhino-auto-mocks/</link>
		<comments>http://telldontask.wordpress.com/2009/11/10/bdd-with-mspec-and-rhino-auto-mocks/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 23:40:42 +0000</pubDate>
		<dc:creator>telldontask</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[MSpecs]]></category>
		<category><![CDATA[RhinoMocks]]></category>

		<guid isPermaLink="false">http://telldontask.wordpress.com/2009/11/10/bdd-with-mspec-and-rhino-auto-mocks/</guid>
		<description><![CDATA[I’ve long been a fan of test driven development in theory but in practice have experienced many of the issues which turn people off TDD and unit testing in general. Brittle tests which do too much, tell you very little about the meaning behind the code and are more a hindrance than a help when [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=9&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’ve long been a fan of test driven development in theory but in practice have experienced many of the issues which turn people off TDD and unit testing in general.</p>
<p>Brittle tests which do too much, tell you very little about the meaning behind the code and are more a hindrance than a help when it comes to making changes at a later date.</p>
<p>Well as you may have guessed, given the title of this post, I have found an answer to these problems in the form of BDD using MSpec and Rhino Automocking. I have been using this approach for a good while now and continue to be pleasantly surprised by just how much fun it is writing my tests, but also how stupidly easy they are to change, and how well they document my project’s requirements.</p>
<p><strong>Update: You can get MSpec from <a href="http://github.com/machine/machine.specifications" target="_blank">github</a></strong><strong>.</strong></p>
<h3>External Tool</h3>
<p>It’s a good idea to set up an external tool in Visual Studio to run your MSpec tests and produce html output.</p>
<p>Create a new external tool which launches <strong>mspec.exe</strong> with the following arguments.</p>
<p><strong><code>$(TargetName)$(TargetExt) --html &quot;$(ProjectDir)\Report.html&quot;</code></strong></p>
<p>Make sure the initial directory is <strong>$(BinDir)</strong> and tick <strong>Use output window</strong>.</p>
<p><a href="http://telldontask.files.wordpress.com/2009/11/image4.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://telldontask.files.wordpress.com/2009/11/image_thumb4.png?w=469&#038;h=457" width="469" height="457" /></a>&#160;</p>
<h3>Using your favourite Test Runner</h3>
<p>Included in the MSpec download are scripts to configure various test runners to recognise and run MSpec tests.</p>
<p><a href="http://telldontask.files.wordpress.com/2009/11/image5.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://telldontask.files.wordpress.com/2009/11/image_thumb5.png?w=491&#038;h=314" width="491" height="314" /></a></p>
<p>Simply run the bat file which relates to your build runner and way you go!</p>
<h3>Writing Specifications</h3>
<p>Ensure you add a reference (in your Tests Project) to <strong>Machine.Specifications.dll.</strong></p>
<p>Now the fun begins.</p>
<p>I’ve created an ASP.NET MVC site and empty class library Tests project.</p>
<p>Let’s say we want to create a simple page which allows users to search for a product.</p>
<p>We’ll start by creating a new folder in our tests folder called <strong>Controllers</strong> and add a new class file called <strong>ProductControllerTets.cs</strong></p>
<p>Having discussed this feature in detail with the client, I’ve a pretty good idea of what they want, so I start with the following.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7a1638e4-1630-4538-9a41-599d5d0dc95b" class="wlWriterSmartContent">
<div style="border-bottom:#000080 1px solid;border-left:#000080 1px solid;font-family:&#039;color:#000;font-size:10pt;border-top:#000080 1px solid;border-right:#000080 1px solid;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">using</span> Machine.Specifications; </li>
<li style="background:#f3f3f3;">&#160; </li>
<li><span style="color:#0000ff;">namespace</span> MSpecExample.Tests.Controllers </li>
<li style="background:#f3f3f3;">{ </li>
<li>&#160;&#160;&#160; [<span style="color:#2b91af;">Subject</span>(<span style="color:#a31515;">&quot;Product Search&quot;</span>)] </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160; <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">when_product_search_page_requested</span> </li>
<li>&#160;&#160;&#160; { </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:#2b91af;">It</span> should_return_product_search_page; </li>
<li>&#160;&#160;&#160; } </li>
<li style="background:#f3f3f3;">&#160; </li>
<li>&#160;&#160;&#160; [<span style="color:#2b91af;">Subject</span>(<span style="color:#a31515;">&quot;Product Search&quot;</span>)] </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160; <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">when_asked_for_products_matching_search_term</span> </li>
<li>&#160;&#160;&#160; { </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:#2b91af;">It</span> should_retrieve_a_list_of_products_with_titles_containing_the_search_term; </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:#2b91af;">It</span> should_return_the_list_of_products_to_the_user; </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160; } </li>
<li>&#160; </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160; [<span style="color:#2b91af;">Subject</span>(<span style="color:#a31515;">&quot;Product Search&quot;</span>)] </li>
<li>&#160;&#160;&#160; <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">when_empty_search_term_entered</span> </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160; { </li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:#2b91af;">It</span> should_return_an_error_message; </li>
<li style="background:#f3f3f3;">&#160;&#160;&#160; } </li>
<li>} </li>
</ol></div>
</p></div>
</p></div>
<p>What I particularly like about this, is that you can really think about exactly what you’re doing and express it in code which will eventually become executable tests without actually implementing any code (yet!).</p>
<p>If we now build our test project and run the tests using the console runner via the external tool we set up earlier), we’ll get a <strong>report.html</strong> file in the tests project which looks like this…</p>
<p><a href="http://telldontask.files.wordpress.com/2009/11/image2.png"><img style="display:inline;border-width:0;" title="image" border="0" alt="image" src="http://telldontask.files.wordpress.com/2009/11/image_thumb2.png?w=715&#038;h=460" width="715" height="460" /></a></p>
<p>In <a href="http://telldontask.wordpress.com/2009/11/19/bdd-with-mspec-and-rhino-auto-mocks-part-2/" target="_blank">part 2</a>, we&#8217;ll start implementing these tests.</p>
<p>In <a href="http://telldontask.wordpress.com/2009/11/29/bdd-with-mspec-and-rhino-auto-mocks-part-3/" target="_blank">part 3</a>, we’ll introduce Rhino AutoMocker.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/telldontask.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/telldontask.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/telldontask.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/telldontask.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/telldontask.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/telldontask.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/telldontask.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/telldontask.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/telldontask.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/telldontask.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/telldontask.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/telldontask.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/telldontask.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/telldontask.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=9&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://telldontask.wordpress.com/2009/11/10/bdd-with-mspec-and-rhino-auto-mocks/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b6cf9c1a25c7a667c1592e513624bea1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">telldontask</media:title>
		</media:content>

		<media:content url="http://telldontask.files.wordpress.com/2009/11/image_thumb4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://telldontask.files.wordpress.com/2009/11/image_thumb5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://telldontask.files.wordpress.com/2009/11/image_thumb2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>Hello WordPress!</title>
		<link>http://telldontask.wordpress.com/2009/11/10/hello-world/</link>
		<comments>http://telldontask.wordpress.com/2009/11/10/hello-world/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 23:31:43 +0000</pubDate>
		<dc:creator>telldontask</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I’ve decided to switch my blog to WordPress. I&#8217;ll be using Windows Live Writer to write most of my posts and the excellent Paste as Visual Studio Code plugin to handle c# code excerpts.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=1&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’ve decided to switch my blog to WordPress.</p>
<p>I&#8217;ll be using Windows Live Writer to write most of my posts and the excellent <a href="http://tinyurl.com/yevfvdb" target="_blank">Paste as Visual Studio Code</a> plugin to handle c# code excerpts.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/telldontask.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/telldontask.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/telldontask.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/telldontask.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/telldontask.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/telldontask.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/telldontask.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/telldontask.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/telldontask.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/telldontask.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/telldontask.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/telldontask.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/telldontask.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/telldontask.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=1&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://telldontask.wordpress.com/2009/11/10/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b6cf9c1a25c7a667c1592e513624bea1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">telldontask</media:title>
		</media:content>
	</item>
		<item>
		<title>Fluent NHibernate Gotcha</title>
		<link>http://telldontask.wordpress.com/2009/10/19/fluent-nhibernate-gotcha/</link>
		<comments>http://telldontask.wordpress.com/2009/10/19/fluent-nhibernate-gotcha/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 14:04:00 +0000</pubDate>
		<dc:creator>telldontask</dc:creator>
				<category><![CDATA[Fluent NHibernate]]></category>
		<category><![CDATA[Gotchas]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[S#arp Architecture]]></category>

		<guid isPermaLink="false">http://telldontask.wordpress.com/2009/10/19/fluent-nhibernate-gotcha</guid>
		<description><![CDATA[It seems today’s the day for me to make daft mistakes and then blog about them. If you’re using Fluent NHibernate (and there are many reasons why you should ) and see this error message… An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail. &#160; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=48&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It seems today’s the day for me to make daft mistakes and then blog about them.</p>
<p>If you’re using Fluent NHibernate (and there are many reasons why you should <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) and see this error message…</p>
<p><em>An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.      <br />&#160; * Database was not configured through Database method.</em></p>
<p><em>System.IndexOutOfRangeException: Index was outside the bounds of the array.</em></p>
<p><em>at System.Array.InternalGetReference(Void* elemRef, Int32 rank, Int32* pIndices)      <br />at System.Array.GetValue(Int32 index)       <br />at NHibernate.Type.AbstractEnumType..ctor(SqlType sqlType, Type enumType)       <br />at NHibernate.Type.EnumStringType..ctor(Type enumClass)       <br />at FluentNHibernate.Mapping.GenericEnumMapper`1..ctor()</em></p>
<p>Do yourself a favour and check you haven’t left any empty Enums in your domain layer (the one that Fluent NHibernate is using to map to your database).</p>
<p>Funnily enough, if you do have an empty Enum, I don’t know, off the top of my head maybe something like this…</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:79ab007c-f4ce-4752-adb9-63ba633f4dc5" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">enum</span> <span style="color:#2b91af;">NoteType</span></li>
<li style="background:#f3f3f3;">{</li>
<li>&#160;&#160;&#160;&#160;</li>
<li style="background:#f3f3f3;">}</li>
</ol></div>
</p></div>
</p></div>
<p>Then you’ll probably get the error above.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/telldontask.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/telldontask.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/telldontask.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/telldontask.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/telldontask.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/telldontask.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/telldontask.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/telldontask.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/telldontask.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/telldontask.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/telldontask.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/telldontask.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/telldontask.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/telldontask.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=48&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://telldontask.wordpress.com/2009/10/19/fluent-nhibernate-gotcha/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b6cf9c1a25c7a667c1592e513624bea1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">telldontask</media:title>
		</media:content>
	</item>
		<item>
		<title>S#arp Architecture WCF Gotcha</title>
		<link>http://telldontask.wordpress.com/2009/10/19/sarp-architecture-wcf-gotcha/</link>
		<comments>http://telldontask.wordpress.com/2009/10/19/sarp-architecture-wcf-gotcha/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 07:33:00 +0000</pubDate>
		<dc:creator>telldontask</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[S#arp Architecture]]></category>

		<guid isPermaLink="false">http://telldontask.wordpress.com/2009/10/19/sarp-architecture-wcf-gotcha</guid>
		<description><![CDATA[We’ve recently adopted the excellent S#arp Architecture for our projects. I highly recommend taking a look at the project site. On Friday I created a simple WCF service using S#arp’s Northwind sample site for&#160; reference. Using WcfTestClient I located my service and attempted to test one of the methods, only to get the following error. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=47&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We’ve recently adopted the excellent S#arp Architecture for our projects. I highly recommend taking a look at the <a href="http://sharparchitecture.net/">project site</a>.</p>
<p>On Friday I created a simple WCF service using S#arp’s Northwind sample site for&#160; reference.</p>
<p>Using WcfTestClient I located my service and attempted to test one of the methods, only to get the following error.</p>
<p><em>Could not load file or assembly &#8216;Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc&#8217; or one of its dependencies. The system cannot find the file specified.</em></p>
<p>I looked for the usual suspects (rogue entries in the GAC, searching the c:\ drive for instances of Castle.Windsor) but couldn’t find the problem.</p>
<p>Eventually I discovered this code in the sample site’s web.config.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cd4b8c43-015c-4528-a679-0f61c1daaae1" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background:#ddd;overflow:auto;">
<ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;">
<li><span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">runtime</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">&#160;&#160;<span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">assemblyBinding</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">xmlns</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">urn:schemas-microsoft-com:asm.v1</span>&quot;<span style="color:#0000ff;">&gt;</span></li>
<li>&#160;&#160;&#160;&#160;<span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">dependentAssembly</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">assemblyIdentity</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">name</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">Castle.Windsor</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">publicKeyToken</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">407dd0808d44fbdc</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">culture</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">neutral</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li>&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#0000ff;">&lt;</span><span style="color:#a31515;">bindingRedirect</span><span style="color:#0000ff;"> </span><span style="color:#ff0000;">oldVersion</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">0.0.0.0-65535.65535.65535.65535</span>&quot;<span style="color:#0000ff;"> </span><span style="color:#ff0000;">newVersion</span><span style="color:#0000ff;">=</span>&quot;<span style="color:#0000ff;">2.0.0.0</span>&quot;<span style="color:#0000ff;">/&gt;</span></li>
<li style="background:#f3f3f3;">&#160;&#160;&#160;&#160;<span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">dependentAssembly</span><span style="color:#0000ff;">&gt;</span></li>
<li>&#160;&#160;<span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">assemblyBinding</span><span style="color:#0000ff;">&gt;</span></li>
<li style="background:#f3f3f3;"><span style="color:#0000ff;">&lt;/</span><span style="color:#a31515;">runtime</span><span style="color:#0000ff;">&gt;</span></li>
</ol></div>
</p></div>
</p></div>
</p>
<p>Copying this to the web.config for my WCF service solved the problem.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/telldontask.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/telldontask.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/telldontask.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/telldontask.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/telldontask.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/telldontask.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/telldontask.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/telldontask.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/telldontask.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/telldontask.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/telldontask.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/telldontask.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/telldontask.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/telldontask.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=telldontask.wordpress.com&amp;blog=10424474&amp;post=47&amp;subd=telldontask&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://telldontask.wordpress.com/2009/10/19/sarp-architecture-wcf-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b6cf9c1a25c7a667c1592e513624bea1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">telldontask</media:title>
		</media:content>
	</item>
	</channel>
</rss>
