<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nizar&#039;s .NET Blog</title>
	<atom:link href="http://nizarnoorani.com/index.php/feed" rel="self" type="application/rss+xml" />
	<link>http://nizarnoorani.com</link>
	<description></description>
	<lastBuildDate>Mon, 08 Mar 2010 21:13:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Strategy Pattern at work</title>
		<link>http://nizarnoorani.com/index.php/archives/239</link>
		<comments>http://nizarnoorani.com/index.php/archives/239#comments</comments>
		<pubDate>Mon, 08 Mar 2010 18:21:13 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[feature overlap]]></category>
		<category><![CDATA[ood]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[strategy design pattern]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=239</guid>
		<description><![CDATA[We recently ran into a challenging design issue at work.  We are working on a web application that must support internationalization since we have customers in many different countries.  The profile for each customer has different settings and configurations based upon the customer&#8217;s country.
These settings/configurations overlap and differ across countries.  The goal, [...]]]></description>
			<content:encoded><![CDATA[<p>We recently ran into a challenging design issue at work.  We are working on a web application that must support internationalization since we have customers in many different countries.  The profile for each customer has different settings and configurations based upon the customer&#8217;s country.</p>
<p>These settings/configurations overlap and differ across countries.  The goal, of course, is to design/implement the code in a way that enables us to reuse code that is common across countries.  Below is the scenario that we are dealing with, </p>
<ul>
<li>USCustomer.FeatureA() is the same as CACustomer.FeatureA()</li>
<li>USCustomer.FeatureB() is the same as KRCustomer.FeatureB()</li>
<li>CACustomer.FeatureC() is the same as KRCustomer.FeatureC()</li>
<li>KRCustomer.FeatureA() differs from USCustomer.FeatureA()</li>
<li>CACustomer.FeatureB() differs from USCustomer.FeatureB()</li>
<li>USCustomer.FeatureC() differs from CACustomer.FeatureC()</li>
</ul>
<p>The first attempt was of course to try and solve this via sub-classing.  Let&#8217;s look at the different options that we have for sub-classing:</p>
<ol>
<li>Make CA &#038; KR sub-classes of US.  This allows us to re-use USCustomer.FeatureA() for CA and USCustomer.FeatureB() for KR.  But it doesn&#8217;t allow us to re-use CACustomer.FeatureC() for KR.
</li>
<li> Okay, no problem, you say.  We&#8217;ll just make KR a sub-class of CA.  So, CA is a sub-class of US and KR is a sub-class of CA.  But then we run into the issue that USCustomer.FeatureB() can no longer to be re-used for KRCustomer.FeatureB().
</li>
</ol>
<p>Now imagine this kind of situation spread across 15 different countries.  Ouch!  So sub-classing clearly is not the answer.  </p>
<p>It sounds like we need some sort of &#8220;strategy&#8221; that&#8217;ll let us swap/differ settings and configurations across countries without all this coupling.  Well the strategy is to apply the Strategy design pattern.  Below is the overall strategy:</p>
<ol>
<li>
Encapsulate the features:  Each feature gets its own class.  So we end up with the following classes:</p>
<pre>
Customer
CACustomer
KRCustomer
FeatureA : IFeatureA
FeatureB : IFeatureB
FeatureC : IFeatureC
FeatureA1 : IFeatureA
FeatureB1 : IFeatureB
FeatureC1 : IFeatureC
</pre>
</li>
<li>
Setup the constructor of the Customer class to take in the concrete class that is specific to the feature that they require as a parameter.  For instance,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Customer
<span style="color: #000000;">&#123;</span>
   <span style="color: #0600FF;">public</span> Customer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> 
     <span style="color: #0600FF;">this</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> FeatureA<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> FeatureB<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> FeatureC<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>  <span style="color: #000000;">&#125;</span>
&nbsp;
   <span style="color: #0600FF;">public</span> Customer<span style="color: #000000;">&#40;</span>IFeatureA a, IFeatureB b, IFeatureC c<span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
      featureA <span style="color: #008000;">=</span> a;
      featureB <span style="color: #008000;">=</span> b;
      featureC <span style="color: #008000;">=</span> c;
   <span style="color: #000000;">&#125;</span>
&nbsp;
   <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> DoInitialSetup<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
      SetupFeatureA<span style="color: #000000;">&#40;</span>featureA<span style="color: #000000;">&#41;</span>;
      SetupFeatureB<span style="color: #000000;">&#40;</span>featureB<span style="color: #000000;">&#41;</span>;
      SetupFeatureC<span style="color: #000000;">&#40;</span>featureC<span style="color: #000000;">&#41;</span>;
   <span style="color: #000000;">&#125;</span>
&nbsp;
   <span style="color: #0600FF;">private</span> IFeatureA featureA;
   <span style="color: #0600FF;">private</span> IFeatureB featureB;
   <span style="color: #0600FF;">private</span> IFeatureC featureC;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CACustomer <span style="color: #008000;">:</span> Customer
<span style="color: #000000;">&#123;</span>
   <span style="color: #0600FF;">public</span> CACustomer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> 
     <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> FeatureA<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> FeatureB1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> FeatureC1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> KRCustomer <span style="color: #008000;">:</span> Customer
<span style="color: #000000;">&#123;</span>
   <span style="color: #0600FF;">public</span> KRCustomer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> 
     <span style="color: #0600FF;">base</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> FeatureA1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> FeatureB<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> FeatureC1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</li>
</ol>
<p>And voila!  We can now swap implementations across countries and add different implementations for different countries as needed.</p>
<p>The above example was simplified to effectively demonstrate the Strategy pattern without confusing the reader.  In particular, in the above example, the customer classes directly instantiate the features that they need.  This is generally a bad idea in practice for at least two reasons: </p>
<ol>
<li>It makes it difficult to unit test the Customer class.</li>
<li>Each type of customer is still coupled to the specific feature-set that it is using.  In other words, the features cannot be changed dynamically.
</li>
</ol>
<p>Instead of directly instantiating the classes, we should be using an IOC container to handle the object instantiations and configurations.  </p>
<p>For instance, for our application, we are using an XML file to tie concrete implementations with their respective countries.  Below is an example:</p>
<p><b>DefaultLocalization.xml</b></p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;interface</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IFeatureA&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;FeatureA&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;interface</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IFeatureB&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;FeatureB&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;interface</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IFeatureC&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;FeatureC&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><b>CALocalization.xml</b></p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;interface</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IFeatureB&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;FeatureB1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;interface</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IFeatureC&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;FeatureC1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><b>KRLocalization.xml</b></p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;interface</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IFeatureA&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;FeatureA1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;interface</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;IFeatureC&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;FeatureC1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</li>
</ol>
<p>Based on the current country, the right classes get instantiated.  If we ever need change KR to use FeatureC instead of FeatureC1, all we do is make the change in the XML file and we&#8217;re done. </p>
<p>So, in conclusion, the key to the strategy pattern is encapsulation:  Remove the logic that differs from the logic that stays the same via encapsulation.  </p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Strategy+Pattern+at+work+http://pk8cp.th8.us" title="Post to Twitter"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://buzz.yahoo.com/submit?submitUrl=http://nizarnoorani.com/index.php/archives/239&amp;submitHeadline=Strategy+Pattern+at+work" title="Post to Yahoo Buzz"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a class="tt" href="http://delicious.com/post?url=http://nizarnoorani.com/index.php/archives/239&amp;title=Strategy+Pattern+at+work" title="Post to Delicious"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://nizarnoorani.com/index.php/archives/239&amp;title=Strategy+Pattern+at+work" title="Post to Digg"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://nizarnoorani.com/index.php/archives/239&amp;t=Strategy+Pattern+at+work" title="Post to Facebook"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/239&amp;title=Strategy+Pattern+at+work" title="Post to Reddit"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/239&amp;title=Strategy+Pattern+at+work" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://nizarnoorani.com/index.php/archives/239&amp;title=Strategy+Pattern+at+work" title="Post to StumbleUpon"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/index.php/archives/239/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding a UNIQUE constraint</title>
		<link>http://nizarnoorani.com/index.php/archives/232</link>
		<comments>http://nizarnoorani.com/index.php/archives/232#comments</comments>
		<pubDate>Fri, 05 Mar 2010 20:50:03 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tips And Tricks]]></category>
		<category><![CDATA[sql unique]]></category>
		<category><![CDATA[unique constraint]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=232</guid>
		<description><![CDATA[I always forget how to do this and then have to spin my wheels searching websites for it.  Finally, decided to post it on my blog so I (and others) can quickly get to it:

ALTER TABLE SomeTable
	ADD CONSTRAINT unique_key
	UNIQUE (ColumnOne, ColumnTwo, ...)

      Reddit ]]></description>
			<content:encoded><![CDATA[<p>I always forget how to do this and then have to spin my wheels searching websites for it.  Finally, decided to post it on my blog so I (and others) can quickly get to it:</p>
<pre language="sql">
ALTER TABLE SomeTable
	ADD CONSTRAINT unique_key
	UNIQUE (ColumnOne, ColumnTwo, ...)
</pre>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Adding+a+UNIQUE+constraint+http://n62sq.th8.us" title="Post to Twitter"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://buzz.yahoo.com/submit?submitUrl=http://nizarnoorani.com/index.php/archives/232&amp;submitHeadline=Adding+a+UNIQUE+constraint" title="Post to Yahoo Buzz"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a class="tt" href="http://delicious.com/post?url=http://nizarnoorani.com/index.php/archives/232&amp;title=Adding+a+UNIQUE+constraint" title="Post to Delicious"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://nizarnoorani.com/index.php/archives/232&amp;title=Adding+a+UNIQUE+constraint" title="Post to Digg"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://nizarnoorani.com/index.php/archives/232&amp;t=Adding+a+UNIQUE+constraint" title="Post to Facebook"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/232&amp;title=Adding+a+UNIQUE+constraint" title="Post to Reddit"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/232&amp;title=Adding+a+UNIQUE+constraint" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://nizarnoorani.com/index.php/archives/232&amp;title=Adding+a+UNIQUE+constraint" title="Post to StumbleUpon"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/index.php/archives/232/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress on a GoDaddy hosted site &#8211; 500 internal server error!</title>
		<link>http://nizarnoorani.com/index.php/archives/212</link>
		<comments>http://nizarnoorani.com/index.php/archives/212#comments</comments>
		<pubDate>Sat, 20 Feb 2010 17:19:13 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Tips And Tricks]]></category>
		<category><![CDATA[500 internal error]]></category>
		<category><![CDATA[godaddy]]></category>
		<category><![CDATA[IIS hosting]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=212</guid>
		<description><![CDATA[

Is your blog site returning the infamous &#8220;500 &#8211; internal server error&#8221; more often than not?
Are you using Wordpress as your blog publishing platform?
Are you using GoDaddy as your website hosting provider?
Are you using IIS as your web server (as opposed to Linux)?

If yes, continue reading to fix this issue:
There is weird configuration issue with [...]]]></description>
			<content:encoded><![CDATA[<div style="line-height:1.7em">
<ul>
<li>Is your blog site returning the infamous &#8220;500 &#8211; internal server error&#8221; more often than not?</li>
<li>Are you using Wordpress as your blog publishing platform?</li>
<li>Are you using GoDaddy as your website hosting provider?</li>
<li>Are you using IIS as your web server (as opposed to Linux)?</li>
</ul>
<p>If yes, continue reading to fix this issue:</p>
<p>There is weird configuration issue with running WordPress with a IIS web server on GoDaddy.  Taking the following actions will resolve this issue:</p>
<ol>
<li>
Upgrade WordPress to the latest version.  Detailed instructions at:<a href="http://codex.wordpress.org/Upgrading_WordPress" target="_blank"> Upgrading WordPress</a>
</li>
<li>
Install WP-Super-Cache plugin.  <a href="http://wordpress.org/extend/plugins/wp-super-cache/" target="_blank">Here</a> is the download link for it.  In order to enable the plugin, you have to do a little tweaking.  Below are the steps you need to follow:</p>
<ul>
<li>First off, extract the &#8216;wp-super-cache&#8217; folder into your &#8216;wp-content/plugins&#8217; directory.</li>
<li>Log in to your GoDaddy account and navigate to Hosting -> Manage Account.</li>
<li>Click on the Content tab and select File Manager.</li>
<li>Here you will see all your files and folders.  Check the wp-content folder and click the Permissions icon on the top.  Uncheck Inherit and check the Read and Write checkboxes.  Don&#8217;t worry this is only temporary to get your plugin working correctly.  Save your changes.</li>
<li>Now Enable the plugin by going to your WordPress Plugins page.</li>
<li>Next you will have to enable caching.  For this, go back to your File Manager and browse to the &#8220;wp-content/cache&#8221; folder.  Change the permissions on this folder to Read/Write as well.</li>
<li>Now open up the wp-config.php page that&#8217;s in the root directory and add the following line towards the end: define(&#8216;WP_CACHE&#8217;, true)</li>
<li>Go back to the Settings page for the wp-super-cache plugin and set the status to ON.  Make sure to save your settings.  You may see a warning about apache mod_rewrite not enable or installed.  Don&#8217;t worry about this warning.  This just means that your caching will only be HALF-ON which is fine because even it being HALF-ON will fix our &#8216;500 &#8211; internal error&#8217; issue.</li>
<li>Go back to the File Manager and change the permissions on the wp-content folder to Inherit.</li>
<li>Your website should now respond faster and stop generating the 500 &#8211; internal server error issue.</li>
</ul>
</li>
<li>As an additional security measure, I would also recommend installing the <a href="http://wordpress.org/extend/plugins/wp-spamfree/" target="_blank">WP-SpamFree</a> plugin.  This is a very effective plugin that will eliminate virtually all SPAM comments.  Thus decreasing the load on your website.</li>
</ol>
<p>If that still doesn&#8217;t fix the &#8220;500 internal server error&#8221; issue, then try updating your current WordPress theme or switch to a different WordPress theme.  If that doesn&#8217;t work either, then it&#8217;s time to bite the bullet and switch to Linux! <img src='http://nizarnoorani.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=WordPress+on+a+GoDaddy+hosted+site+%E2%80%93+500+internal+server+error%21+http://fsmhh.th8.us" title="Post to Twitter"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://buzz.yahoo.com/submit?submitUrl=http://nizarnoorani.com/index.php/archives/212&amp;submitHeadline=WordPress+on+a+GoDaddy+hosted+site+%E2%80%93+500+internal+server+error%21" title="Post to Yahoo Buzz"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a class="tt" href="http://delicious.com/post?url=http://nizarnoorani.com/index.php/archives/212&amp;title=WordPress+on+a+GoDaddy+hosted+site+%E2%80%93+500+internal+server+error%21" title="Post to Delicious"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://nizarnoorani.com/index.php/archives/212&amp;title=WordPress+on+a+GoDaddy+hosted+site+%E2%80%93+500+internal+server+error%21" title="Post to Digg"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://nizarnoorani.com/index.php/archives/212&amp;t=WordPress+on+a+GoDaddy+hosted+site+%E2%80%93+500+internal+server+error%21" title="Post to Facebook"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/212&amp;title=WordPress+on+a+GoDaddy+hosted+site+%E2%80%93+500+internal+server+error%21" title="Post to Reddit"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/212&amp;title=WordPress+on+a+GoDaddy+hosted+site+%E2%80%93+500+internal+server+error%21" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://nizarnoorani.com/index.php/archives/212&amp;title=WordPress+on+a+GoDaddy+hosted+site+%E2%80%93+500+internal+server+error%21" title="Post to StumbleUpon"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/index.php/archives/212/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Refactoring for Unit Testing</title>
		<link>http://nizarnoorani.com/index.php/archives/173</link>
		<comments>http://nizarnoorani.com/index.php/archives/173#comments</comments>
		<pubDate>Mon, 01 Feb 2010 23:01:05 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit Tests]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=173</guid>
		<description><![CDATA[Imagine the following (which you&#8217;ve very likely run into in the past):
You join a new company and inherit a humongous existing code base.  You are told to add some new functionalities without of course breaking existing functionality.  &#8220;No problem&#8221;, you say!  &#8220;I&#8217;ve done this before.&#8221;
You&#8217;ve got clear requirements and complete access to [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine the following (which you&#8217;ve very likely run into in the past):</p>
<p>You join a new company and inherit a humongous existing code base.  You are told to add some new functionalities without of course breaking existing functionality.  &#8220;No problem&#8221;, you say!  &#8220;I&#8217;ve done this before.&#8221;</p>
<p>You&#8217;ve got clear requirements and complete access to the existing code base.  After some investigation, you figure out that you need to add a few methods to an existing class.  One of these methods is:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">CustomerService.<span style="color: #0000FF;">CanPurchaseProduct</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> productId<span style="color: #000000;">&#41;</span></pre></div></div>

<p>The existing <code>CustomerService</code> class looks somewhat like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CustomerService
<span style="color: #000000;">&#123;</span>
   <span style="color: #0600FF;">public</span> CustomerService<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> customerId<span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
      custManager <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CustomerManager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      cust <span style="color: #008000;">=</span> custManager.<span style="color: #0000FF;">GetCustomer</span><span style="color: #000000;">&#40;</span>customerId<span style="color: #000000;">&#41;</span>;
   <span style="color: #000000;">&#125;</span>
&nbsp;
   ...<span style="color: #0000FF;">other</span> methods...
&nbsp;
   <span style="color: #0600FF;">private</span> CustomerManager custManager;
   <span style="color: #0600FF;">private</span> Customer cust;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>You will also be utilizing an existing class named <code>ProductService</code>. Below is a bare-bones outline of this class:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ProductService
<span style="color: #000000;">&#123;</span>
   <span style="color: #0600FF;">public</span> ProductService<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> productId<span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
      prodManager <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ProductManager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
      prod <span style="color: #008000;">=</span> prodManager.<span style="color: #0000FF;">GetProduct</span><span style="color: #000000;">&#40;</span>productId<span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#125;</span>
&nbsp;
   ... <span style="color: #0000FF;">other</span> methods below .....
&nbsp;
   <span style="color: #0600FF;">private</span> ProductManager prodManager;
   <span style="color: #0600FF;">private</span> Product prod;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Your requirements state the following:</p>
<p>  &#8211; Product must be in stock<br />
  &#8211; Customer must be a member IF product is for members only  </p>
<p>Being the good developer that you are, you start, of course, by writing the unit tests.  They look something like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>TestCase<span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> CanPurchaseProduct_InStockAndForAll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
      <span style="color: #FF0000;">int</span> customerId <span style="color: #008000;">=</span> <span style="color: #FF0000;">123</span>;
      <span style="color: #FF0000;">int</span> prodId <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>;
&nbsp;
      <span style="color: #008080; font-style: italic;">//TODO: Mock this scenario</span>
      CustomerService svc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CustomerService<span style="color: #000000;">&#40;</span>customerId<span style="color: #000000;">&#41;</span>; 
     Assert.<span style="color: #0000FF;">IsTrue</span><span style="color: #000000;">&#40;</span>svc.<span style="color: #0000FF;">CanPurchaseProduct</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>TestCase<span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> CanPurchaseProduct_NotInStock<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
      <span style="color: #FF0000;">int</span> customerId <span style="color: #008000;">=</span> <span style="color: #FF0000;">123</span>;
      <span style="color: #FF0000;">int</span> prodId <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>;
&nbsp;
      <span style="color: #008080; font-style: italic;">//TODO: Mock this scenario</span>
      CustomerService svc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CustomerService<span style="color: #000000;">&#40;</span>customerId<span style="color: #000000;">&#41;</span>; 
     Assert.<span style="color: #0000FF;">IsFalse</span><span style="color: #000000;">&#40;</span>svc.<span style="color: #0000FF;">CanPurchaseProduct</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>TestCase<span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> CanPurchaseProduct_NotAMember<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
      <span style="color: #FF0000;">int</span> customerId <span style="color: #008000;">=</span> <span style="color: #FF0000;">123</span>;
      <span style="color: #FF0000;">int</span> prodId <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>;
&nbsp;
       <span style="color: #008080; font-style: italic;">//TODO: Mock this scenario</span>
      CustomerService svc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CustomerService<span style="color: #000000;">&#40;</span>customerId<span style="color: #000000;">&#41;</span>; 
     Assert.<span style="color: #0000FF;">IsFalse</span><span style="color: #000000;">&#40;</span>svc.<span style="color: #0000FF;">CanPurchaseProduct</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Your initial implementation of the <code>CanPurchaseProduct()</code> method looks like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CustomerService 
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> CanPurchaseProduct<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> productId<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
       ProductService prodService <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ProductService<span style="color: #000000;">&#40;</span>productId<span style="color: #000000;">&#41;</span>;
       <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>prodService.<span style="color: #0000FF;">IsInStock</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
         <span style="color: #0600FF;">return</span> false;
&nbsp;
       <span style="color: #0600FF;">if</span><span style="color: #000000;">&#40;</span>prodService.<span style="color: #0000FF;">IsMembersOnly</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>custService.<span style="color: #0000FF;">IsMember</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
         <span style="color: #0600FF;">return</span> false;
&nbsp;
      <span style="color: #0600FF;">return</span> true;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>If you&#8217;re familiar with unit tests, you&#8217;ll recognize an issue right away:  The way the implementation currently stands, it is impossible to mock out the different scenarios that we have coded for in our test cases.  The reason for this is tight coupling and lack of abstraction.  The <code>CustomerManager</code>, <code>ProductService</code> and <code>ProductManager</code> classes are being directly instantiated by the classes that use them &#8211; an example of tight coupling.  Furthermore, the classes do not implement an interface thus making it impossible to substitute mock versions for them  &#8211; a direct result of lack of abstraction.  So how do we fix this with minimal changes to the existing classes?  Below is one strategy:</p>
<p>1.  Account for dependencies</p>
<p>The first step is figure out the dependencies.  A dependency is any class, resource file, configuration file, etc. that your code is using either directly or indirectly.  In our case, we have the following dependencies:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #008000;">-</span> CustomerManager
<span style="color: #008000;">-</span> ProductService
<span style="color: #008000;">-</span> ProductManager <span style="color: #000000;">&#40;</span>used by ProductService<span style="color: #000000;">&#41;</span>.</pre></div></div>

<p>2.  Make the dependencies &#8220;plug-and-play&#8221;</p>
<p>Now that we know what the dependencies are and the places where they exist, our next step is to remove all the &#8220;knots&#8221; so that we can make them plug and play.  By &#8220;knots&#8221;, I refer to statements like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">   <span style="color: #008000;">-</span> custManager <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CustomerManager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
   <span style="color: #008000;">-</span> productService <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ProductService<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>  
   <span style="color: #008000;">-</span> prodManager <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ProductManager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>Instead of the classes directly instantiating dependencies, the idea is to provide it to them.  This technique is know as <a href="http://msdn.microsoft.com/en-us/magazine/cc163739.aspx">Dependency Injection</a>.  There are multiple ways of doing this.  Keeping in mind that we need make a minimum number of changes to the existing code base, we&#8217;ll go with the simplest one: </p>
<pre>Modify the constructors/methods to take in the dependencies as parameters.</pre>
<p>This is illustrated below:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CustomerService
<span style="color: #000000;">&#123;</span>
   <span style="color: #008080; font-style: italic;">//Instead of directly instantiating, we pass in the dependency.</span>
   <span style="color: #008080; font-style: italic;">//All new classes can now start using this one to allow for unit      </span>
   <span style="color: #008080; font-style: italic;">//testing.</span>
   <span style="color: #0600FF;">public</span> CustomerService<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> customerId,  
     CustomerManager custManager<span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
      cust <span style="color: #008000;">=</span> custManager.<span style="color: #0000FF;">GetCustomer</span><span style="color: #000000;">&#40;</span>customerId<span style="color: #000000;">&#41;</span>;
   <span style="color: #000000;">&#125;</span>
&nbsp;
   <span style="color: #008080; font-style: italic;">//Original constructor becomes empty.  </span>
   <span style="color: #008080; font-style: italic;">//We still need to keep it around since it is probably used other</span>
   <span style="color: #008080; font-style: italic;">//existing classes</span>
   <span style="color: #0600FF;">public</span> CustomerService<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> customerId<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> 
       <span style="color: #0600FF;">this</span><span style="color: #000000;">&#40;</span>customerId, <span style="color: #008000;">new</span> CustomerManager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
   ...
&nbsp;
   <span style="color: #008080; font-style: italic;">//Note that the method is now taking ProductService as a parameter</span>
   <span style="color: #008080; font-style: italic;">//instead of directly instantiating it.</span>
   <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> CanPurchaseProduct<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> prodId, 
        ProductService prodService<span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>...<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ProductService
<span style="color: #000000;">&#123;</span>
   <span style="color: #008080; font-style: italic;">//Instead of directly instantiating, we pass in the dependency.</span>
   <span style="color: #008080; font-style: italic;">//All new classes can now start using this one to allow for unit      </span>
   <span style="color: #008080; font-style: italic;">//testing.</span>
   <span style="color: #0600FF;">public</span> ProductService<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> productId, ProductManager prodManager<span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
&nbsp;
   <span style="color: #000000;">&#125;</span>
&nbsp;
   <span style="color: #0600FF;">public</span> ProductService<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> productId<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> 
     <span style="color: #0600FF;">this</span><span style="color: #000000;">&#40;</span>productId, <span style="color: #008000;">new</span> ProductManager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Note: When it comes time to re-factor/re-design/re-architect (whatever you want to you call) your entire application, you should go with a better alternative to handle dependency injection instead of the approach shown here.   I would recommend using a tool such as <a href="http://www.springframework.net/overview.html">Spring .NET</a>.</p>
<p>3.  Abstract them away!</p>
<p>The final step then is create an interface for each of the concrete classes and replace all references to the concrete classes with their associated interfaces.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> ICustomerService
<span style="color: #000000;">&#123;</span>
  <span style="color: #FF0000;">bool</span> CanPurchaseProduct<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> customerId, IProductService  
    prodService<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> ICustomerManager <span style="color: #000000;">&#123;</span>...<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IProductService <span style="color: #000000;">&#123;</span>...<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IProductManager <span style="color: #000000;">&#123;</span>...<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CustomerService <span style="color: #008000;">:</span> ICustomerService 
<span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">public</span> CustomerService<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> customerId, ICustomerManager<span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>...<span style="color: #000000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> CanPurchaseProduct<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> prodId, IProductService 
    prodService<span style="color: #000000;">&#41;</span> 
  <span style="color: #000000;">&#123;</span>...<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CustomerManager <span style="color: #008000;">:</span> ICustomerManager <span style="color: #000000;">&#123;</span>...<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ProductService <span style="color: #008000;">:</span> IProductService 
<span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">public</span> ProductService<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> prodId, IProductManager<span style="color: #000000;">&#41;</span> 
  <span style="color: #000000;">&#123;</span>...<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ProductManager <span style="color: #008000;">:</span> IProductManager <span style="color: #000000;">&#123;</span>...<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Now, we can finally substitute our mocks for the dependencies in our unit tests as shown below.  Note that in the test cases below I am using the <a href="http://code.google.com/p/moq/">Moq Unit Testing Framework</a> to setup the mocks but you could use any other framework that you&#8217;d like or none at all (if you wish to create the mocks manually).</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>TestCase<span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> CanPurchaseProduct_InStockAndForAll<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #FF0000;">int</span> customerId <span style="color: #008000;">=</span> <span style="color: #FF0000;">123</span>;
   <span style="color: #FF0000;">int</span> prodId <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>;
&nbsp;
   <span style="color: #008080; font-style: italic;">//create mocks</span>
   Mock<span style="color: #008000;">&lt;</span>ICustomerManager<span style="color: #008000;">&gt;</span> custManager <span style="color: #008000;">=</span> 
     mockFactory.<span style="color: #0000FF;">Create</span><span style="color: #008000;">&lt;</span>ICustomerManager<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
   Mock<span style="color: #008000;">&lt;</span>IProductService<span style="color: #008000;">&gt;</span> prodService <span style="color: #008000;">=</span> 
      mockFactory.<span style="color: #0000FF;">Create</span><span style="color: #008000;">&lt;</span>IProductService<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
   Customer cust <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Customer<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">123</span><span style="color: #000000;">&#41;</span>;
   cust.<span style="color: #0000FF;">IsMember</span> <span style="color: #008000;">=</span> false;
&nbsp;
   <span style="color: #008080; font-style: italic;">//setup mocks</span>
   custManager.<span style="color: #0000FF;">Setup</span><span style="color: #000000;">&#40;</span>cm <span style="color: #008000;">=&gt;</span> cm.<span style="color: #0000FF;">GetCustomer</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">123</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Returns</span><span style="color: #000000;">&#40;</span>cust<span style="color: #000000;">&#41;</span>;
&nbsp;
   prodService.<span style="color: #0000FF;">Setup</span><span style="color: #000000;">&#40;</span>ps <span style="color: #008000;">=&gt;</span> ps.<span style="color: #0000FF;">IsInStock</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Returns</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>;
   prodService.<span style="color: #0000FF;">Setup</span><span style="color: #000000;">&#40;</span>ps <span style="color: #008000;">=&gt;</span> ps.<span style="color: #0000FF;">IsMembersOnly</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Returns</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span>;
&nbsp;
   <span style="color: #008080; font-style: italic;">//run test</span>
   CustomerService svc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CustomerService<span style="color: #000000;">&#40;</span>customerId, custManager.<span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span>; 
   Assert.<span style="color: #0000FF;">IsTrue</span><span style="color: #000000;">&#40;</span>svc.<span style="color: #0000FF;">CanPurchaseProduct</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span>, prodService.<span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>TestCase<span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> CanPurchaseProduct_NotInStock<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #FF0000;">int</span> customerId <span style="color: #008000;">=</span> <span style="color: #FF0000;">123</span>;
   <span style="color: #FF0000;">int</span> prodId <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>;
&nbsp;
   <span style="color: #008080; font-style: italic;">//create mocks</span>
   Mock<span style="color: #008000;">&lt;</span>ICustomerManager<span style="color: #008000;">&gt;</span> custManager <span style="color: #008000;">=</span> 
      mockFactory.<span style="color: #0000FF;">Create</span><span style="color: #008000;">&lt;</span>ICustomerManager<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
   Mock<span style="color: #008000;">&lt;</span>IProductService<span style="color: #008000;">&gt;</span> prodService <span style="color: #008000;">=</span> 
      mockFactory.<span style="color: #0000FF;">Create</span><span style="color: #008000;">&lt;</span>IProductService<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
   Customer cust <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Customer<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">123</span><span style="color: #000000;">&#41;</span>;
   cust.<span style="color: #0000FF;">IsMember</span> <span style="color: #008000;">=</span> false;
&nbsp;
   <span style="color: #008080; font-style: italic;">//setup mocks</span>
   custManager.<span style="color: #0000FF;">Setup</span><span style="color: #000000;">&#40;</span>cm <span style="color: #008000;">=&gt;</span> cm.<span style="color: #0000FF;">GetCustomer</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">123</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Returns</span><span style="color: #000000;">&#40;</span>cust<span style="color: #000000;">&#41;</span>;
   prodService.<span style="color: #0000FF;">Setup</span><span style="color: #000000;">&#40;</span>ps <span style="color: #008000;">=&gt;</span> ps.<span style="color: #0000FF;">IsInStock</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Returns</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span>;
&nbsp;
   <span style="color: #008080; font-style: italic;">//run test</span>
   CustomerService svc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CustomerService<span style="color: #000000;">&#40;</span>customerId, custManager.<span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span>; 
   Assert.<span style="color: #0000FF;">IsFalse</span><span style="color: #000000;">&#40;</span>svc.<span style="color: #0000FF;">CanPurchaseProduct</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span>, prodService.<span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#91;</span>TestCase<span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> CanPurchaseProduct_NotAMember<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #FF0000;">int</span> customerId <span style="color: #008000;">=</span> <span style="color: #FF0000;">123</span>;
   <span style="color: #FF0000;">int</span> prodId <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>;
&nbsp;
   <span style="color: #008080; font-style: italic;">//create mocks</span>
   Mock<span style="color: #008000;">&lt;</span>ICustomerManager<span style="color: #008000;">&gt;</span> custManager <span style="color: #008000;">=</span> 
      mockFactory.<span style="color: #0000FF;">Create</span><span style="color: #008000;">&lt;</span>ICustomerManager<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
   Mock<span style="color: #008000;">&lt;</span>IProductService<span style="color: #008000;">&gt;</span> prodService <span style="color: #008000;">=</span> 
      mockFactory.<span style="color: #0000FF;">Create</span><span style="color: #008000;">&lt;</span>IProductService<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
   Customer cust <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Customer<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">123</span><span style="color: #000000;">&#41;</span>;
   cust.<span style="color: #0000FF;">IsMember</span> <span style="color: #008000;">=</span> false;
&nbsp;
   <span style="color: #008080; font-style: italic;">//setup mocks</span>
   custManager.<span style="color: #0000FF;">Setup</span><span style="color: #000000;">&#40;</span>cm <span style="color: #008000;">=&gt;</span> cm.<span style="color: #0000FF;">GetCustomer</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">123</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Returns</span><span style="color: #000000;">&#40;</span>cust<span style="color: #000000;">&#41;</span>;
&nbsp;
   prodService.<span style="color: #0000FF;">Setup</span><span style="color: #000000;">&#40;</span>ps <span style="color: #008000;">=&gt;</span> ps.<span style="color: #0000FF;">IsInStock</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Returns</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>;
   prodService.<span style="color: #0000FF;">Setup</span><span style="color: #000000;">&#40;</span>ps <span style="color: #008000;">=&gt;</span> ps.<span style="color: #0000FF;">IsMembersOnly</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Returns</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>;
&nbsp;
   <span style="color: #008080; font-style: italic;">//run test</span>
   CustomerService svc <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CustomerService<span style="color: #000000;">&#40;</span>customerId, custManager.<span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span>; 
   Assert.<span style="color: #0000FF;">IsFalse</span><span style="color: #000000;">&#40;</span>svc.<span style="color: #0000FF;">CanPurchaseProduct</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span>, prodService.<span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And there you have it.  We were able to take an existing code base that had no support for unit-testing and re-factor it so that the additional methods that we added could be unit-tested.  Furthermore, we did this without requiring us to make any sweeping architectural changes to the existing code base.  </p>
<p>One could argue if the additional work is really worthwhile.  If you&#8217;re already a test-driven developer then I don&#8217;t need convince you that it is definitely worthwhile.  But if you&#8217;re not then I&#8217;ll highlight a few long-term benefits that result from the additional work:</p>
<p>- The code base is now more extensible. It can work with other implementations for ICustomerManager and IProductService.<br />
- At any given time one can run the test cases and know if anything has been broken.<br />
- Unit-testing forces us to think about the dependencies and code in a manner that leads to clean and easy-to-understand code.<br />
- The test cases serve as an up-to-date documentation on what the code does and how it is being  used.</p>
<p>I hope that the above points will encourage you to investigate the pros/cons of test driven development more fully.</p>
<p><a href="http://www.codeproject.com/script/Articles/BlogFeedList.aspx?amid=noorani786" rel="tag" style="display:none">CodeProject</a> </p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Refactoring+for+Unit+Testing+http://fpko8.th8.us" title="Post to Twitter"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://buzz.yahoo.com/submit?submitUrl=http://nizarnoorani.com/index.php/archives/173&amp;submitHeadline=Refactoring+for+Unit+Testing" title="Post to Yahoo Buzz"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a class="tt" href="http://delicious.com/post?url=http://nizarnoorani.com/index.php/archives/173&amp;title=Refactoring+for+Unit+Testing" title="Post to Delicious"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://nizarnoorani.com/index.php/archives/173&amp;title=Refactoring+for+Unit+Testing" title="Post to Digg"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://nizarnoorani.com/index.php/archives/173&amp;t=Refactoring+for+Unit+Testing" title="Post to Facebook"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/173&amp;title=Refactoring+for+Unit+Testing" title="Post to Reddit"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/173&amp;title=Refactoring+for+Unit+Testing" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://nizarnoorani.com/index.php/archives/173&amp;title=Refactoring+for+Unit+Testing" title="Post to StumbleUpon"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/index.php/archives/173/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>WCF over HTTPS</title>
		<link>http://nizarnoorani.com/index.php/archives/156</link>
		<comments>http://nizarnoorani.com/index.php/archives/156#comments</comments>
		<pubDate>Wed, 26 Aug 2009 14:54:55 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[https]]></category>
		<category><![CDATA[httpTransport]]></category>
		<category><![CDATA[transport]]></category>
		<category><![CDATA[WCF over HTTPS]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=156</guid>
		<description><![CDATA[I have been working on a WCF web service that I finally deployed to our staging server which runs over HTTPS.  Everything seemed fine.  I was able to hit it and generate the WSDL.  However, when I tried running the svcutil.exe on it, I got the following error:

Error: Cannot add the transport [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on a WCF web service that I finally deployed to our staging server which runs over HTTPS.  Everything seemed fine.  I was able to hit it and generate the WSDL.  However, when I tried running the <code>svcutil.exe</code> on it, I got the following error:</p>
<pre>
Error: Cannot add the transport element 'httpTransport'. Another transport eleme
nt already exists in the binding 'System.ServiceModel.Configuration.HttpTranspor
tElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=
b77a5c561934e089'. There can only be one transport element for each binding.
</pre>
<p>Upon investigation, I realized that when deploying a WCF web service over HTTPS, you must set the &#8216;Security&#8217; mode to &#8216;Transport.&#8217;.  Below are the steps to do this:</p>
<p>1.  Add the following inside the <system.serviceModel> section:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bindings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsHttpBinding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;binding</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;webBinding&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">&quot;Transport&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/security<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/binding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsHttpBinding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bindings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>2.  Add the following attribute to the <endpoint /> element:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;">bindingConfiguration=&quot;webBinding&quot;</pre></div></div>

<p>That should be all.</p>
<p>Below is a sample <system.serviceModel> section:</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system</span>.serviceModel<span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;MyWebService&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">behaviorConfiguration</span>=<span style="color: #ff0000;">&quot;ServiceBehavior&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- Service Endpoints --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;wsHttpBinding&quot;</span></span>
<span style="color: #009900;">           <span style="color: #000066;">bindingConfiguration</span>=<span style="color: #ff0000;">&quot;webBinding&quot;</span> <span style="color: #000066;">contract</span>=<span style="color: #ff0000;">&quot;IMyWebService&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/endpoint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;endpoint</span> <span style="color: #000066;">address</span>=<span style="color: #ff0000;">&quot;mex&quot;</span> <span style="color: #000066;">binding</span>=<span style="color: #ff0000;">&quot;mexHttpBinding&quot;</span> </span>
<span style="color: #009900;">         <span style="color: #000066;">contract</span>=<span style="color: #ff0000;">&quot;IMetadataExchange&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/services<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bindings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;wsHttpBinding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;binding</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;webBinding&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security</span> <span style="color: #000066;">mode</span>=<span style="color: #ff0000;">&quot;Transport&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/binding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/wsHttpBinding<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bindings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;behaviors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;serviceBehaviors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;behavior</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ServiceBehavior&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;serviceMetadata</span> <span style="color: #000066;">httpGetEnabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/behavior<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/serviceBehaviors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/behaviors<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system</span>.serviceModel<span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div>

<p align="left"><a class="tt" href="http://twitter.com/home/?status=WCF+over+HTTPS+http://icmr3.th8.us" title="Post to Twitter"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://buzz.yahoo.com/submit?submitUrl=http://nizarnoorani.com/index.php/archives/156&amp;submitHeadline=WCF+over+HTTPS" title="Post to Yahoo Buzz"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a class="tt" href="http://delicious.com/post?url=http://nizarnoorani.com/index.php/archives/156&amp;title=WCF+over+HTTPS" title="Post to Delicious"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://nizarnoorani.com/index.php/archives/156&amp;title=WCF+over+HTTPS" title="Post to Digg"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://nizarnoorani.com/index.php/archives/156&amp;t=WCF+over+HTTPS" title="Post to Facebook"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/156&amp;title=WCF+over+HTTPS" title="Post to Reddit"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/156&amp;title=WCF+over+HTTPS" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://nizarnoorani.com/index.php/archives/156&amp;title=WCF+over+HTTPS" title="Post to StumbleUpon"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/index.php/archives/156/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What the heck was I working on??</title>
		<link>http://nizarnoorani.com/index.php/archives/135</link>
		<comments>http://nizarnoorani.com/index.php/archives/135#comments</comments>
		<pubDate>Tue, 25 Aug 2009 04:16:10 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Tips And Tricks]]></category>
		<category><![CDATA[note]]></category>
		<category><![CDATA[outlook]]></category>
		<category><![CDATA[vs studio]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=135</guid>
		<description><![CDATA[Does it ever happen to you that you go to work in the morning, look at the screen and then ask yourself : What the heck was I working on??  Happens to me all the time.  Maybe I was in the middle of debugging some code the previous day, or writing a unit-test [...]]]></description>
			<content:encoded><![CDATA[<p>Does it ever happen to you that you go to work in the morning, look at the screen and then ask yourself : What the heck was I working on??  Happens to me all the time.  Maybe I was in the middle of debugging some code the previous day, or writing a unit-test or finishing up the implementation of a class or going through existing code to understand what it&#8217;s doing or something else.  Given the detailed nature of software development, it&#8217;s sometimes hard to remember where you left off and from where you need to pick things up again.  </p>
<p>Below is an approach that&#8217;s worked quite well for me:<br />
<div id="attachment_144" class="wp-caption alignleft" style="width: 810px"><img src="http://nizarnoorani.com/wp-content/uploads/2009/08/untitled2.jpg" alt="Tells me where I left off" title="A note to myself" width="800" height="500" class="size-full wp-image-144" /><p class="wp-caption-text">Tells me where I left off</p></div><br />
<br/><br/><br />
I write myself a little MS Outlook note and put right in the middle of the screen. Simple, but very effective!</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=What+the+heck+was+I+working+on%3F%3F+http://7yxgx.th8.us" title="Post to Twitter"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://buzz.yahoo.com/submit?submitUrl=http://nizarnoorani.com/index.php/archives/135&amp;submitHeadline=What+the+heck+was+I+working+on%3F%3F" title="Post to Yahoo Buzz"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a class="tt" href="http://delicious.com/post?url=http://nizarnoorani.com/index.php/archives/135&amp;title=What+the+heck+was+I+working+on%3F%3F" title="Post to Delicious"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://nizarnoorani.com/index.php/archives/135&amp;title=What+the+heck+was+I+working+on%3F%3F" title="Post to Digg"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://nizarnoorani.com/index.php/archives/135&amp;t=What+the+heck+was+I+working+on%3F%3F" title="Post to Facebook"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/135&amp;title=What+the+heck+was+I+working+on%3F%3F" title="Post to Reddit"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/135&amp;title=What+the+heck+was+I+working+on%3F%3F" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://nizarnoorani.com/index.php/archives/135&amp;title=What+the+heck+was+I+working+on%3F%3F" title="Post to StumbleUpon"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/index.php/archives/135/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Am I officially a &#8220;nerd&#8221;??</title>
		<link>http://nizarnoorani.com/index.php/archives/132</link>
		<comments>http://nizarnoorani.com/index.php/archives/132#comments</comments>
		<pubDate>Wed, 12 Aug 2009 03:59:06 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit Tests]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=132</guid>
		<description><![CDATA[okay i know this is lame.. but i am seriously getting a high from writing unit test cases.. seriously it&#8217;s such a rush to see 243 test cases all run AND pass in a matter of seconds&#8230;  if i don&#8217;t stop i am afraid i&#8217;ll turn into a &#8220;testaholic&#8221;
      [...]]]></description>
			<content:encoded><![CDATA[<p>okay i know this is lame.. but i am seriously getting a high from writing unit test cases.. seriously it&#8217;s such a rush to see 243 test cases all run AND pass in a matter of seconds&#8230;  if i don&#8217;t stop i am afraid i&#8217;ll turn into a &#8220;testaholic&#8221;</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Am+I+officially+a+%E2%80%9Cnerd%E2%80%9D%3F%3F+http://6t24q.th8.us" title="Post to Twitter"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://buzz.yahoo.com/submit?submitUrl=http://nizarnoorani.com/index.php/archives/132&amp;submitHeadline=Am+I+officially+a+%E2%80%9Cnerd%E2%80%9D%3F%3F" title="Post to Yahoo Buzz"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a class="tt" href="http://delicious.com/post?url=http://nizarnoorani.com/index.php/archives/132&amp;title=Am+I+officially+a+%E2%80%9Cnerd%E2%80%9D%3F%3F" title="Post to Delicious"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://nizarnoorani.com/index.php/archives/132&amp;title=Am+I+officially+a+%E2%80%9Cnerd%E2%80%9D%3F%3F" title="Post to Digg"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://nizarnoorani.com/index.php/archives/132&amp;t=Am+I+officially+a+%E2%80%9Cnerd%E2%80%9D%3F%3F" title="Post to Facebook"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/132&amp;title=Am+I+officially+a+%E2%80%9Cnerd%E2%80%9D%3F%3F" title="Post to Reddit"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/132&amp;title=Am+I+officially+a+%E2%80%9Cnerd%E2%80%9D%3F%3F" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://nizarnoorani.com/index.php/archives/132&amp;title=Am+I+officially+a+%E2%80%9Cnerd%E2%80%9D%3F%3F" title="Post to StumbleUpon"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/index.php/archives/132/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cast to the rescue!</title>
		<link>http://nizarnoorani.com/index.php/archives/128</link>
		<comments>http://nizarnoorani.com/index.php/archives/128#comments</comments>
		<pubDate>Wed, 04 Mar 2009 00:20:37 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Cast]]></category>
		<category><![CDATA[converting to interface]]></category>
		<category><![CDATA[generics]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=128</guid>
		<description><![CDATA[Just learn&#8217;t something today that I&#8217;d like to share.
Say you&#8217;ve got a generic list of

IQueryable&#60;Person&#62; persons;

that you&#8217;d like to convert to

IQueryable&#60;IPerson&#62; iPersons;

where Person : IPerson.  
How do you do this?  Very simple:

IQueryable&#60;IPerson&#62; iPersons = persons.Cast&#60;IPerson&#62;&#40;&#41;;

Note that:

IQueryable&#60;IPerson&#62; iPersons = &#40;IQueryable&#60;IPerson&#62;&#41;persons;

won&#8217;t work.
      Reddit ]]></description>
			<content:encoded><![CDATA[<p>Just learn&#8217;t something today that I&#8217;d like to share.</p>
<p>Say you&#8217;ve got a generic list of</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">IQueryable<span style="color: #008000;">&lt;</span>Person<span style="color: #008000;">&gt;</span> persons;</pre></div></div>

<p>that you&#8217;d like to convert to</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">IQueryable<span style="color: #008000;">&lt;</span>IPerson<span style="color: #008000;">&gt;</span> iPersons;</pre></div></div>

<p>where Person : IPerson.  </p>
<p>How do you do this?  Very simple:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">IQueryable<span style="color: #008000;">&lt;</span>IPerson<span style="color: #008000;">&gt;</span> iPersons <span style="color: #008000;">=</span> persons.<span style="color: #0000FF;">Cast</span><span style="color: #008000;">&lt;</span>IPerson<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Note that:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp csharp" style="font-family:monospace;">IQueryable<span style="color: #008000;">&lt;</span>IPerson<span style="color: #008000;">&gt;</span> iPersons <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>IQueryable<span style="color: #008000;">&lt;</span>IPerson<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#41;</span>persons;</pre></div></div>

<p>won&#8217;t work.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Cast%3C%3E+to+the+rescue%21+http://4gqfn.th8.us" title="Post to Twitter"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://buzz.yahoo.com/submit?submitUrl=http://nizarnoorani.com/index.php/archives/128&amp;submitHeadline=Cast%3C%3E+to+the+rescue%21" title="Post to Yahoo Buzz"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a class="tt" href="http://delicious.com/post?url=http://nizarnoorani.com/index.php/archives/128&amp;title=Cast%3C%3E+to+the+rescue%21" title="Post to Delicious"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://nizarnoorani.com/index.php/archives/128&amp;title=Cast%3C%3E+to+the+rescue%21" title="Post to Digg"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://nizarnoorani.com/index.php/archives/128&amp;t=Cast%3C%3E+to+the+rescue%21" title="Post to Facebook"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/128&amp;title=Cast%3C%3E+to+the+rescue%21" title="Post to Reddit"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/128&amp;title=Cast%3C%3E+to+the+rescue%21" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://nizarnoorani.com/index.php/archives/128&amp;title=Cast%3C%3E+to+the+rescue%21" title="Post to StumbleUpon"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/index.php/archives/128/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Fix to Mock.SetupAllProperties() &#8211; Not working in Moq 3.0</title>
		<link>http://nizarnoorani.com/index.php/archives/126</link>
		<comments>http://nizarnoorani.com/index.php/archives/126#comments</comments>
		<pubDate>Tue, 03 Mar 2009 19:36:10 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Unit Tests]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[moq]]></category>
		<category><![CDATA[SetupAllProperties()]]></category>
		<category><![CDATA[SetupAllProperties() fix]]></category>
		<category><![CDATA[SetupAllProperties() not working]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=126</guid>
		<description><![CDATA[If you download the latest version of Moq, you&#8217;ll notice that the Mock.SetupAllProperties() method does not work.  Try it in Debug mode and you&#8217;ll notice that the method just gets skipped.
Upon inspection, I discovered that a conditional attribute that was being applied to the method which was causing it to be skipped.  I [...]]]></description>
			<content:encoded><![CDATA[<p>If you download the latest version of <a href='http://code.google.com/p/moq/'>Moq</a>, you&#8217;ll notice that the Mock<T>.SetupAllProperties() method does not work.  Try it in Debug mode and you&#8217;ll notice that the method just gets skipped.</p>
<p>Upon inspection, I discovered that a conditional attribute that was being applied to the method which was causing it to be skipped.  I am assuming that attribute was meant to be removed but got overlooked.</p>
<p>Anyways, to fix it, here is what you do:</p>
<p>1.  Download the source code for Moq and open up the file Mock.Generic.cs<br />
2.  Find the method SetupAllProperties() and remove the conditional attribute:<br />
     [Conditional("DESKTOP")]<br />
3.  Re-build and overwrite for existing Moq.dll that your project is referencing with the new one.</p>
<p>Cheers!</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Fix+to+Mock.SetupAllProperties%28%29+%E2%80%93+Not+working+in+Moq+3.0+http://tgy5o.th8.us" title="Post to Twitter"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://buzz.yahoo.com/submit?submitUrl=http://nizarnoorani.com/index.php/archives/126&amp;submitHeadline=Fix+to+Mock.SetupAllProperties%28%29+%E2%80%93+Not+working+in+Moq+3.0" title="Post to Yahoo Buzz"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a class="tt" href="http://delicious.com/post?url=http://nizarnoorani.com/index.php/archives/126&amp;title=Fix+to+Mock.SetupAllProperties%28%29+%E2%80%93+Not+working+in+Moq+3.0" title="Post to Delicious"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://nizarnoorani.com/index.php/archives/126&amp;title=Fix+to+Mock.SetupAllProperties%28%29+%E2%80%93+Not+working+in+Moq+3.0" title="Post to Digg"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://nizarnoorani.com/index.php/archives/126&amp;t=Fix+to+Mock.SetupAllProperties%28%29+%E2%80%93+Not+working+in+Moq+3.0" title="Post to Facebook"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/126&amp;title=Fix+to+Mock.SetupAllProperties%28%29+%E2%80%93+Not+working+in+Moq+3.0" title="Post to Reddit"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/126&amp;title=Fix+to+Mock.SetupAllProperties%28%29+%E2%80%93+Not+working+in+Moq+3.0" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://nizarnoorani.com/index.php/archives/126&amp;title=Fix+to+Mock.SetupAllProperties%28%29+%E2%80%93+Not+working+in+Moq+3.0" title="Post to StumbleUpon"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/index.php/archives/126/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Integrating TypeMock with ASP .NET Unit tests</title>
		<link>http://nizarnoorani.com/index.php/archives/111</link>
		<comments>http://nizarnoorani.com/index.php/archives/111#comments</comments>
		<pubDate>Mon, 16 Feb 2009 13:22:54 +0000</pubDate>
		<dc:creator>Nizar</dc:creator>
				<category><![CDATA[ASP .NET]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit Tests]]></category>
		<category><![CDATA[ivonna]]></category>
		<category><![CDATA[mocking]]></category>
		<category><![CDATA[type mock]]></category>
		<category><![CDATA[vs studio]]></category>

		<guid isPermaLink="false">http://nizarnoorani.com/?p=111</guid>
		<description><![CDATA[When it comes to writing unit tests for your ASP .NET pages, there isn&#8217;t much help out there.  I experimented with a few open source testing tools and found some major limitations.  
Both NUnitAsp and WaitN, for instance, are &#8220;client-side&#8221; tools.  In other words, you have to write your tests against the [...]]]></description>
			<content:encoded><![CDATA[<p>When it comes to writing unit tests for your ASP .NET pages, there isn&#8217;t much help out there.  I experimented with a few open source testing tools and found some major limitations.  </p>
<p>Both NUnitAsp and WaitN, for instance, are &#8220;client-side&#8221; tools.  In other words, you have to write your tests against the actual HTML output.  For example, to get the value of a textbox, you have to specify the actual HTML id of the textbox.  That&#8217;s painful!  Especially, since ASP .NET ends up assigning long and complicated ID&#8217;s to your controls.  Plus NUnitAsp is no longer being maintained or supported.</p>
<p>Unlike NUnitAsp and WaitN, VS Studio ASP .NET Unit testing let&#8217;s you examine the actual HttpRequest object.  What this means is that you can call methods on your Page and get access to the controls within the page.  VS Studio ASP .NET is a pretty decent tool and maybe the answer for you. IF you don&#8217;t need to use TypeMock that is.  But if you do, then tough luck because VS Studio ASP .NET unit tests don&#8217;t work with TypeMock.  If you give it try, you&#8217;ll get the following exception:</p>
<pre>
Test method AzAsh.WebApp.Tests.DefaultTest.LoginNotRequiredTest threw exception:  TypeMock.TypeMockException:
*** Typemock Isolator is not currently enabled.
To enable do one of the following:

* To run Typemock Isolator as part of an automated process you can:
   - run tests via TMockRunner.exe command line tool
   - use 'TypeMockStart' tasks for MSBuild or NAnt

* To work with Typemock Isolator inside Visual Studio.NET:
        set Tools->Enable Typemock Isolator from within Visual Studio

For more information consult the documentation (see 'Running' topic).
</pre>
<p>Check the enable property as they have suggested and you&#8217;ll notice that Typemock <b><i>is</i></b> enabled!  So, what gives?  I have no idea.  But I do know that <a href='http://sm-art.biz/Ivonna/Download.aspx'>Ivonna</a> &#8211; a ASP .NET testing tool that is being developed in partnership with TypeMock WILL let you work in conjunction with TypeMock.  Like VS Studio, it allows you to examine the intrinsic objects, such as the Page object.  In addition, it&#8217;s got another neat feature that let&#8217;s you inject setup code and assertions into your page&#8217;s lifecycle event handlers &#8211; very handy especially during type mocking.  The only drawback is that it&#8217;s a little slow.  The unit tests take a while to run. </p>
<p>So if you&#8217;ve been scratching your head trying to figure how to develop ASP .NET tests that can work with TypeMock, Ivonna is probably the tool you&#8217;ve been waiting for!  </p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Integrating+TypeMock+with+ASP+.NET+Unit+tests+http://q493x.th8.us" title="Post to Twitter"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://buzz.yahoo.com/submit?submitUrl=http://nizarnoorani.com/index.php/archives/111&amp;submitHeadline=Integrating+TypeMock+with+ASP+.NET+Unit+tests" title="Post to Yahoo Buzz"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a class="tt" href="http://delicious.com/post?url=http://nizarnoorani.com/index.php/archives/111&amp;title=Integrating+TypeMock+with+ASP+.NET+Unit+tests" title="Post to Delicious"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-delicious.png" alt="Post to Delicious" /></a> <a class="tt" href="http://digg.com/submit?url=http://nizarnoorani.com/index.php/archives/111&amp;title=Integrating+TypeMock+with+ASP+.NET+Unit+tests" title="Post to Digg"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://nizarnoorani.com/index.php/archives/111&amp;t=Integrating+TypeMock+with+ASP+.NET+Unit+tests" title="Post to Facebook"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-facebook.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/111&amp;title=Integrating+TypeMock+with+ASP+.NET+Unit+tests" title="Post to Reddit"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://nizarnoorani.com/index.php/archives/111&amp;title=Integrating+TypeMock+with+ASP+.NET+Unit+tests" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://nizarnoorani.com/index.php/archives/111&amp;title=Integrating+TypeMock+with+ASP+.NET+Unit+tests" title="Post to StumbleUpon"><img class="nothumb" src="http://nizarnoorani.com/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://nizarnoorani.com/index.php/archives/111/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->