<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Mehfuz's WebLog</title><link>http://weblogs.asp.net/mehfuzh/default.aspx</link><description>Live crazy, think different!</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/burncsharp" /><feedburner:info uri="burncsharp" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by/2.0/</creativeCommons:license><image><link>http://creativecommons.org/licenses/by/2.0/</link><url>http://creativecommons.org/images/public/somerights20.gif</url><title>Some Rights Reserved</title></image><feedburner:emailServiceId>burncsharp</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/burncsharp" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.yourminis.com/subscribe.aspx?u=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://www.yourminis.com/images/addtoyourminisbadge.gif">Subscribe with Yourminis.com</feedburner:feedFlare><feedburner:feedFlare href="http://www.flurry.com/pushRssFeed.do?r=fb&amp;url=http%3A%2F%2Ffeeds.feedburner.com%2Fburncsharp" src="http://www.flurry.com/images/flurry_rss_logo2.gif">Subscribe with Flurry</feedburner:feedFlare><item><title>Writing ASP.NET MVC bootstrapper with AutoBox</title><link>http://feedproxy.google.com/~r/burncsharp/~3/nJKr-9l6NCs/writing-asp-net-mvc-bootstrapper-with-autobox.aspx</link><pubDate>Mon, 30 Jan 2012 15:47:10 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:8272204</guid><dc:creator>mehfuzh</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=8272204</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=8272204</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2012/01/30/writing-asp-net-mvc-bootstrapper-with-autobox.aspx#comments</comments><description>&lt;p&gt;This will post will show how you can use AutoBox to easily write a bootstrapper for ASP.NET MVC. I have used the latest version of AutoBox (available from &lt;em&gt;nuget, &lt;/em&gt;this version also includes &lt;em&gt;Castle.Windsor&lt;/em&gt; internally for managing dependencies rather using its own resolver and does not require interface to type naming convention [IAccountRepository –&amp;gt; AccountRepository]) . To understand what is AutoBox , how you can use it for caching using memcached and let it automatically handle dependencies for controllers and repositories, i would recommend to take a look at this post:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/mehfuzh/archive/2011/11/06/introducing-autobox-on-the-fly-dependency-injection-and-caching-container.aspx" target="_blank"&gt;http://weblogs.asp.net/mehfuzh/archive/2011/11/06/introducing-autobox-on-the-fly-dependency-injection-and-caching-container.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Moving forward , let’s consider a simple bootstrapper interface:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:46c414d8-1abb-4173-80b2-ba530f922d60" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IBootStrapperTask&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Execute();&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The &lt;em&gt;Execute()&lt;/em&gt;&amp;#160; method will be invoked during initialization for registering routes, controllers, mappings (&lt;em&gt;AutoMapper&lt;/em&gt;), etc. We will have one static factory (Ex. BootStrapper)&amp;#160; that will initiate it through &lt;em&gt;CommonServiceLocator.&lt;/em&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a04f252d-8743-47af-b7b9-d2ccbdcffeac" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;BootStrapper&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; Executes registered tasks.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Execute()&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ServiceLocator&lt;/span&gt;.Current.GetAllInstances&amp;lt;&lt;span style="color:#2b91af"&gt;IBootStrapperTask&lt;/span&gt;&amp;gt;().ToList().ForEach(task =&amp;gt;task.Execute());&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;A typical example of a bootstrapping task could be &lt;em&gt;RegisterRoutes&lt;/em&gt;:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:216e66e7-c1ad-4d4c-9263-d0d853154138" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;RegisterRoutes&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IBootStrapperTask&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;readonly&lt;/span&gt; &lt;span style="color:#2b91af"&gt;RouteCollection&lt;/span&gt; routes;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; Initializes the new instance of &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;see cref=&amp;quot;RegisterRoutes&amp;quot;/&amp;gt;&lt;/span&gt;&lt;span style="color:#008000"&gt; class.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; RegisterRoutes()&lt;/li&gt; &lt;li&gt;        : &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;RouteTable&lt;/span&gt;.Routes)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// intentionally left blank.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; Initializes the new instance of &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;see cref=&amp;quot;RegisterRoutes&amp;quot;/&amp;gt;&lt;/span&gt;&lt;span style="color:#008000"&gt; class.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#008000"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;internal&lt;/span&gt; RegisterRoutes(&lt;span style="color:#2b91af"&gt;RouteCollection&lt;/span&gt; routes)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.routes = routes;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Execute()&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li&gt;        routes.Clear();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        routes.IgnoreRoute(&lt;span style="color:#a31515"&gt;&amp;quot;{resource}.axd/{*pathInfo}&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;        routes.IgnoreRoute(&lt;span style="color:#a31515"&gt;&amp;quot;{*favicon}&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; {favicon = &lt;span style="color:#a31515"&gt;@&amp;quot;(.*/)?favicon.ico(/.*)?&amp;quot;}&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Routes&lt;/span&gt;.Register(routes);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Here on line 29, i have added &lt;em&gt;Routes.Register &lt;/em&gt;which is similar to the &lt;em&gt;BootStrapper.Execute()&lt;/em&gt; that further narrows down to specific routing classes. For example. &lt;em&gt;AccountRoutes&lt;/em&gt;. &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f3ebc510-760b-4507-a2a2-aaaf988dfb9c" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Register(&lt;span style="color:#2b91af"&gt;RouteCollection&lt;/span&gt; routes)&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;ServiceLocator&lt;/span&gt;.Current.GetAllInstances&amp;lt;&lt;span style="color:#2b91af"&gt;IRoutesRegistration&lt;/span&gt;&amp;gt;().ToList()&lt;/li&gt; &lt;li&gt;       .ForEach(task =&amp;gt; task.Register(routes));&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;The code inside &lt;em&gt;Routes&lt;/em&gt; class again pretty straight forward and exactly identical to &lt;em&gt;BootStrapper&lt;/em&gt; except the &lt;em&gt;IRoutesRegistration &lt;/em&gt;interface&lt;em&gt;. W&lt;/em&gt;e can also have &lt;em&gt;RegisterControllers&lt;/em&gt; but since the dependencies are automatically wired by AutoBox, we only need to specify (if required) what repository methods to be data cached and for what duration.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:a7c5b040-d85c-4841-90f3-6cb80699674d" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;RegisterControllers&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;IBootStrapperTask&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IBootStrapperTask&lt;/span&gt;.Execute()&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Container&lt;/span&gt;.Setup&amp;lt;&lt;span style="color:#2b91af"&gt;ProductRepository&lt;/span&gt;&amp;gt;(x =&amp;gt; x.GetProductDetails(0)).Caches(&lt;span style="color:#2b91af"&gt;TimeSpan&lt;/span&gt;.FromMinutes(1)).VaryByArgs();&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;ControllerBuilder&lt;/span&gt;.Current.SetControllerFactory(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;MyControllerFactory&lt;/span&gt;());&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;More on caching and how &lt;em&gt;MyControllerFactory&lt;/em&gt; should look like; please check my previous post as well as the product documentation. Finally, it’s about gluing the whole thing together and we just need to have these lines in &lt;em&gt;global.asax.cs&lt;/em&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3fef78be-753b-4a8a-bf28-324b4042ea06" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;protected&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Application_Start()&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#008000"&gt;// Initializes autobox self.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Container&lt;/span&gt;.Init();&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;BootStrapper&lt;/span&gt;.Execute();&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;When you will run the project; if you followed the flow then it should work as you have expected it. The project page for AutoBox can be reached here: &lt;a href="http://mehfuzh.github.com/AutoBox/" target="_blank"&gt;http://mehfuzh.github.com/AutoBox/&lt;/a&gt; .&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope that helps&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8272204" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=nJKr-9l6NCs:bPk87BsRdOY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=nJKr-9l6NCs:bPk87BsRdOY:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=nJKr-9l6NCs:bPk87BsRdOY:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=nJKr-9l6NCs:bPk87BsRdOY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=nJKr-9l6NCs:bPk87BsRdOY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/nJKr-9l6NCs" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/AutoBox/default.aspx">AutoBox</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/DI/default.aspx">DI</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/MemCached/default.aspx">MemCached</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/MVC/default.aspx">MVC</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2012/01/30/writing-asp-net-mvc-bootstrapper-with-autobox.aspx</feedburner:origLink></item><item><title>Assert the order of expected calls over instances</title><link>http://feedproxy.google.com/~r/burncsharp/~3/bQUv4DOgqBw/assert-the-order-of-expected-calls-over-instances.aspx</link><pubDate>Fri, 27 Jan 2012 12:24:10 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:8269958</guid><dc:creator>mehfuzh</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=8269958</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=8269958</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2012/01/27/assert-the-order-of-expected-calls-over-instances.aspx#comments</comments><description>&lt;p&gt;How you assert through unit test that an user is authenticated before doing withdraw operation? You can surely verify a method is invoked as expected but if you want to ensure the order right then you might require a little more. JustMock lets you specify the order in which your setups should be executed. This helps you identify the exact way in which a particular logic is implemented.&lt;/p&gt;  &lt;p&gt;To begin, lets consider the following context:&lt;/p&gt;  &lt;p&gt;User wants to withdraw money from his account. Withdraw operation should validate the following goals:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It should check if the user is authenticated &lt;/li&gt;    &lt;li&gt;It should get the balance for the authenticated user and check if the amount to be withdrawn is less than or equals to what is specified. &lt;/li&gt;    &lt;li&gt;Do the withdraw operation and return the remaining balance. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Now we have one &lt;em&gt;IUserService interface&lt;/em&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e72e60d8-51c6-4eb0-8f4e-6a7a29c21190" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IUserSerivce&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; IsAuthenticated { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; }&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;IUser&lt;/span&gt; GetUser();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;One &lt;em&gt;IAccountService&lt;/em&gt; interface to process the accounts operation:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1c5aea31-0d1f-4261-88c0-5573242835dd" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;interface&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IAccountService&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;double&lt;/span&gt; Withdraw(&lt;span style="color:#0000ff"&gt;double&lt;/span&gt; amount);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;double&lt;/span&gt; GetBalance(&lt;span style="color:#2b91af"&gt;IUser&lt;/span&gt; user);&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The basic &lt;em&gt;AccountRepository&lt;/em&gt; class with minimal implementation covering the above context looks like:&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d2b73c03-6cdf-44d9-b776-4f42fc3f6ab1" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;AccountRepsotory&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; AccountRepsotory(&lt;span style="color:#2b91af"&gt;IUserSerivce&lt;/span&gt; userService, &lt;span style="color:#2b91af"&gt;IAccountService&lt;/span&gt; accountService)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.userService = userService;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.accountService = accountService;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color:#0000ff"&gt;double&lt;/span&gt; Withdraw(&lt;span style="color:#0000ff"&gt;double&lt;/span&gt; amount)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (userService.IsAuthenticated)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (accountService.GetBalance(userService.GetUser()) &amp;gt;= amount)&lt;/li&gt; &lt;li&gt;            {&lt;/li&gt; &lt;li&gt;                &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; accountService.Withdraw(amount);&lt;/li&gt; &lt;li&gt;            }&lt;/li&gt; &lt;li&gt;        }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ArgumentException&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;TODO&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;readonly&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IUserSerivce&lt;/span&gt; userService;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;readonly&lt;/span&gt; &lt;span style="color:#2b91af"&gt;IAccountService&lt;/span&gt; accountService;&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Ensuring every step to be executed in an orderly manner , we just need to specify an extra &lt;em&gt;InOrder &lt;/em&gt;option in &lt;em&gt;Mock.Arrange&lt;/em&gt; that will otherwise fail the test during assert for any change of the expected execution order.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9dcb68e7-33af-4389-9f56-e3f4f73a58eb" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;[&lt;span style="color:#2b91af"&gt;TestMethod&lt;/span&gt;]&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ShouldCheckUserAndBalanceInOrderWhenSpecificAmountIsWithdrawn()&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; userService = &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Create&amp;lt;&lt;span style="color:#2b91af"&gt;IUserSerivce&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; accountService = &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Create&amp;lt;&lt;span style="color:#2b91af"&gt;IAccountService&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li&gt;    &lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; user = &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Create&amp;lt;&lt;span style="color:#2b91af"&gt;IUser&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Arrange(() =&amp;gt; userService.IsAuthenticated).Returns(&lt;span style="color:#0000ff"&gt;true&lt;/span&gt;).InOrder();&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Arrange(() =&amp;gt; userService.GetUser()).Returns(user).InOrder();&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Arrange(() =&amp;gt; accountService.GetBalance(user)).Returns(1000).InOrder();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Arrange(() =&amp;gt; accountService.Withdraw(&lt;span style="color:#2b91af"&gt;Arg&lt;/span&gt;.AnyDouble)).Returns((amount) =&amp;gt; 1000 - amount).InOrder();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; repository = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;AccountRepsotory&lt;/span&gt;(userService, accountService);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Assert&lt;/span&gt;.AreEqual(990, repository.Withdraw(10));&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Assert(userService);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Assert(accountService);&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Let’s remove the line# 13 from &lt;em&gt;AccountRepository.Withdraw&lt;/em&gt;&amp;#160; that yields:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:001d3345-f255-4c4c-9b74-3d1e8000da0b" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol start="1" style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color:#0000ff"&gt;double&lt;/span&gt; Withdraw(&lt;span style="color:#0000ff"&gt;double&lt;/span&gt; amount)&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (userService.IsAuthenticated)&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; accountService.Withdraw(amount);&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ArgumentException&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;TODO&amp;quot;&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Since we broke the order, the test will fail with the following message:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/image_58BAABB2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/image_thumb_1F9FBAB1.png" width="666" height="75" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here one thing to notice that &lt;em&gt;InOrder&lt;/em&gt; is applied to different mock instances within the test method scope that makes it effective in most practical and wide variety of scenarios. I have used Q3 SP build for the purpose (Also available via NuGet).&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope that helps&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8269958" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=bQUv4DOgqBw:vbObqFTv6sk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=bQUv4DOgqBw:vbObqFTv6sk:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=bQUv4DOgqBw:vbObqFTv6sk:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=bQUv4DOgqBw:vbObqFTv6sk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=bQUv4DOgqBw:vbObqFTv6sk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/bQUv4DOgqBw" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/JustMock/default.aspx">JustMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Mocking/default.aspx">Mocking</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Unit+Test/default.aspx">Unit Test</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2012/01/27/assert-the-order-of-expected-calls-over-instances.aspx</feedburner:origLink></item><item><title>Asserting a mock with test framework</title><link>http://feedproxy.google.com/~r/burncsharp/~3/Zj5afHUJEy0/asserting-a-mock-with-test-framework.aspx</link><pubDate>Fri, 09 Dec 2011 12:44:40 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:8104168</guid><dc:creator>mehfuzh</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=8104168</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=8104168</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2011/12/09/asserting-a-mock-with-test-framework.aspx#comments</comments><description>&lt;p&gt;When asserting an expected call for its number of occurrences or may be just to verify if the setup/arrange is acted as intended, the tool generally raises assertion that points us to the reason why the test failed. Different mocking tools use different exception classes therefore there is no common way to consolidate them.&lt;/p&gt;  &lt;p&gt;However, if we just take a look into the test framework unless its some alien one, they all have a common underlying structure for Assert.Throws or &lt;em&gt;ExpectedException (MSTest)&lt;/em&gt;. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;em&gt;MS Test (C# and Silverlight)&lt;/em&gt;&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;&lt;em&gt;Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException&lt;/em&gt;&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;&lt;em&gt;NUnit&lt;/em&gt;&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;&lt;em&gt;NUnit.Framework.AssertionException&lt;/em&gt;&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;&lt;em&gt;XUnit&lt;/em&gt;&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;&lt;em&gt;Xunit.Sdk.AssertException&lt;/em&gt;&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;&lt;em&gt;MSpec&lt;/em&gt;&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;&lt;em&gt;Machine.Specifications.SpecificationException&lt;/em&gt;&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;&lt;em&gt;MbUnit&lt;/em&gt;&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;&lt;em&gt;Gallio.Framework.Assertions.AssertionException&lt;/em&gt;&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;blockquote&gt;&lt;/blockquote&gt;  &lt;p&gt;So the point here is that if we just use the existing exception class rather than thinking one of our own, it greatly increases the scope of the tooling support. For example, let’s consider the “Test Results” window inside visual studio 2010 that tells us that &lt;em&gt;Foo.Echo()&lt;/em&gt; is never invoked as it is expected. Since, its just one line and shows only the reason rather the whole stack trace, it is definitely more user-friendly:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/image_049AA131.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/image_thumb_2636CA02.png" width="736" height="58" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Comparing to the one below, for which you even need to expand and see what’s going wrong.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/image_6A2A884C.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/image_thumb_3BF08C92.png" width="737" height="48" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here I mentioned the word “increased tooling support”, of course it means the tool vendors (who are creating runners) never need to know which mocking tool and update their formatting code over considering&amp;#160; a test framework.&lt;/p&gt;  &lt;p&gt;Technically , JustMock dynamically probes the underlying framework which is the idea very much got from this&amp;#160; project at codeplex which I would like to point here:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://fluentassertions.codeplex.com/" target="_blank"&gt;http://fluentassertions.codeplex.com/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The feature is available from Q3 2011 in JustMock Free as well as in commercial edition.&lt;/p&gt;  &lt;p&gt;Hope that helps&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8104168" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=Zj5afHUJEy0:6qMUKs3r3M4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=Zj5afHUJEy0:6qMUKs3r3M4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=Zj5afHUJEy0:6qMUKs3r3M4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=Zj5afHUJEy0:6qMUKs3r3M4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=Zj5afHUJEy0:6qMUKs3r3M4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/Zj5afHUJEy0" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/JustMock/default.aspx">JustMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Mocking/default.aspx">Mocking</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Unit+Test/default.aspx">Unit Test</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2011/12/09/asserting-a-mock-with-test-framework.aspx</feedburner:origLink></item><item><title>Future mocking with #IgnoreInstance</title><link>http://feedproxy.google.com/~r/burncsharp/~3/sL9VKnA_6JM/future-mocking-with-ignoreinstance.aspx</link><pubDate>Fri, 02 Dec 2011 11:36:41 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:8085605</guid><dc:creator>mehfuzh</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=8085605</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=8085605</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2011/12/02/future-mocking-with-ignoreinstance.aspx#comments</comments><description>&lt;p&gt;In my previous post, i showed how JustMock picks mock expectations based on current context without the instance being injected. Based on feedback we found that It’s sometimes confusing and often does not work as intended. However, the context of this post is not to introduce &lt;em&gt;future mocking &lt;/em&gt;rather a new feature that allows you to skip mock instance intentionally (when you can’t pass the dependency through a constructor or via method argument) instead the tool is applying it for you on behalf.&lt;/p&gt;  &lt;p&gt;You can find more on &lt;em&gt;future mocking&lt;/em&gt; and some abstract behind it from my previous post:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/mehfuzh/archive/2011/09/30/future-mocking-revisited.aspx"&gt;http://weblogs.asp.net/mehfuzh/archive/2011/09/30/future-mocking-revisited.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now moving forward, i will represent a code block that fails and then solve it with &lt;strong&gt;Ig&lt;/strong&gt;&lt;em&gt;noreInstance&lt;/em&gt;&amp;#160; modifier. I am of course thankful to &lt;i&gt;Lior Friedman&lt;/i&gt; for pointing me this. So the code that is very much similar to what he showed me:&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Code that fails&lt;/em&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bff80d54-9d64-4173-b4a8-7b9b2fc12f46" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;var&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; fakeUsed = &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Mock&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Create&amp;lt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;UsedClass&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;&amp;gt;();&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Mock&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Arrange(() =&amp;gt; fakeUsed.ReturnFive()).Returns(&lt;/span&gt;&lt;span style="color:#8cd0d3"&gt;7&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Assert&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.AreEqual(&lt;/span&gt;&lt;span style="color:#8cd0d3"&gt;7&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;, fakeUsed.ReturnFive());    &lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Assert&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.AreEqual(&lt;/span&gt;&lt;span style="color:#8cd0d3"&gt;5&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;, &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;new&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;UsedClass&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;().ReturnFive());&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Now , if the context resolve is implicit then both of the calls will return the same value. In this typical use case the search by context wont work because for some arrange I might want to ignore instance and for some other I want to execute the call as it is.&amp;#160; Taking this into account, introduced more explicit &lt;em&gt;ignoreInstance&lt;/em&gt; switch. This will not only let you ignore instance per setup for the same type also make it more pragmatic and to the point since now I know what I am doing, not the tool getting on my&amp;#160; way.&lt;/p&gt;  &lt;p&gt;Therefore only when you want to apply a particular setup for all instance, you will do it like:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:03c185ef-dc68-4a6e-95d7-b3cbbd124dc1" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 400px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;var&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; fakeUsed = &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Mock&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Create&amp;lt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;UsedClass&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;&amp;gt;();&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Mock&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Arrange(() =&amp;gt; fakeUsed.ReturnFive()).Returns(&lt;/span&gt;&lt;span style="color:#8cd0d3"&gt;7&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;).IgnoreInstance();&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Assert&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.AreEqual(&lt;/span&gt;&lt;span style="color:#8cd0d3"&gt;7&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;, fakeUsed.ReturnFive());    &lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Assert&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.AreEqual(&lt;/span&gt;&lt;span style="color:#8cd0d3"&gt;7&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;, &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;new&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;UsedClass&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;().ReturnFive());&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;This is a new feature and available from Q3 2011 build and removes the implicit context search approach. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope that helps&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;P.S. We are gathering next cool feature for JustMock. Since we believe it’s a tool worth when there is a personal touch therefore please send me / us your ideas in the forum or via email or just a tweet.&lt;/em&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8085605" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=sL9VKnA_6JM:gvTDfIETSxk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=sL9VKnA_6JM:gvTDfIETSxk:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=sL9VKnA_6JM:gvTDfIETSxk:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=sL9VKnA_6JM:gvTDfIETSxk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=sL9VKnA_6JM:gvTDfIETSxk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/sL9VKnA_6JM" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/JustMock/default.aspx">JustMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Mocking/default.aspx">Mocking</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Telerik/default.aspx">Telerik</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2011/12/02/future-mocking-with-ignoreinstance.aspx</feedburner:origLink></item><item><title>Introducing AutoBox - On the fly dependency injection and caching container.</title><link>http://feedproxy.google.com/~r/burncsharp/~3/9yTzJ5kcxPk/introducing-autobox-on-the-fly-dependency-injection-and-caching-container.aspx</link><pubDate>Sat, 05 Nov 2011 22:00:29 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:8034637</guid><dc:creator>mehfuzh</dc:creator><slash:comments>6</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=8034637</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=8034637</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2011/11/06/introducing-autobox-on-the-fly-dependency-injection-and-caching-container.aspx#comments</comments><description>&lt;p&gt;Just when we have dependencies for a controller, we need to wrap around our heads to write a bootstrapper that will dynamically inject dependencies for a controller in runtime and once we we want to do&amp;#160; data caching like a particular method in accounts repository need to get cached for a&amp;#160; certain number of time and it should invalidate when someone calls &lt;em&gt;update&lt;/em&gt;, things get complex and may be we get around this with some attribute based solution.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/autoboxLogo-medium_34F69349.jpg"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="autoboxLogo-medium" border="0" alt="autoboxLogo-medium" src="http://weblogs.asp.net/blogs/mehfuzh/autoboxLogo-medium_thumb_4A2498F1.jpg" width="240" height="64" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Therefore, I introduce to you AutoBox. It is a on the fly dependency injection and caching container. It dynamically injects dependencies based on convention. Also, let you cache repository calls to &lt;strong&gt;memcached&lt;/strong&gt; (the most popular cross-platform caching system) which is originally implemented by &lt;em&gt;LiveJournal&lt;/em&gt; and used by high volume site like &lt;em&gt;Youtube&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;Now getting started with AutoBox is simple.&amp;#160; Lets consider that you have a ProductController and the constructor looks something like:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:06f22593-80ad-426e-a3ae-a8ff04a229df" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 100px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; ProductController(&lt;/span&gt;&lt;span style="color:#d0d081"&gt;IProductRepository&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; repository)&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;this&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.repository = repository;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;ProductRepository &lt;/em&gt;is implemented in&lt;em&gt; MyCoolWebSite.Repository&lt;/em&gt; folder where IProductRepository is under&lt;em&gt; MyCoolWebSite.Repository.Abstraction&lt;/em&gt; (Not a required). In the global.ascx you first need to add the following line:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:98194f05-57b2-4cc3-af03-2f388290f1c5" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Container&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Init();&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Here to mention that&amp;#160; AutoBox will do the mapping on demand thus making it lazy.&lt;/p&gt;  &lt;p&gt;Next you need to override the &lt;strong&gt;GetControllerInstance&lt;/strong&gt; from &lt;strong&gt;DefaultControllerFactory&lt;/strong&gt;. Since AutoBox is implemented using &lt;strong&gt;CommonServiceLocator, &lt;/strong&gt;therefore you can directly include &lt;em&gt;&lt;strong&gt;ServiceLocator.Current.GetInstance&lt;/strong&gt;&lt;/em&gt; that will return the target controller with dependencies properly injected.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e6085d89-6041-4ddd-a3c6-738dfb42ef8f" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;class&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;CustomControllerFactory&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; : &lt;/span&gt;&lt;span style="color:#efefaf"&gt;DefaultControllerFactory&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;protected&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;override&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#d0d081"&gt;IController&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; GetControllerInstance(System.Web.Routing.&lt;/span&gt;&lt;span style="color:#efefaf"&gt;RequestContext&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; requestContext, &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Type&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; controllerType)&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;return&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;ServiceLocator&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Current.GetInstance(controllerType) &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;as&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#d0d081"&gt;IController&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Finally, at the end of &lt;em&gt;global.ascx.cs&lt;/em&gt; you need to write the following line; so that all the controller get instance requests go through &lt;em&gt;AutoBox&lt;/em&gt;:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4bdbcb9f-0fdd-486a-a562-3c2ee3a9d822" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;ControllerBuilder&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Current.SetControllerFactory(&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;new&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;CustomControllerFactory&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;());&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hit F5 and and you are ready to roll with dependencies.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now, moving forward there is a method in IProuductRepository lets say IProductReposiroty.GetAllProducts(). You just dont want to hit database all the time, unless invalidated. Therefore, you can further specify (you can also combine that with your bootstrapper that registers routes and mappings using AutoMapper):&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:62f9518b-adb9-45b0-a67e-99813e2327e2" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#efefaf"&gt;Container&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Setup&amp;lt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;ProductRepository&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;&amp;gt;(x =&amp;gt; x.GetAllProducts()).Caches(&lt;/span&gt;&lt;span style="color:#efefaf"&gt;TimeSpan&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.FromMinutes(&lt;/span&gt;&lt;span style="color:#8cd0d3"&gt;1&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;));&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;This tells AutoBox to cache the result of the call (using memcached) that will automatically invalidate after a minute. However you can explicitly specify the method that will invalidate it.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c214a350-b539-467d-90a2-47549cb522f2" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Container&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Setup&amp;lt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;ProductRepository&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;&amp;gt;(x=&amp;gt; x.Create(&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Arg&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Varies&amp;lt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Product&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;&amp;gt;()).Invalidates(x =&amp;gt; x.GetAllProducts());&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;You will notice here that I have used &lt;strong&gt;Arg.Varies{T}&lt;/strong&gt;. Its similar to &lt;em&gt;VaryByParams&lt;/em&gt; in output cache where it tells the tool to invalidate&amp;#160; based on the variable argument value. Finally to make &lt;em&gt;&lt;strong&gt;Memcached&lt;/strong&gt;&lt;/em&gt; working you will need to have the following block in&lt;em&gt; web.config&lt;/em&gt; (will be added automatically when installed from &lt;strong&gt;NuGet [Yes its NuGet]&lt;/strong&gt;).&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d6b51a09-5357-4113-9139-1a42765b5777" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#efefaf"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;xml&lt;/span&gt;&lt;span style="color:#efefaf"&gt; version=&lt;/span&gt;&amp;quot;&lt;span style="color:#dca3a3"&gt;1.0&lt;/span&gt;&amp;quot;&lt;span style="color:#efefaf"&gt; encoding=&lt;/span&gt;&amp;quot;&lt;span style="color:#dca3a3"&gt;utf-8&lt;/span&gt;&amp;quot;&lt;span style="color:#efefaf"&gt;?&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#efefaf"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;configuration&lt;/span&gt;&lt;span style="color:#efefaf"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;  &lt;span style="color:#efefaf"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;configSections&lt;/span&gt;&lt;span style="color:#efefaf"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#efefaf"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;section&lt;/span&gt;&lt;span style="color:#efefaf"&gt; name=&lt;/span&gt;&amp;quot;&lt;span style="color:#dca3a3"&gt;autoBox&lt;/span&gt;&amp;quot;&lt;span style="color:#efefaf"&gt; type=&lt;/span&gt;&amp;quot;&lt;span style="color:#dca3a3"&gt;AutoBox.AutoBoxSection, AutoBox&lt;/span&gt;&amp;quot;&lt;span style="color:#efefaf"&gt; /&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;  &lt;span style="color:#efefaf"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;configSections&lt;/span&gt;&lt;span style="color:#efefaf"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;  &lt;span style="color:#efefaf"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;autoBox&lt;/span&gt;&lt;span style="color:#efefaf"&gt; cacheStore=&lt;/span&gt;&amp;quot;&lt;span style="color:#dca3a3"&gt;localhost&lt;/span&gt;&amp;quot;&lt;span style="color:#efefaf"&gt; cacheProvider=&lt;/span&gt;&amp;quot;&lt;span style="color:#dca3a3"&gt;MemcachedProvider&lt;/span&gt;&amp;quot;&lt;span style="color:#efefaf"&gt; /&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#efefaf"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;configuration&lt;/span&gt;&lt;span style="color:#efefaf"&gt;&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here you will notice that by default its pointing to &lt;em&gt;localhost&lt;/em&gt; and &lt;em&gt;MemcachedProvider&lt;/em&gt;. However it can be an external IP pointing to &lt;strong&gt;Amazon ElastiCache &lt;/strong&gt;(released a few weeks ago).Here to note that memcached is a caching mechanism and therefore the tool is agnostic of any underlying cloud service that you may use.&lt;/p&gt;  &lt;p&gt;To test caching locally, you can use the &lt;em&gt;&lt;strong&gt;CouchBase’s Membase&lt;/strong&gt; server&lt;/em&gt; (Not limited to), it gives you a nice web based GUI to monitor the cache usage, configure memory and clusters.&lt;/p&gt;  &lt;p&gt;You can download it from this link:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.couchbase.com/products-and-services/memcached/" target="_blank"&gt;http://www.couchbase.com/products-and-services/memcached/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;You can get more information on this project, download source and contribute at the following URL:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://mehfuzh.github.com/AutoBox/" target="_blank"&gt;http://mehfuzh.github.com/AutoBox/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;As mentioned above, it is also possible to use the tool with a hand-rolled bootstrapper that uses IOC container (Ex. Ninject) and AutoMapper&amp;#160; and can save you some lines in binding the controller dependencies and if you want to use high-performance caching mechanism like memcached and don’t&amp;#160; want to pull your hair off on how to invalidate a repository call when saved a part of it then this tool can give you a boost.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope that helps&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=8034637" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=9yTzJ5kcxPk:gZR8Ix4j7F8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=9yTzJ5kcxPk:gZR8Ix4j7F8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=9yTzJ5kcxPk:gZR8Ix4j7F8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=9yTzJ5kcxPk:gZR8Ix4j7F8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=9yTzJ5kcxPk:gZR8Ix4j7F8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/9yTzJ5kcxPk" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/AutoBox/default.aspx">AutoBox</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/couchbase/default.aspx">couchbase</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/DI/default.aspx">DI</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/MemCached/default.aspx">MemCached</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/MVC/default.aspx">MVC</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2011/11/06/introducing-autobox-on-the-fly-dependency-injection-and-caching-container.aspx</feedburner:origLink></item><item><title>Future mocking revisited</title><link>http://feedproxy.google.com/~r/burncsharp/~3/x9-OdBw3AUk/future-mocking-revisited.aspx</link><pubDate>Fri, 30 Sep 2011 12:06:41 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7971092</guid><dc:creator>mehfuzh</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7971092</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7971092</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2011/09/30/future-mocking-revisited.aspx#comments</comments><description>&lt;p&gt;Previously , I have posted how it is possible to mock a method without passing the dependency through a constructor / calling method. This is something true for third party controls and tools where we have little control over how its created.&lt;/p&gt;  &lt;p&gt;You can find more on that in the following post:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://weblogs.asp.net/mehfuzh/archive/2011/07/21/fake-a-member-without-worrying-about-passing-the-dependency.aspx" href="http://weblogs.asp.net/mehfuzh/archive/2011/07/21/fake-a-member-without-worrying-about-passing-the-dependency.aspx"&gt;http://weblogs.asp.net/mehfuzh/archive/2011/07/21/fake-a-member-without-worrying-about-passing-the-dependency.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now the feature that lets you mock&amp;#160; members without passing the dependency, we call it&lt;em&gt; Future mocking&lt;/em&gt;. However it does not mean that Justmock ignores the instance completely but rather there is a workflow where it checks if there is no match for instance (of course it is a profiler intensive feature) and mocked within current context it tries to match any setup that is meant for. &lt;/p&gt;  &lt;p&gt;One of the best example that I recently encountered through a community feedback that describes a UI case where based on some action against the form, raises an event which needs to be handled in a specific way in the unit test to assert the expected value.&lt;/p&gt;  &lt;p&gt;Therefore, we have a Form class where the constructor looks something like:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4000905e-1960-4274-9339-f9b9e236fd8e" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; Form2()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;InitializeComponent();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;this&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.service = &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;new&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;EntryService&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;service.Saved += &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;new&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;EventHandler&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;EntrySavedEventArgs&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;&amp;gt;(service_Saved);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;}            &lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;We have a &lt;em&gt;SaveToDatabase&lt;/em&gt; method that on the other hand invokes the Save method in &lt;em&gt;EntryService&lt;/em&gt; and finally raise an event when successfully saved.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7875e797-baea-4bf9-ab01-8b66d1086ab6" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;void&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; SaveToDatabase(&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;string&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; value)&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;try&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;this&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.service.Save(value);&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;catch&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; (&lt;/span&gt;&lt;span style="color:#efefaf"&gt;DuplicateEntryException&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; ex)&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;MessageBox&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Show(&lt;/span&gt;&lt;span style="color:#dca3a3"&gt;&amp;quot;Entry Duplicated &amp;quot;&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; + ex.DuplicatedValue);&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;catch&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; (&lt;/span&gt;&lt;span style="color:#efefaf"&gt;ArgumentNullException&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;this&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.label1.Text = &lt;/span&gt;&lt;span style="color:#dca3a3"&gt;&amp;quot;Valeur manquante&amp;quot;&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here&amp;#160; for now lets consider our event target will have just the following block:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;   &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bd1a7c8f-b02a-4f3c-8ea2-2227ae387776" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#dac6a5"&gt;void&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; service_Saved(&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;object&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; sender, &lt;/span&gt;&lt;span style="color:#efefaf"&gt;EntrySavedEventArgs&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; e)&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;this&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.label1.Text = &lt;/span&gt;&lt;span style="color:#dca3a3"&gt;&amp;quot;Saved string : &amp;quot;&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; + e.EntryValue;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;In the first snippet we can see that &lt;em&gt;EntryService&lt;/em&gt; is created in&amp;#160; the constructor of Form2 class and therefore not injected via some external class/agent. The thing that the particular user wanted to do is to raise the target event with the expected &lt;em&gt;EntryValue&lt;/em&gt; that is passed during &lt;em&gt;SaveToDatabase&lt;/em&gt; call. So the specification for it that verifies such follows:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5f22e9c0-eeea-4494-a50f-7a1d1971e312" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;[&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Subject&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;(&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;typeof&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;(&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Form2&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;))]&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;class&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;when_save_to_database_is_invoked_on_form&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Establish&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; context = () =&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#d0d081"&gt;IEntryService&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; serviceMock = &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Mock&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Create&amp;lt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;EntryService&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;&amp;gt;();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Mock&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Arrange(() =&amp;gt; serviceMock.Save(valueToSave)).Raises(() =&amp;gt; serviceMock.Saved += &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;null&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;, &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;new&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;EntrySavedEventArgs&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;(valueToSave));&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;sut = &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;new&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Form2&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;();         &lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;private&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Because&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; of = () =&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#d7d7c8"&gt;sut.SaveToDatabase(valueToSave);&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;private&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;It&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; should_assert_that_label_contains_expected_valueToSave = () =&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#d7d7c8"&gt;sut.label1.Text.ShouldEqual(&lt;/span&gt;&lt;span style="color:#dca3a3"&gt;&amp;quot;Saved string : &amp;quot;&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; + valueToSave);&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;static&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Form2&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; sut;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;const&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;string&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; valueToSave = &lt;/span&gt;&lt;span style="color:#dca3a3"&gt;&amp;quot;Raise Event&amp;quot;&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Here we can see that although no instance is supplied to the target UI class JM picks up the intended setup from the context. Needless to mention that in code there are smells like labe1 is private and is accessed by specifying &lt;em&gt;InternalsVIsibleTo&amp;#160; &lt;/em&gt;for specification assembly&lt;em&gt; &lt;/em&gt; but rather it should be implemented using MVVM and {Binding Label1 } way. But that is out of the scope of this post and leave that to the reader. I would further thank &lt;em&gt;Vincent Grondin&lt;/em&gt; for the project and you can try this out with the latest release as of today.&lt;/p&gt;  &lt;p&gt;You can further download the sample project here:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:df9dc0ac-6154-4901-89a9-28eeddf75b9b" class="wlWriterEditableSmartContent"&gt;&lt;div&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/MockingExample_24BEF58E.zip" target="_blank"&gt;MockingExample.zip&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Finally, hope this has given you an idea on getting started with future mocking.&lt;/p&gt;  &lt;p&gt;Thanks&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7971092" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=x9-OdBw3AUk:m8ADWHJP7e0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=x9-OdBw3AUk:m8ADWHJP7e0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=x9-OdBw3AUk:m8ADWHJP7e0:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=x9-OdBw3AUk:m8ADWHJP7e0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=x9-OdBw3AUk:m8ADWHJP7e0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/x9-OdBw3AUk" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/JustMock/default.aspx">JustMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Mocking/default.aspx">Mocking</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/MSpec/default.aspx">MSpec</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2011/09/30/future-mocking-revisited.aspx</feedburner:origLink></item><item><title>PostSharp and JustMock side by side.</title><link>http://feedproxy.google.com/~r/burncsharp/~3/1WJHHiI_OzI/postsharp-and-justmock-side-by-side.aspx</link><pubDate>Fri, 05 Aug 2011 16:00:46 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7898529</guid><dc:creator>mehfuzh</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7898529</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7898529</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2011/08/05/postsharp-and-justmock-side-by-side.aspx#comments</comments><description>&lt;p&gt;In this post I will show mocking a member call inside a PostSharp aspect. There were previously compatibility issues between both of the tools running side by side which is now been officially fixed with the most recent release of that tool (&amp;gt;= 2.1.2.8-1594). For those who don’t know what PostSharp is all about, it is a tool that lets you write aspects easily than you can imagine.&lt;/p&gt;  &lt;p&gt;Personally , it took me just minutes to get started with a aspect that will authorize a call before invoking it. Consider that you want to authorize an asp.net MVC controller action and if you ever look into the code you will see that it validates the currently logged in user’s identity.&lt;/p&gt;  &lt;p&gt;In the simplest way I have an Identity class that has a &lt;em&gt;IsAuthenticated&lt;/em&gt; property which is not implemented for sure:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cbfe10ca-f925-4cac-8c20-2c5a326502da" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;class&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Identity&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;static&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;bool&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; IsAuthenticated&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;get&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;throw&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;new&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;NotImplementedException&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;(&lt;/span&gt;&lt;span style="color:#dca3a3"&gt;&amp;quot;Mimic the code User.Identity.IsAuthenticated&amp;quot;&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Next we have an Inventory class that places an order for an authorized user:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8e2e6b4f-c509-423f-bbf2-f827e034bc40" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;class&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Inventory&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt; &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;     &lt;span style="color:#d7d7c8"&gt;[&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Authorize&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;]&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;     &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;bool&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; PlaceOrder(&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Order&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; order)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;     &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;         &lt;span style="color:#d7d7c8"&gt;orders.Add(order);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;         &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;return&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;true&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;     &lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;     &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;bool&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; HasOrders()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;     &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;         &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;return&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; orders.Count &amp;gt; &lt;/span&gt;&lt;span style="color:#8cd0d3"&gt;0&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;     &lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;     &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;private&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#d0d081"&gt;IList&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Order&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;&amp;gt; orders = &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;new&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;List&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Order&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;&amp;gt;();&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt; &lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now AuthorizeAttribute is implemented on &lt;em&gt;MethodInterceptionAspect&lt;/em&gt; where we can write useful&amp;#160; code during the execution of a particular action (return to login page if not authorized, etc). In this case it just skips call for invalid identity.&lt;/p&gt;    &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5cb26bb0-5cff-47cd-8c11-35c0a707cc48" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;[&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Serializable&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;]&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;class&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;AuthorizeAttribute&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; : &lt;/span&gt;&lt;span style="color:#efefaf"&gt;MethodInterceptionAspect&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;override&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;void&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; OnInvoke(&lt;/span&gt;&lt;span style="color:#efefaf"&gt;MethodInterceptionArgs&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; args)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;if&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; (&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Identity&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.IsAuthenticated)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;            &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;base&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.OnInvoke(args);&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;br /&gt;    &lt;p&gt;Here to note that SerializableAttribute is a required attribute by PostSharp. Once you compile the code it will actually write the necessary hooks inside the method based on the aspects you have declared.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Next is a simple test using MSpec where&amp;#160; I ensured that if the identity is valid then it places the order to an inventory.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:59ecaa83-dddb-436a-ab66-02713611a0e0" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;[&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Subject&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;(&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;typeof&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;(&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Inventory&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;))]&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;public&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;class&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;when_authorization_ensures_a_valid_identity&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Establish&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; context = () =&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#efefaf"&gt;Mock&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Arrange(() =&amp;gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Identity&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.IsAuthenticated).Returns(&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;true&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#d7d7c8"&gt;inventory = &lt;/span&gt;&lt;span style="color:#dac6a5"&gt;new&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Inventory&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;();&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;private&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Because&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; of = () =&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;inventory.PlaceOrder(&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;new&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Order&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;(&lt;/span&gt;&lt;span style="color:#dca3a3"&gt;&amp;quot;Talisker&amp;quot;&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;, &lt;/span&gt;&lt;span style="color:#8cd0d3"&gt;1&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;) { OrderDate = &lt;/span&gt;&lt;span style="color:#efefaf"&gt;DateTime&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt;.Now });&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;private&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;It&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; should_assert_that_order_place_was_successful = () =&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;        &lt;span style="color:#d7d7c8"&gt;inventory.HasOrders().ShouldBeTrue();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;   &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#d7d7c8"&gt;&lt;/span&gt;&lt;span style="color:#dac6a5"&gt;static&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; &lt;/span&gt;&lt;span style="color:#efefaf"&gt;Inventory&lt;/span&gt;&lt;span style="color:#d7d7c8"&gt; inventory;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#d7d7c8"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Here I have mocked the static Identity call using the Justmock that intercepts it on top the PostSharp hooks during authorization. Further I used the PostSharp starter edition for the purpose.&lt;/p&gt;  &lt;p&gt;you can find the sample project here : &lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:97772070-e7f1-4fcf-a4fc-27b3e86c1197" class="wlWriterEditableSmartContent"&gt;&lt;div&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/JustMockPostSharp_607917EE.zip" target="_blank"&gt;JustMock+PostSharp.zip&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Happy coding ~~&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7898529" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=1WJHHiI_OzI:8u6vviOnFeE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=1WJHHiI_OzI:8u6vviOnFeE:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=1WJHHiI_OzI:8u6vviOnFeE:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=1WJHHiI_OzI:8u6vviOnFeE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=1WJHHiI_OzI:8u6vviOnFeE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/1WJHHiI_OzI" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/JustMock/default.aspx">JustMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/MSpec/default.aspx">MSpec</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/PostSharp/default.aspx">PostSharp</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2011/08/05/postsharp-and-justmock-side-by-side.aspx</feedburner:origLink></item><item><title>Fake a member without passing the instance via dependency</title><link>http://feedproxy.google.com/~r/burncsharp/~3/BQAaNyBoxio/fake-a-member-without-worrying-about-passing-the-dependency.aspx</link><pubDate>Thu, 21 Jul 2011 10:36:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7878112</guid><dc:creator>mehfuzh</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7878112</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7878112</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2011/07/21/fake-a-member-without-worrying-about-passing-the-dependency.aspx#comments</comments><description>&lt;p&gt;I have came across this several times in forum (telerik) on how I can really fake an item yet I don’t want to pass the instance as an argument. Ideally, this is not a best design but there are third- partly libraries that you have little control over how its written.&amp;nbsp; Anyway, whatever the case might be. This post will show you how you can achieve the above using JustMock. I will be using MSpec in conjunction for the example.&lt;/p&gt;  &lt;p&gt;So here is the sample class that I am going to use:&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6464b8e6-09bc-493f-8db9-97e961ea1391" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: rgb(221, 221, 221); overflow: auto; max-height: 300px;"&gt; &lt;ol style="background: rgb(0, 0, 0); margin: 0px 0px 0px 2em; padding: 0px 0px 0px 5px;"&gt; &lt;li&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;LegacyCode&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; CheckUser(&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; userName, &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; password)&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; _service = &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;LoginService&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;();&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;return&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; _service.ValidateUser(userName, password);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Here &lt;em&gt;CheckUser&lt;/em&gt; is calling&amp;nbsp; &lt;em&gt;LoginService.ValidateUser&lt;/em&gt; that we are going replace with a fake call. Also here is the&amp;nbsp; &lt;em&gt;LoginService &lt;/em&gt;class&lt;em&gt; &lt;/em&gt;that is not much significant just throws exception when &lt;em&gt;ValidateUser&lt;/em&gt; is called that will even confirm if the correct variant is invoked.&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fd4cc166-da3d-42b6-94b8-da7148bc3f59" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: rgb(221, 221, 221); overflow: auto;"&gt; &lt;ol style="background: rgb(0, 0, 0); margin: 0px 0px 0px 2em; padding: 0px 0px 0px 5px;"&gt; &lt;li&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;LoginService&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; ValidateUser(&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; userName, &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; password)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;throw&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; NotImplementedException&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(220, 163, 163);"&gt;"Nothing implemented yet."&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Here is the specification that I wrote with Justmock and MSpec&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:95e21847-27a2-4305-bfa9-990e48775662" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: rgb(221, 221, 221); overflow: auto;"&gt; &lt;ol style="background: rgb(0, 0, 0); margin: 0px 0px 0px 2.5em; padding: 0px 0px 0px 5px;"&gt; &lt;li&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;&amp;nbsp; [&lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;Subject&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;LoginService&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;))]&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;public&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;class&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;when_a_mock_is_called_without_instance_being_injected&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;Establish&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; context = () =&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;service = &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;LoginService&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;Mock&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;.Arrange(() =&amp;gt; service.ValidateUser(userName, password)).MustBeCalled();&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;private&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;Because&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; of = () =&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;var&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; sut = &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;LegacyCode&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;sut.CheckUser(userName, password);&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;};&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;private&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;It&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; must_assert_that_fake_setup_is_invoked_from_context = () =&amp;gt; &lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;Mock&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;.Assert(service);&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;/li&gt; &lt;li&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;static&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(239, 239, 175);"&gt;LoginService&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; service;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;readonly&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;static&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; userName = &lt;/span&gt;&lt;span style="color: rgb(220, 163, 163);"&gt;"User"&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;&lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;readonly&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;static&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; &lt;/span&gt;&lt;span style="color: rgb(218, 198, 165);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt; password = &lt;/span&gt;&lt;span style="color: rgb(220, 163, 163);"&gt;"Pwd"&lt;/span&gt;&lt;span style="color: rgb(215, 215, 200);"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&amp;nbsp;&lt;span style="color: rgb(215, 215, 200);"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;This concludes that if you have a mock setup and you cant pass the instance via dependency injection, JustMock will still try to find the closest mock setup for arguments that it will replace the original call with when invoked. There is no extra setup call to be associated in that regard and keeps the tool more out of your way. &lt;/p&gt;  &lt;p&gt;In addition I am attaching the sample project to let you have a look. Also you will be needing JustMock full edition installed to try this out.&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:78332689-7051-4989-8cca-eb156a6d44d7" class="wlWriterEditableSmartContent"&gt;&lt;div&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/JustMock_Legacy01_5FB2271C.zip" target="_blank" mce_href="http://weblogs.asp.net/blogs/mehfuzh/JustMock_Legacy01_5FB2271C.zip"&gt;JustMock_Legacy01.zip&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7878112" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=BQAaNyBoxio:9WBxqpNQT8M:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=BQAaNyBoxio:9WBxqpNQT8M:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=BQAaNyBoxio:9WBxqpNQT8M:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=BQAaNyBoxio:9WBxqpNQT8M:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=BQAaNyBoxio:9WBxqpNQT8M:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/BQAaNyBoxio" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/JustMock/default.aspx">JustMock</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2011/07/21/fake-a-member-without-worrying-about-passing-the-dependency.aspx</feedburner:origLink></item><item><title>Running JustMock profiler outside of Visual Studio</title><link>http://feedproxy.google.com/~r/burncsharp/~3/qGSoRa7WtFM/running-justmock-profiler-outside-of-visual-studio.aspx</link><pubDate>Tue, 24 May 2011 14:54:13 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7802226</guid><dc:creator>mehfuzh</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7802226</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7802226</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2011/05/24/running-justmock-profiler-outside-of-visual-studio.aspx#comments</comments><description>&lt;p&gt;In this post , I would be focusing on the issue that generally comes to query on how to run JustMock with standalone tools like nunit or msbuild console. Since mocking concrete method works initializing the .net profiler that is set using two variables in the runtime to let JustMock work the correct way.&lt;/p&gt;  &lt;p&gt;COR_ENABLE_PROFILING, “0x1”    &lt;br /&gt;COR_PROFILER, &amp;quot;{D1087F67-BEE8-4f53-B27A-4E01F64F3DA8}&amp;quot;&lt;/p&gt;  &lt;p&gt;Now while running msbuild&amp;#160; or nunit console or standalone GUI tool, initialization is not always the easy / expected thing to get going.&amp;#160; Therefore I created a tiny runner (unofficial) that will do just that and let you pipe your test DLL containing the tests&amp;#160; with JustMock. All you have to do is create a &lt;em&gt;batch&lt;/em&gt; file where you will pass the path to runner and test DLL in the following format:&lt;/p&gt;  &lt;p&gt;&lt;em&gt;JustMockRunner.exe&amp;#160; &amp;quot;%Path to test runner%\nunit-console.exe”&amp;#160; &amp;quot;%PathToDir%\JustMockTrialTests.dll&amp;quot;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Once the bat is executed, in this case it will open up the console, run the tests and print result from the test runner.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/image_58AE6358.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/image_thumb_74A38220.png" width="680" height="393" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The runner along with a sample project (taken from a user’s post in JustMock forum) can be downloaded by&lt;em&gt;&amp;#160;&lt;/em&gt;clicking the link below:&lt;strong&gt;&lt;u&gt;&lt;font size="5"&gt; &lt;/font&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:11ccf3e5-9cc5-480a-aa8e-30e4172e1753" class="wlWriterEditableSmartContent"&gt;&lt;div&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/JustRunner_with_samples_3C7F077C.zip" target="_blank"&gt;JustRunner_with_samples.zip&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;  &lt;p&gt;P.S. To take the advantage of profiler intensive tests , JustMock full edition&amp;#160; must be installed which actually registers the profiler. Also, please build the test project (output DLLs are removed) before running&amp;#160; &lt;em&gt;Run.bat&lt;/em&gt; .&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope this helps&lt;/p&gt;    &lt;p&gt;&lt;font color="#ff0000"&gt;Update : JustMockRunner.exe to work in .net 3.5 and removed the extra &lt;em&gt;Console.ReadLine&lt;/em&gt; that was causing problem in CI server integration.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7802226" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=qGSoRa7WtFM:0fLTBwB55L4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=qGSoRa7WtFM:0fLTBwB55L4:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=qGSoRa7WtFM:0fLTBwB55L4:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=qGSoRa7WtFM:0fLTBwB55L4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=qGSoRa7WtFM:0fLTBwB55L4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/qGSoRa7WtFM" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/JustMock/default.aspx">JustMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Mocking/default.aspx">Mocking</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Runner/default.aspx">Runner</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2011/05/24/running-justmock-profiler-outside-of-visual-studio.aspx</feedburner:origLink></item><item><title>Mocking MsCorlib members</title><link>http://feedproxy.google.com/~r/burncsharp/~3/Cd9W8yA3nXE/mocking-mscorlib-members.aspx</link><pubDate>Thu, 12 May 2011 12:21:40 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7787968</guid><dc:creator>mehfuzh</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7787968</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7787968</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2011/05/12/mocking-mscorlib-members.aspx#comments</comments><description>&lt;p&gt;In this post , I will show how you can mock&amp;#160; members from MsCorlib. This is more of an introductory post and shows what you need to do in order to successfully mock an MsCorlib member.&lt;/p&gt;  &lt;p&gt;If you are planning to mock &lt;em&gt;File&lt;/em&gt; or &lt;em&gt;DateTime&lt;/em&gt; then the process is pretty straight forward , you just need to put a &lt;em&gt;MockClassAttribute&lt;/em&gt; on top your test class. The process for intercepting&amp;#160; such is bit different as we don’t want to get your code through the particular logic for every other type and make your test slower. Therefore, we limit it to an attribute declaration to mark that the test class has some framework members to mock ahead.&lt;/p&gt;  &lt;p&gt;In a simple example, let’s say I want to assert a &lt;em&gt;DateTime&lt;/em&gt;:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:11fa6e1e-28b1-452e-a448-93d9895471c7" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;[&lt;/span&gt;&lt;span style="color:#678cb1"&gt;TestMethod&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;]&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;public&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;void&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; WhenDateTimeNowIsCalledItShouldReturnMockedValue()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;Mock&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Arrange(() &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#678cb1"&gt;DateTime&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Now)&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Returns(&lt;/span&gt;&lt;span style="color:#93c763"&gt;new&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#678cb1"&gt;DateTime&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;(&lt;/span&gt;&lt;span style="color:#ffcd22"&gt;1900&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;, &lt;/span&gt;&lt;span style="color:#ffcd22"&gt;2&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;, &lt;/span&gt;&lt;span style="color:#ffcd22"&gt;1&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;));&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;var&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; now &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#678cb1"&gt;DateTime&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Now;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;Assert&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;AreEqual(&lt;/span&gt;&lt;span style="color:#ffcd22"&gt;1900&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;, now&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Year);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;} &lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Or Let’s say I want just want to check if &lt;em&gt;File.Delete&lt;/em&gt;&amp;#160; is invoked:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e2d2522e-18c1-43c7-9ebc-0ee0623fe6ec" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#f1f2f3"&gt;[&lt;/span&gt;&lt;span style="color:#678cb1"&gt;TestMethod&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;]&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;public&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;void&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; WhenFileIsDeletedItShouldInvokeTheMockedImplementation()&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#f1f2f3"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;var&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; filename &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;this&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;GetType()&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Assembly&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;ManifestModule&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;FullyQualifiedName;&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;var&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; fi &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;new&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#678cb1"&gt;FileInfo&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;(filename);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;bool&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; called &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;false&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;Mock&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Arrange(() &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; fi&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Delete())&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;DoInstead(() &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; called &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;true&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#f1f2f3"&gt;fi&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Delete();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;Assert&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;IsTrue(called);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;} &lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;These require no special treatment other than the attribute declaration.&amp;#160; But what about other types from MsCorlib and can we mock them ?&amp;#160; Yes we can! We can mock virtually any MsCorlib type using JustMock. The only pre-requisite is to initialize it during the setup. The process is called pre-interception.&amp;#160; It is required in a sense that you don’t have to include mock specific attribute in each test method and keep it in one place. Therefore, lets say I want to mock &lt;em&gt;DriveInfo.GetDrives().&lt;/em&gt; All is required that you initialize it during setup in the following way:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:495c8c0d-dc41-4181-b441-ff56facf93a7" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#f1f2f3"&gt;[ClassInitialize]&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;public&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;static&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;void&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; Initialize(TestContext context)&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#f1f2f3"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;Mock&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Partial&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;DriveInfo&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;()&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;For(() &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#678cb1"&gt;DriveInfo&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;GetDrives());&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#f1f2f3"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The rest is plane old vanilla:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9c5ff9d7-c4e2-4494-973d-d016b141c6e2" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;[&lt;/span&gt;&lt;span style="color:#678cb1"&gt;TestMethod&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;]&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;public&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;void&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; WhenDriveInfoGetDrivesIsCalledItShouldExecuteTheMockedSetup()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;bool&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; called &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;false&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;Mock&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Arrange(() &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#678cb1"&gt;DriveInfo&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;GetDrives())&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;DoInstead(() &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; called &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;true&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;DriveInfo&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;GetDrives();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;Assert&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;IsTrue(called);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;} &lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;You can further elevate it to initialize all its member:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1ee228c0-c943-4ba7-b161-330f95a099c8" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;Mock&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Initialize&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;DriveInfo&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;();&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope that you find this useful. If you have any questions or ideas please directly contact the JustMock support team.&amp;#160; Finally, this is a JustMock Commercial edition feature thus not available in the free version.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Thanks&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7787968" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=Cd9W8yA3nXE:j7wH4t1Yt5Y:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=Cd9W8yA3nXE:j7wH4t1Yt5Y:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=Cd9W8yA3nXE:j7wH4t1Yt5Y:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=Cd9W8yA3nXE:j7wH4t1Yt5Y:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=Cd9W8yA3nXE:j7wH4t1Yt5Y:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/Cd9W8yA3nXE" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/JustMock/default.aspx">JustMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Mocking/default.aspx">Mocking</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Telerik/default.aspx">Telerik</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Unit+Test/default.aspx">Unit Test</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2011/05/12/mocking-mscorlib-members.aspx</feedburner:origLink></item><item><title>Mocking constructor</title><link>http://feedproxy.google.com/~r/burncsharp/~3/3dHTaZZ6d8I/mocking-constructor.aspx</link><pubDate>Tue, 22 Mar 2011 14:35:22 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7729607</guid><dc:creator>mehfuzh</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7729607</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7729607</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2011/03/22/mocking-constructor.aspx#comments</comments><description>&lt;p&gt;While unit testing a target type, it is likely that the test is failing during object creation because we forgot to include a mandatory configuration file or a line in the constructor is throwing exception because it is making call to some external service or data store which on the other hand requires a little more orchestration to get things going . To better illustrate this, let’s create an entity framework data container either new or from an existing database. Once we have completed the required steps, there will be an entry-point class where we will notice the following default constructor:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f9640afa-e882-44bb-9ad8-899d09118a58" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#99a38a"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#99a38a"&gt; Initializes a new NorthwindEntities object using the connection string found in the &amp;#39;NorthwindEntities&amp;#39; section of the application configuration file.&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#808080"&gt;///&lt;/span&gt;&lt;span style="color:#99a38a"&gt; &lt;/span&gt;&lt;span style="color:#808080"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;public&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; NorthwindEntities() : &lt;/span&gt;&lt;span style="color:#93c763"&gt;base&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;(&lt;/span&gt;&lt;span style="color:#ec7600"&gt;&amp;quot;name=NorthwindEntities&amp;quot;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;, &lt;/span&gt;&lt;span style="color:#ec7600"&gt;&amp;quot;NorthwindEntities&amp;quot;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;this&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;ContextOptions&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;LazyLoadingEnabled &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;true&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#f1f2f3"&gt;OnContextCreated();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The comment clearly shows that by default it will search for&amp;#160; a connection string named “NorthwindEntities” in the configuration file. Though this is not an ideal case where it makes the class more production oriented less TDD friendly (if you think it in a TDD purist way) but to avoid this kind of situation the newest release of Telerik JustMock (Free / Commercial) includes a way to mock such case comprehensively. Thus making it flexible for testers who don’t need to include a configuration file or initialize a default service.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Using the JustMock free edition, I can now easily test the above data container without going through any unnecessary configuration hassle:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b5f10cd4-e0f3-4abe-902f-7b311ab2412e" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;[&lt;/span&gt;&lt;span style="color:#678cb1"&gt;TestMethod&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;]&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;public&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#93c763"&gt;void&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; ShouldAssertWhenSaveOperationIsExpected()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;var&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; context &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#678cb1"&gt;Mock&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Create&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;NorthwindEntities&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;(&lt;/span&gt;&lt;span style="color:#678cb1"&gt;Constructor&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Mocked);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;Mock&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Arrange(() &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&amp;gt;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; context&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;SaveChanges(&lt;/span&gt;&lt;span style="color:#678cb1"&gt;Arg&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;IsAny&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;SaveOptions&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;()))&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;MustBeCalled();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#f1f2f3"&gt;context&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;SaveChanges(&lt;/span&gt;&lt;span style="color:#678cb1"&gt;SaveOptions&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;AcceptAllChangesAfterSave);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#678cb1"&gt;Mock&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Assert(context);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The key here is the &lt;strong&gt;Consturctor.Mocked&lt;/strong&gt; overload in &lt;em&gt;Mock.Create&amp;lt;T&amp;gt;&lt;/em&gt;.&amp;#160; By default it is set &lt;strong&gt;Constructor.NotMocked&lt;/strong&gt; as general&amp;#160; but incase your constructor is throwing some unknown exception and you have little control over its codebase then this could be just it.&lt;/p&gt;  &lt;p&gt;# region Developer’s log:&lt;/p&gt;  &lt;p&gt;As the feature is supported in JustMock free edition, it is right to say that there is no profiler involved. Therefore, it is not possible to use &lt;strong&gt;FormatterServices &lt;/strong&gt;in that regard : &lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:79cd652c-0c69-4ecc-9ed3-d6cfc4a6012a" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 100px; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;var&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; context &lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;=&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; &lt;/span&gt;&lt;span style="color:#678cb1"&gt;FormatterServices&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;GetSafeUninitializedObject(&lt;/span&gt;&lt;span style="color:#93c763"&gt;typeof&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;(&lt;/span&gt;&lt;span style="color:#678cb1"&gt;NorthwindEntities&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;));&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;If we just open up the &lt;em&gt;NorthwindEntities&lt;/em&gt; class in IL dissembler , we will see something like this:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6244767a-d81a-4c88-afac-43237974cfd8" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #000000; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_0000:  ldarg&lt;/span&gt;&lt;span style="color:#ffcd22"&gt;.0&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_0001:  ldarg&lt;/span&gt;&lt;span style="color:#ffcd22"&gt;.1&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_0002:  ldstr      &lt;/span&gt;&lt;span style="color:#ec7600"&gt;&amp;quot;NorthwindEntities&amp;quot;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_0007:  call       instance &lt;/span&gt;&lt;span style="color:#93c763"&gt;void&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; [System&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Data&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Entity]System&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Data&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Objects&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#678cb1"&gt;ObjectContext&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;::.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;ctor(&lt;/span&gt;&lt;span style="color:#93c763"&gt;string&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;,&lt;/span&gt;&lt;/li&gt; &lt;li&gt;                                                                                                &lt;span style="color:#f1f2f3"&gt;&lt;/span&gt;&lt;span style="color:#93c763"&gt;string&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_000c:  nop&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_000d:  nop&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_000e:  ldarg&lt;/span&gt;&lt;span style="color:#ffcd22"&gt;.0&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_000f:  call       instance &lt;/span&gt;&lt;span style="color:#93c763"&gt;class&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; [System&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Data&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Entity]System&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Data&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Objects&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#678cb1"&gt;ObjectContextOptions&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; [System&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Data&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Entity]System&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Data&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Objects&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#678cb1"&gt;ObjectContext&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;::&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;get_ContextOptions()&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_0014:  ldc&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;i4&lt;/span&gt;&lt;span style="color:#ffcd22"&gt;.1&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_0015:  callvirt   instance &lt;/span&gt;&lt;span style="color:#93c763"&gt;void&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt; [System&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Data&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Entity]System&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Data&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;Objects&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;.&lt;/span&gt;&lt;span style="color:#678cb1"&gt;ObjectContextOptions&lt;/span&gt;&lt;span style="color:#e8e2b7"&gt;::&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;set_LazyLoadingEnabled(&lt;/span&gt;&lt;span style="color:#93c763"&gt;bool&lt;/span&gt;&lt;span style="color:#f1f2f3"&gt;)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_001a:  nop&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_001b:  nop&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#f1f2f3"&gt;IL_001c:  ret&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here on line 4 it is first calling the base constructor which is actually the case for all .net objects. Even If the class has no base, .net framework will still do an instance&lt;em&gt;&amp;#160;&lt;/em&gt;call to System.Object itself.&amp;#160; But it is possible to skip the call during proxy initialization dynamically&amp;#160; that framework wont let you do otherwise if the base class has no default constructor. Of course, this wont work with sealed class in that case profiler is the only resort. Also, Silverlight runtime does not allow it but you can still reference Silverlight class library from .net test project to make things work.&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;Hope that you will find the &lt;strong&gt;Constructor.Mocked &lt;/strong&gt;feature useful. You can download sample the project for this post here &lt;a href="http://weblogs.asp.net/blogs/mehfuzh/EntityFramework01_017AED4E.zip" target="_blank"&gt;EntityFramework01.zip&lt;/a&gt;. Finally If you like NuGet, you can also try &lt;strong&gt;install-package JustMock&lt;/strong&gt; to grab the latest bits.&amp;#160; &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Thanks&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7729607" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=3dHTaZZ6d8I:5TaSU6cZSYc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=3dHTaZZ6d8I:5TaSU6cZSYc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=3dHTaZZ6d8I:5TaSU6cZSYc:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=3dHTaZZ6d8I:5TaSU6cZSYc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=3dHTaZZ6d8I:5TaSU6cZSYc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/3dHTaZZ6d8I" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/JustMock/default.aspx">JustMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/MSIL/default.aspx">MSIL</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Telerik/default.aspx">Telerik</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2011/03/22/mocking-constructor.aspx</feedburner:origLink></item><item><title>NuGet JustMock</title><link>http://feedproxy.google.com/~r/burncsharp/~3/RanxCd1klCs/nuget-justmock.aspx</link><pubDate>Wed, 22 Dec 2010 09:22:11 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7665862</guid><dc:creator>mehfuzh</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7665862</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7665862</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2010/12/22/nuget-justmock.aspx#comments</comments><description>&lt;p&gt;As most of us already know JustMock got&amp;#160; a free edition. The free edition is not a stripped down of the features of the full edition but I would rather say its a strip down of the type you can mock. Technically, free version runs on&amp;#160; proxy as full version runs on proxy + profiler. In full version, It switches to profiler when you are mocking final methods or sealed class or anything else that can not be done using inheritance. Like in full version you can mock non public methods , in free version you can still do it but it has to be virtual for protected or must be done through &lt;em&gt;InternalsVisibleTo&lt;/em&gt; attribute for internal virtual methods (If you have access to the source and can apply the attribute).&lt;/p&gt;  &lt;p&gt;Now, you can get a copy of free edition from the product page. Install it and off you go. But it is also exposed to NuGet. Those of you are not familiar with NuGet (that will be odd). But still NuGet is the centralized package manager from Microsoft that cuts the workflow of manual inclusion of&amp;#160; libraries in your project. I think NuGet in future will limit the scope of&amp;#160; “.vsi” packages and installers because of its ease (except in some cases). Its similar to ruby gems. In ruby, virtually you can install any library in this way “gem&amp;#160; install &amp;lt;target_library&amp;gt;” and you are off to go. It will check the dependencies, install them or less prompt with the steps you need to do.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now sticking to the post, to get started you first need to install NuGet package manager. Once you have completed the step pressing &lt;em&gt;&lt;strong&gt;“Ctrl + W, Ctrl + Z”&lt;/strong&gt;&lt;/em&gt; it will bring up an console like one below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/image_4CC4D169.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/image_thumb_4450D645.png" width="726" height="388" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Once you are here, you just have to type “install-package justmock”&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/image_7684385D.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/image_thumb_656FE4AD.png" width="716" height="104" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Next, it will should print the confirmation when the installation is complete:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/image_2D01BDD5.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/image_thumb_09851970.png" width="716" height="106" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Moving to visual studio solution explorer, you will now see:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/image_73DABB05.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://weblogs.asp.net/blogs/mehfuzh/image_thumb_7B367AB2.png" width="256" height="306" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Finally, NuGet is still in its early ages and steps that are shown here may not remain the same in coming releases, but feel free to enjoy what is out there right now. Regarding JustMock free edition, there is a nice post by &lt;strong&gt;Phil Japikse&lt;/strong&gt; at &lt;a href="http://www.skimedic.com/blog/post/2010/12/15/Introducing-JustMock-Free-Edition.aspx" target="_blank"&gt;Introducing JustMock Free Edition&lt;/a&gt;. I think its worth checking if not already.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Have fun and happy holidays!&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7665862" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=RanxCd1klCs:TIwSgXbNvb8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=RanxCd1klCs:TIwSgXbNvb8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=RanxCd1klCs:TIwSgXbNvb8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=RanxCd1klCs:TIwSgXbNvb8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=RanxCd1klCs:TIwSgXbNvb8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/RanxCd1klCs" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/JustMock/default.aspx">JustMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Nuget/default.aspx">Nuget</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2010/12/22/nuget-justmock.aspx</feedburner:origLink></item><item><title>Writing LINQ providers easily and elegantly (LinqExtender 3.0)</title><link>http://feedproxy.google.com/~r/burncsharp/~3/F_6DSzrebFA/writing-linq-providers-easily-and-elegantly-linqextender-3-0.aspx</link><pubDate>Sun, 28 Nov 2010 14:17:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7652341</guid><dc:creator>mehfuzh</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7652341</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7652341</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2010/11/28/writing-linq-providers-easily-and-elegantly-linqextender-3-0.aspx#comments</comments><description>&lt;P&gt;When writing a custom LINQ provider, developer must focus into plenty of issues other than the main purpose of just creating a LINQ to something. Like how to deal with&amp;nbsp;projection, how to parse valued expressions, how to parse members, how to do orderby and the list goes on. &lt;/P&gt;
&lt;P&gt;This is the reason I came up with LinqExtender, it deals with all such issues. But over the time&amp;nbsp;I found out that the idea of providing a fluent interface to lookup your query information is easy at some point but becomes really cluttered as the provider logic goes bigger and thus it greatly violates SRP (Single responsibility pattern). Over all, it inherits a base class that makes even impossible to include my own base. With all these in mind I came to push a new release that cuts all this issues.&lt;/P&gt;
&lt;P&gt;Therefore, first rather having an iterative fluent interface, it is build on simplified AST (Abstract syntax tree) over the original &lt;EM&gt;System.Linq.Expressions&lt;/EM&gt; with an intent more on making of custom LINQ providers easy, contextual, elegant and of course free of noises like how to deal with projection, what to be done if user invokes a method on the IQueryable, etc.&lt;/P&gt;
&lt;P&gt;Moreover,&amp;nbsp;as I don’t want to implement a base class, therefore just an interface should be sufficient enough to make the class queryable.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;interface&lt;/SPAN&gt; IQueryContext&amp;lt;T&amp;gt;
{
  IEnumerable&amp;lt;T&amp;gt; Execute(Ast.Expression expression);  
}&lt;/PRE&gt;
&lt;P&gt;Now, if we consider the following LINQ query:&lt;/P&gt;&lt;PRE class=csharpcode&gt;var query = from book &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; context
    &lt;SPAN class=kwrd&gt;where&lt;/SPAN&gt; (book.Id &amp;gt; 1) &amp;amp;&amp;amp; (book.Author == &lt;SPAN class=str&gt;"Scott"&lt;/SPAN&gt; || book.Author == &lt;SPAN class=str&gt;"Charlie"&lt;/SPAN&gt;)
    Select book&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;Things that come to mind on the first place are:&lt;/P&gt;
&lt;OL&gt;
&lt;OL&gt;
&lt;LI&gt;How do translate the logical groupings&lt;/LI&gt;
&lt;LI&gt;How to deal with different opeartors&lt;/LI&gt;
&lt;LI&gt;How to get the value that&amp;nbsp;is compared for a member&lt;/LI&gt;&lt;/OL&gt;&lt;/OL&gt;
&lt;P&gt;Or if the &lt;EM&gt;where&lt;/EM&gt;&amp;nbsp;clause&amp;nbsp;has expression&amp;nbsp;like:&amp;nbsp; book.Author == GetCurrentUsername(), we&amp;nbsp;need to&amp;nbsp;do some specific arts to invoke and reflect the value out of it. Will it not be nice, if the value is already there for us as intended. LinqExtender was/is focused to do all that for you.&lt;/P&gt;
&lt;P&gt;The above expression is roughly&amp;nbsp;translated into a simplified expression tree that looks similar to:&lt;/P&gt;&lt;PRE class=csharpcode&gt;BlockExpression
    TypeExpression : Name == &lt;SPAN class=str&gt;"Book"&lt;/SPAN&gt;, If NameAttribute applied then Name = &lt;SPAN class=str&gt;"as specified"&lt;/SPAN&gt;.
    LambdaExpression
        LogicalExpresion - Contains the logical parts | Operator = LogicalOperator.AND
            BinaryExpression 
                MemberExpression 
                    Name == &lt;SPAN class=str&gt;"Id"&lt;/SPAN&gt;
                LiteralExpression
                    Value = 1    
            BinaryExpression
                LogicalExpression : Operator = LogicalOperator.OR
                    BinaryExpression
                        MemberExpression - 
                            Name == &lt;SPAN class=str&gt;"Author"&lt;/SPAN&gt;
                        LiteralExpression
                            Value = &lt;SPAN class=str&gt;"Scott"&lt;/SPAN&gt;    
                    BinaryExpression
                        MemberExpression - 
                            Name == &lt;SPAN class=str&gt;"Author"&lt;/SPAN&gt;
                        LiteralExpression
                            Value = &lt;SPAN class=str&gt;"John"&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;The root is the &lt;EM&gt;BlockExpresion&lt;/EM&gt;, it contains other expressions as specified in the query. Like in this case &lt;EM&gt;TypeExpression&lt;/EM&gt; is for &lt;EM&gt;select&lt;/EM&gt;, it is possible to get the TypeReference for the target object. &lt;EM&gt;LambdaExpression&lt;/EM&gt; is for &lt;EM&gt;where&lt;/EM&gt; clause, it can contain logical and/or binary expressions. &lt;EM&gt;LogicalExpresion&lt;/EM&gt; on the other hand can contain N number of binary expressions and each &lt;EM&gt;BinaryExpression&lt;/EM&gt; contains &lt;EM&gt;MemberExpression&lt;/EM&gt; with the detail of the member followed by a &lt;EM&gt;LiteralEpxression&lt;/EM&gt; with the reflected value from the query.&lt;/P&gt;
&lt;P&gt;If we had an&amp;nbsp;&lt;EM&gt;orderby&amp;nbsp;&lt;/EM&gt;clause&amp;nbsp;in the expression, then BlockExpression would have contained an additional &lt;EM&gt;OrderByExpression&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;Finally, visiting the expression (using &lt;EM&gt;Visitor Pattern&lt;/EM&gt;) will produce a nice TSQL (Showed in the sample text provider =&amp;gt; project homepage):&lt;/P&gt;&lt;PRE class=csharpcode&gt;select * from Book
&lt;SPAN class=kwrd&gt;where&lt;/SPAN&gt;
Book.Id &amp;gt; 10 &amp;amp;&amp;amp; (Book.Author = &lt;SPAN class=str&gt;"Scott"&lt;/SPAN&gt;  OR Book.Author = &lt;SPAN class=str&gt;"Charlie"&lt;/SPAN&gt;)&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/STYLE&gt;

&lt;P&gt;The is just an overview, i have pulled up a home page for the project (shows creating a custom text provider that prints out TSQL representation of the query to the console) &amp;nbsp;along with link to the&amp;nbsp;source and archive to download. You can find it here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://mehfuzh.github.com/LinqExtender/" target=_blank mce_href="http://mehfuzh.github.com/LinqExtender/"&gt;http://mehfuzh.github.com/LinqExtender/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;However, I wont say that the tool is a feature complete, therefore feel to fork, update and&amp;nbsp;use it as you like.&lt;/P&gt;
&lt;P&gt;---&lt;/P&gt;
&lt;P&gt;Here to mention that&amp;nbsp;I moved the project from CodePlex(linqextender.codeplex.com) (that served it well and good), as github gives me more simplicity on how&amp;nbsp;I manage the project and gives a way to pull up my own project homepage (which is also a GIT repository). Not to mention that I pulled the home page with &lt;STRONG&gt;Jekyll&lt;/STRONG&gt; in no time with a minimalistic look and feel and of course its HTML 5.&lt;/P&gt;
&lt;P&gt;The page may come different in IE8 (comes great with IE9, Chrome or FileFox , looks like border-radius is not working in IE8). Also, used &lt;STRONG&gt;highlight.js&lt;/STRONG&gt; which is a&amp;nbsp;great javascript syntax highlighter that works nicely with HTML5 “&lt;STRONG&gt;code&lt;/STRONG&gt;” tag and has plenty of styles like ZenBurn, Idea, Vs, GitHub, etc and overall&amp;nbsp;simple to include.&lt;/P&gt;
&lt;P&gt;---&lt;/P&gt;
&lt;P&gt;Enjoy!!&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7652341" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=F_6DSzrebFA:h9OjMmETOQ0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=F_6DSzrebFA:h9OjMmETOQ0:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=F_6DSzrebFA:h9OjMmETOQ0:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=F_6DSzrebFA:h9OjMmETOQ0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=F_6DSzrebFA:h9OjMmETOQ0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/F_6DSzrebFA" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/LinqExtender/default.aspx">LinqExtender</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2010/11/28/writing-linq-providers-easily-and-elegantly-linqextender-3-0.aspx</feedburner:origLink></item><item><title>How to raise event for a mocked call.</title><link>http://feedproxy.google.com/~r/burncsharp/~3/SJrzCjYH3b0/how-to-raise-event-for-a-mocked-call.aspx</link><pubDate>Wed, 06 Oct 2010 10:01:31 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7624213</guid><dc:creator>mehfuzh</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7624213</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7624213</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2010/10/06/how-to-raise-event-for-a-mocked-call.aspx#comments</comments><description>&lt;p&gt;Recently, while i was working with a support issue , i found this interesting piece of test code that i would like to share here. This is actually written by &lt;a href="http://www.lieser-online.de/" target="_blank"&gt;Stefan Lieser&lt;/a&gt; (clean code developer from Germany forwarded to me by Jan from Telerik Germany). As the title states,&amp;#160; it is to mock a specific event for an expected call.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now Stefan wants to raise an event from &lt;em&gt;WebClient&lt;/em&gt; class of &lt;em&gt;System.Net&lt;/em&gt; for a download operation. Therefore, first the &lt;em&gt;WebClient &lt;/em&gt;class is mocked during setup.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1ac53c7d-935f-4dd6-9904-626fb7375327" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;[&lt;span style="color:#2b91af"&gt;SetUp&lt;/span&gt;]&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Setup()&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li class="even"&gt;    webClient = &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Create&amp;lt;&lt;span style="color:#2b91af"&gt;WebClient&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Next the mocking here takes place in two part. First, &lt;em&gt;DownloadDataCompletedEventArgs &lt;/em&gt;is&lt;em&gt;&amp;#160;&lt;/em&gt;mocked to return an expected data when &lt;em&gt;Result&lt;/em&gt; property is get.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:696facaa-b0b9-4d53-92ff-478c4eb57bbd" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt; &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; e = &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Create&amp;lt;&lt;span style="color:#2b91af"&gt;DownloadDataCompletedEventArgs&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li class="even"&gt; &lt;/li&gt; &lt;li&gt; &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; data = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff"&gt;byte&lt;/span&gt;[] { 1, 2, 3 };&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt; &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Arrange(() =&amp;gt; e.Result).Returns(data);&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;This is followed by an arrange that will raise the expected event when &lt;em&gt;DownloadDataAsync&lt;/em&gt; is invoked.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:852a124c-eec9-4e16-9ccb-a7e839fd03ef" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Arrange(() =&amp;gt; webClient.DownloadDataAsync(&lt;span style="color:#2b91af"&gt;Arg&lt;/span&gt;.IsAny&amp;lt;&lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;&amp;gt;()))&lt;/li&gt; &lt;li class="even"&gt;    .Raises(() =&amp;gt; webClient.DownloadDataCompleted += &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, e);&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Finally, the whole test method ends up like:&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:204f8759-1c9f-410e-928e-63f51ccd42d1" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;  [&lt;span style="color:#2b91af"&gt;Test&lt;/span&gt;]&lt;/li&gt; &lt;li class="even"&gt;  &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ShouldAssertExepectedDataWhenDownloadIsCompleted()&lt;/li&gt; &lt;li&gt;  {&lt;/li&gt; &lt;li class="even"&gt;      &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; count = 0;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;      &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; e = &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Create&amp;lt;&lt;span style="color:#2b91af"&gt;DownloadDataCompletedEventArgs&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li&gt;      &lt;/li&gt; &lt;li class="even"&gt;      &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; data = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#0000ff"&gt;byte&lt;/span&gt;[] { 1, 2, 3 };&lt;/li&gt; &lt;li&gt;     &lt;/li&gt; &lt;li class="even"&gt;      &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Arrange(() =&amp;gt; e.Result).Returns(data);&lt;/li&gt; &lt;li&gt;     &lt;/li&gt; &lt;li class="even"&gt;      &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Arrange(() =&amp;gt; webClient.DownloadDataAsync(&lt;span style="color:#2b91af"&gt;Arg&lt;/span&gt;.IsAny&amp;lt;&lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;&amp;gt;()))&lt;/li&gt; &lt;li&gt;          .Raises(() =&amp;gt; webClient.DownloadDataCompleted += &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, e);&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;      &lt;span style="color:#0000ff"&gt;byte&lt;/span&gt;[] exepectedData = &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;      webClient.DownloadDataCompleted += &lt;span style="color:#0000ff"&gt;delegate&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; sender, &lt;span style="color:#2b91af"&gt;DownloadDataCompletedEventArgs&lt;/span&gt; de)  &lt;/li&gt; &lt;li class="even"&gt;      {&lt;/li&gt; &lt;li&gt;          exepectedData = de.Result;&lt;/li&gt; &lt;li class="even"&gt;          count++; &lt;/li&gt; &lt;li&gt;      };&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;      webClient.DownloadDataAsync(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Uri&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;http://example.de&amp;quot;&lt;/span&gt;));&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;      &lt;span style="color:#2b91af"&gt;Assert&lt;/span&gt;.That(count, &lt;span style="color:#2b91af"&gt;Is&lt;/span&gt;.EqualTo(1));&lt;/li&gt; &lt;li&gt;      &lt;span style="color:#2b91af"&gt;Assert&lt;/span&gt;.That(exepectedData.Length, &lt;span style="color:#2b91af"&gt;Is&lt;/span&gt;.EqualTo(data.Length));&lt;/li&gt; &lt;li class="even"&gt;  }&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The above example is done using JustMock SP1. You can further download the code here:    &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F60BB8FA-6F02-4999-8F5E-9DD4E92C4DA7:6586fdab-3fae-4176-9bf5-b7b19728d3fd" class="wlWriterEditableSmartContent"&gt;&lt;div&gt;&lt;a href="http://weblogs.asp.net/blogs/mehfuzh/WebClientTest001_3EC161FD.zip" target="_blank" onClick="javascript: pageTracker._trackPageview('WebClientTest001.zip');"&gt;WebClientTest001.zip&lt;/a&gt;&lt;/div&gt;&lt;/div&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Happy coding !!&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7624213" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=SJrzCjYH3b0:9suN2D7Rl7Q:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=SJrzCjYH3b0:9suN2D7Rl7Q:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=SJrzCjYH3b0:9suN2D7Rl7Q:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=SJrzCjYH3b0:9suN2D7Rl7Q:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=SJrzCjYH3b0:9suN2D7Rl7Q:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/SJrzCjYH3b0" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/Agile/default.aspx">Agile</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/JustMock/default.aspx">JustMock</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2010/10/06/how-to-raise-event-for-a-mocked-call.aspx</feedburner:origLink></item><item><title>Mocking SPContext.Current with JustMock</title><link>http://feedproxy.google.com/~r/burncsharp/~3/1_Z4Z1qYSCc/mocking-spcontext-current-with-justmock.aspx</link><pubDate>Mon, 27 Sep 2010 12:42:49 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7620872</guid><dc:creator>mehfuzh</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/mehfuzh/rsscomments.aspx?PostID=7620872</wfw:commentRss><wfw:comment>http://weblogs.asp.net/mehfuzh/commentapi.aspx?PostID=7620872</wfw:comment><comments>http://weblogs.asp.net/mehfuzh/archive/2010/09/27/mocking-spcontext-current-with-justmock.aspx#comments</comments><description>&lt;p&gt;Today, I happen to find an interesting post on mocking SharePoint context using TypeMock. Being a JustMocker, i thought rather to follow the footsteps and see if can do the same with JustMock. I am no SharePoint expert. Occasionally, I use a Windows 2003 VM with SharePoint server installed which gives me the required flavor of SharePoint for testing&amp;nbsp; SP capabilities of JM.&lt;/p&gt; &lt;p&gt;Anyway, here is the original post that i am going to recycle using JustMock.&lt;/p&gt; &lt;p&gt;&lt;a title="http://meronymy.blogspot.com/2010/09/mocking-spcontextcurrent-with-typemock.html" href="http://meronymy.blogspot.com/2010/09/mocking-spcontextcurrent-with-typemock.html" target="_blank"&gt;http://meronymy.blogspot.com/2010/09/mocking-spcontextcurrent-with-typemock.html&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The scenario here is pretty simple. There is a method that returns an URL from the current &lt;em&gt;SPContext&lt;/em&gt; which i am going to mock in order to return my expected URL.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Therefore, the class for which the behavior to be mocked is similar to:&lt;/p&gt; &lt;p&gt;&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:24e40be3-6418-4eea-9e16-f31fac6e6e3e" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Site&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; GetHomePageUrl()&lt;/li&gt; &lt;li class="even"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#2b91af"&gt;SPContext&lt;/span&gt;.Current.Site.Url;&lt;/li&gt; &lt;li class="even"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Finally, the test that creates fake instance of &lt;em&gt;SPSite&lt;/em&gt; and passes it to the current context:&lt;/p&gt; &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:118a35e9-4381-4916-9997-295cc7aafb5a" class="wlWriterEditableSmartContent"&gt; &lt;div class="le-pavsc-container"&gt; &lt;div style="background: #ddd; max-height: 300px; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;[&lt;span style="color:#2b91af"&gt;TestMethod&lt;/span&gt;]&lt;/li&gt; &lt;li class="even"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; ShouldAssertSPSiteUrlWithExpected()&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; fakeSiteUrl = &lt;span style="color:#a31515"&gt;&amp;quot;http://www.telerik.com&amp;quot;&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; fakeSharepointSite = &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Create&amp;lt;&lt;span style="color:#2b91af"&gt;SPSite&lt;/span&gt;&amp;gt;();&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#008000"&gt;// Arrange&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Arrange(() =&amp;gt; &lt;span style="color:#2b91af"&gt;SPContext&lt;/span&gt;.Current.Site).Returns(fakeSharepointSite);&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af"&gt;Mock&lt;/span&gt;.Arrange(() =&amp;gt; fakeSharepointSite.Url).Returns(fakeSiteUrl);&lt;/li&gt; &lt;li class="even"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#008000"&gt;// Act&lt;/span&gt;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; actualUrl = &lt;span style="color:#2b91af"&gt;Site&lt;/span&gt;.GetHomePageUrl();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li class="even"&gt;    &lt;span style="color:#2b91af"&gt;Assert&lt;/span&gt;.AreEqual(fakeSiteUrl, actualUrl);&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;&lt;pre class="brush: csharp;"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;I have used&amp;nbsp; JustMock SP1 for the purpose and thanks to the original author for this sample.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hope that helps&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7620872" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=1_Z4Z1qYSCc:RfzkuM-OLl8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=1_Z4Z1qYSCc:RfzkuM-OLl8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=1_Z4Z1qYSCc:RfzkuM-OLl8:7Q72WNTAKBA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?d=7Q72WNTAKBA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/burncsharp?a=1_Z4Z1qYSCc:RfzkuM-OLl8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/burncsharp?i=1_Z4Z1qYSCc:RfzkuM-OLl8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/burncsharp/~4/1_Z4Z1qYSCc" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/JustMock/default.aspx">JustMock</category><category domain="http://weblogs.asp.net/mehfuzh/archive/tags/SharePoint/default.aspx">SharePoint</category><feedburner:origLink>http://weblogs.asp.net/mehfuzh/archive/2010/09/27/mocking-spcontext-current-with-justmock.aspx</feedburner:origLink></item></channel></rss>

