<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Md. Adil Akhter's Weblogs</title><link>http://weblogs.asp.net/adilakhter/default.aspx</link><description>Me, My Thoughts and My Journey ....</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/AdilAkhtersWeblogs" type="application/rss+xml" /><feedburner:emailServiceId>AdilAkhtersWeblogs</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><title>Cr-Documentor - A Cool DXCore Plug-in for Visual Studio</title><link>http://feedproxy.google.com/~r/AdilAkhtersWeblogs/~3/CDrVFMxAbXw/cr-documentor.aspx</link><pubDate>Mon, 24 Nov 2008 12:48:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6751453</guid><dc:creator>Adil Akhter</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://weblogs.asp.net/adilakhter/rsscomments.aspx?PostID=6751453</wfw:commentRss><wfw:comment>http://weblogs.asp.net/adilakhter/commentapi.aspx?PostID=6751453</wfw:comment><comments>http://weblogs.asp.net/adilakhter/archive/2008/11/24/cr-documentor.aspx#comments</comments><description>May be I am last person on the Earth, who discovered and started using this way too cool plug-in recently ….however, if you have not checked it out yet – probably you should do it now :). Cr_Documentor gives you just-in time rendering of your XML Documentation...(&lt;a href="http://weblogs.asp.net/adilakhter/archive/2008/11/24/cr-documentor.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6751453" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AdilAkhtersWeblogs/~4/CDrVFMxAbXw" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/adilakhter/archive/tags/Tool/default.aspx">Tool</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/Cr_5F00_Documentor/default.aspx">Cr_Documentor</category><feedburner:origLink>http://weblogs.asp.net/adilakhter/archive/2008/11/24/cr-documentor.aspx</feedburner:origLink></item><item><title>.Net Provider Pattern - Designing decoupled and extensible Component for .Net Application</title><link>http://feedproxy.google.com/~r/AdilAkhtersWeblogs/~3/6DaYM2QtdK0/ProviderDesignPattern.aspx</link><pubDate>Sun, 02 Nov 2008 21:22:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6704951</guid><dc:creator>Adil Akhter</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://weblogs.asp.net/adilakhter/rsscomments.aspx?PostID=6704951</wfw:commentRss><wfw:comment>http://weblogs.asp.net/adilakhter/commentapi.aspx?PostID=6704951</wfw:comment><comments>http://weblogs.asp.net/adilakhter/archive/2008/11/02/ProviderDesignPattern.aspx#comments</comments><description>&lt;h5&gt;Introduction &lt;/h5&gt;  &lt;p&gt;&lt;font size="2"&gt;Provider Design pattern of .Net Framework 2.0 is one of the most exciting way to design component in decoupled and extensible way. In my today&amp;#8217;s post, I will discuss about this design pattern and how we can use it to make the components inside our applications decoupled while providing extension point for our components and finally I will discuss some of the great advantages of this design pattern. Hence , sit back tight , I will give you a quick tour on Provider pattern which I divided in following sections &amp;#8211; &lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;1. &lt;/font&gt;&lt;a href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_What_is_Provider" mce_href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_What_is_Provider"&gt;&lt;font size="2"&gt;What is Provider Design Pattern ?&lt;/font&gt;&lt;/a&gt;       &lt;br /&gt;&lt;font size="2"&gt;2. &lt;/font&gt;&lt;a href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_Provider_Pattern_-" mce_href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_Provider_Pattern_-"&gt;&lt;font size="2"&gt;Provider Pattern &amp;#8211; Nuts &amp;amp; Bolts in Nutshell&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;    &lt;ul&gt;     &lt;li&gt;&lt;font size="2"&gt;&amp;#160;&lt;/font&gt;&lt;a href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_Custom_Configuration_Section" mce_href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_Custom_Configuration_Section"&gt;&lt;font size="2"&gt;Custom Configuration Section&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/li&gt;      &lt;li&gt;&lt;font size="2"&gt;&amp;#160;&lt;/font&gt;&lt;a href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_API_Class" mce_href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_API_Class"&gt;&lt;font size="2"&gt;API Class&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/li&gt;      &lt;li&gt;&lt;a href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_Concrete_Provider_and" mce_href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_Concrete_Provider_and"&gt;&lt;font size="2"&gt;Application ProviderBase and Concrete Providers&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/li&gt;   &lt;/ul&gt;   &lt;font size="2"&gt;3. &lt;/font&gt;&lt;a href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_Advantage_of" mce_href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_Advantage_of"&gt;&lt;font size="2"&gt;Advantages of Provider Design Pattern&lt;/font&gt;&lt;/a&gt;     &lt;br /&gt;&lt;font size="2"&gt;4. &lt;/font&gt;&lt;a href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_4._Last_few" mce_href="http://weblogs.asp.net/controlpanel/blogs/posteditor.aspx?SelectedNavItem=Posts&amp;amp;sectionid=934&amp;amp;postid=6704951#_4._Last_few"&gt;&lt;font size="2"&gt;Last few words&amp;#8230;&lt;/font&gt;&lt;/a&gt;     &lt;p mce_keep="true"&gt;&amp;#160;&lt;/p&gt; &lt;/blockquote&gt;  &lt;h5&gt;&lt;a class="" title="_What_is_Provider" name="_What_is_Provider"&gt;&lt;/a&gt;1. What is Provider Pattern? &lt;/h5&gt;  &lt;p&gt;&lt;font size="2"&gt;Provider pattern is a way in .Net Framework 2.0 to design extensible and decoupled Component. Ron Howard mentioned - &lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2"&gt;&amp;#8220;&lt;em&gt;A provider is simply a contract between an API and the Business Logic/Data Abstraction Layer. The provider is the implementation of the API separate from the API itself.&lt;/em&gt;&amp;#8221;&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&lt;font size="2"&gt;Provider Pattern is a way to get rid of the coupling among the components while making the components extensible. Main reason for our today's discussion on Provider Pattern is its wonderful ability to publish the API and at the same time make the API pluggable; that is - it gives us the flexibility to choose the API that is best suited for the application rather than the one developed by API developer. And from an API developer perspective, it allows them to create an extension point for the API where clients of the framework can extend the functionality in their own way. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;In the next section, we will see how we can build our component using Provider Design Pattern - &lt;/font&gt;&lt;/p&gt;  &lt;h5&gt;&lt;a class="" title="_Provider_Pattern_-" name="_Provider_Pattern_-"&gt;&lt;/a&gt;2. Provider Pattern - Nuts &amp;amp; Bolts in a Nutshell&lt;/h5&gt;  &lt;p&gt;&lt;font size="2"&gt;The basic idea behind the provider pattern is to have multiple concrete providers and selecting one of them depending on configuration (just a change in *.config file can lead to completely different provider to perform the operation) at the runtime by avoiding writing huge amount of code and coupling among the components. Provider pattern completely abstract the decision of which provider to use out of programming interface. That way we can say that, it has some kind of dependency injection/inversion flavor, but it does not use any kind of container like Windsor or Spring.net.&amp;#160; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;First, let&amp;#8217;s consider our problem domain that we will be using throughout today's discussion. For the sake of simplicity, we have the following simple domain object- &lt;em&gt;User&lt;/em&gt; and we need a persistence media to store(/Save) and retrieve(/Get) it &amp;#8211; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/User_2.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/User_2.jpg"&gt;&lt;font size="2"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="194" alt="User" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/User_thumb.jpg" width="165" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/User_thumb.jpg" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;&amp;#160; &lt;br /&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Figure1 : User Domain Object&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;So, the class responsible for communicating with the physical persistence media - &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;PersistenceManager has only 2 job now &amp;#8211;      &lt;br /&gt;&lt;/font&gt;    &lt;br /&gt;&lt;img src="http://www.dotnetscraps.com/samples/bullets/004.gif" align="middle" mce_src="http://www.dotnetscraps.com/samples/bullets/004.gif" /&gt;&amp;#160; &lt;font size="2"&gt;&lt;span style="color: blue"&gt;public static void &lt;/span&gt;Save&amp;lt;T&amp;gt;(T obj)&amp;#160; &lt;br /&gt;&lt;img src="http://www.dotnetscraps.com/samples/bullets/004.gif" align="middle" mce_src="http://www.dotnetscraps.com/samples/bullets/004.gif" /&gt;&amp;#160; &lt;span style="color: blue"&gt;public static &lt;/span&gt;T Get&amp;lt;T&amp;gt;()&lt;/font&gt;&lt;/p&gt; &lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;  &lt;p&gt;&lt;font size="2"&gt;Currently we are only supporting two Persistence media - SQL Server2005 and Xml (In File system). Depending on the clients&amp;#8217; need, we will be using any one of them at the runtime, keeping in mind that in future client might use some other persistence media like Oracle , mySql or whatever.      &lt;br /&gt;      &lt;br /&gt;If you are not familiar with provider pattern , you would have solved this problem using any dependency injection container (e.g. Windsor/Spring.Net/Unity) , or introducing factory method to instantiate the desired component at the runtime; that is, either you had to introduce new code (write &amp;amp; manage) or new vocabulary to grasp( with dependency injection container) while providing your custom solution. Truly that would be an overhead if we would like to solve ONLY this problem. Then, why not use something from Framework when Framework is providing it (e.g. Asp.net Membership)?       &lt;br /&gt;      &lt;br /&gt;Here, I will show you how you can solve it using Provider Design Pattern and .Net Framework 2.0 very easily.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Provider design pattern consist of following basic parts &amp;#8211; &lt;/font&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;br /&gt;&lt;img src="http://www.dotnetscraps.com/samples/bullets/004.gif" align="middle" mce_src="http://www.dotnetscraps.com/samples/bullets/004.gif" /&gt;&amp;#160;&lt;font size="2"&gt;&lt;em&gt;API class&lt;/em&gt; (PersistenceManager) to publish API( save and get). It is also responsible to instantiate a concrete provider depending on the configuration.       &lt;br /&gt;      &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;img src="http://www.dotnetscraps.com/samples/bullets/004.gif" align="middle" mce_src="http://www.dotnetscraps.com/samples/bullets/004.gif" /&gt; Domain specific &lt;em&gt;Abstract Provider &lt;/em&gt;(PersistenceProviderBase) aka Application ProviderBase inherited from ProviderBase class of System.Configuration.Provider namespace.       &lt;br /&gt;      &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;img src="http://www.dotnetscraps.com/samples/bullets/004.gif" align="middle" mce_src="http://www.dotnetscraps.com/samples/bullets/004.gif" /&gt;&lt;em&gt; Concrete Providers &lt;/em&gt;(XmlPersistenceProvider and SqlPersistanceProvider) inherited from domain specific Abstract Provider.       &lt;br /&gt;      &lt;br /&gt;&lt;/font&gt;&lt;img src="http://www.dotnetscraps.com/samples/bullets/004.gif" align="middle" mce_src="http://www.dotnetscraps.com/samples/bullets/004.gif" /&gt;&lt;em&gt; Custom &lt;/em&gt;&lt;font size="2"&gt;&lt;em&gt;Configuration Section&lt;/em&gt; to configure the Providers and a class inherited from ConfigurationSection to represent it in .Net.&lt;/font&gt;&lt;/blockquote&gt;  &lt;p&gt;&lt;font size="2"&gt;The following diagram shows different parts of provider design pattern that I will clarify one by one &amp;#8211; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/providerpattern_2.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/providerpattern_2.jpg"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/a&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/providerpattern_2.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/providerpattern_2.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="285" alt="providerpattern" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/providerpattern_thumb.jpg" width="526" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/providerpattern_thumb.jpg" /&gt;&lt;/a&gt;&lt;/a&gt;&lt;/a&gt;&lt;font size="2"&gt;      &lt;br /&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Figure2 : Basic Parts of Provider Design Pattern&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Let's start with the last part, i.e. ,&amp;#160; Custom Configuration Section - &lt;/font&gt;&lt;/p&gt;  &lt;h5&gt;&lt;img src="http://www.dotnetscraps.com/samples/bullets/032.gif" align="middle" mce_src="http://www.dotnetscraps.com/samples/bullets/032.gif" /&gt;&amp;#160;&lt;u&gt;Custom Configuration Section &lt;/u&gt;&lt;/h5&gt;  &lt;p&gt;&lt;font size="2"&gt;In order to make the provider pattern pluggable and flexible, it is quite obvious that we need to implement a means by which we can configure the provider at the runtime. Application configuration is the most easy and convenient way to link the communication between our Providers and API.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;First we need to add a class inherited from ConfigurationSection to handle the configuration of the providers or we can implement :&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/ClassDiagram3_2.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/ClassDiagram3_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="260" alt="ClassDiagram3" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/ClassDiagram3_thumb.png" width="206" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/ClassDiagram3_thumb.png" /&gt;&lt;/a&gt;     &lt;br /&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Figure3 : Class to store Custom Configuration Section&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Following is the custom section for the Persistence Provider: &lt;/font&gt;&lt;/p&gt; &lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Listing1.1 : Custom Configuration Section:&lt;/font&gt;&lt;/strong&gt;   &lt;br /&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;   &amp;lt;PersistenceProvider defaultProvider=&lt;span style="color: #006080"&gt;&amp;quot;XmlPersistenceProvider&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &amp;lt;providers&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;       &amp;lt;add name=&lt;span style="color: #006080"&gt;&amp;quot;XmlPersistenceProvider&amp;quot;&lt;/span&gt; type=&lt;span style="color: #006080"&gt;&amp;quot;ProviderPattern.XmlPersistenceProvider, ProviderPattern&amp;quot;&lt;/span&gt; PersistenceMediaConnectionString=&lt;span style="color: #006080"&gt;&amp;quot;C:\PersistenceMedia\DocumentInfos.xml&amp;quot;&lt;/span&gt;/&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;       &amp;lt;add name=&lt;span style="color: #006080"&gt;&amp;quot;SqlPersistenceProvider&amp;quot;&lt;/span&gt; type=&lt;span style="color: #006080"&gt;&amp;quot;ProviderPattern.SqlPersistenceProvider, ProviderPattern&amp;quot;&lt;/span&gt; PersistenceMediaConnectionString=&lt;span style="color: #006080"&gt;&amp;quot;[Your database connection string]&amp;quot;&lt;/span&gt;/&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     &amp;lt;/providers&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;   &amp;lt;/PersistenceProvider&amp;gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;br /&gt;

&lt;p&gt;&lt;font face="vER" size="2"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="vER" size="2"&gt;Important attributes to note here:&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="vER" size="2"&gt;1. &lt;strong&gt;defaultProvider&lt;/strong&gt; : Refers to the default Concrete Provider.&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="vER" size="2"&gt;2. &lt;strong&gt;PersistenceMediaConnectionString&lt;/strong&gt; : Defined to provide extra information needed to the Concrete Provider. For example , XmlPersistenceProvider will save the information about the domain object in the path specified and SqlPersistenceProvider use the value specified as the connection string to the database. 

    &lt;br /&gt;

    &lt;br /&gt;We can also define as many other attributes as needed that can be used while initializing the concrete provider( e.g. logFilePath). Benefit is, we can come back to the configuration and change it at the runtime and Concrete Provider will be updated accordingly.&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;Now let's move on and explore the API class whose responsibility is to initialize the concrete provider depending on the configuration section and publish the API.&lt;/font&gt;&lt;/p&gt;

&lt;h5&gt;&lt;font face="vER"&gt;&lt;img src="http://www.dotnetscraps.com/samples/bullets/032.gif" align="middle" mce_src="http://www.dotnetscraps.com/samples/bullets/032.gif" /&gt;&lt;u&gt;&amp;#160;&lt;/u&gt;&lt;/font&gt;&lt;font face="vER"&gt;&lt;u&gt;API Class&lt;/u&gt;&lt;/font&gt;&lt;/h5&gt;

&lt;p&gt;&lt;font face="vER" size="2"&gt;API class is the major gateway to the concrete provider as I mentioned earlier that it communicates directly with the underlying persistence media using one of the concrete provider to perform the operation (e.g. Save/Get) that is exposes &amp;#8211; &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Listing2.1 : Save Method of API Class:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;        public static void &lt;/span&gt;Save&amp;lt;T&amp;gt;(T obj)
        {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(DefaultProvider == &lt;span style="color: blue"&gt;null&lt;/span&gt;)
            {
                Instantiate(&lt;br /&gt;                    &lt;span style="color: #2b91af"&gt;PersistenceProviderConfigSection&lt;/span&gt;.GetPersistenceConfigSection());
            }
            DefaultProvider.Save&amp;lt;T&amp;gt;(obj);
        }&lt;br /&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Listing2.2 : Get Method of API Class:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;        public static &lt;/span&gt;T Get&amp;lt;T&amp;gt;()
        {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(DefaultProvider == &lt;span style="color: blue"&gt;null&lt;/span&gt;)
            {
                Instantiate(&lt;span style="color: #2b91af"&gt;PersistenceProviderConfigSection&lt;/span&gt;.GetPersistenceConfigSection());
            }
            &lt;span style="color: blue"&gt;return &lt;/span&gt;DefaultProvider.Get&amp;lt;T&amp;gt;();
        }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;font face="vER" size="2"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="vER" size="2"&gt;If we look at the PersistenceManager closely, the static Instantiate method, that instantiate the provider based on the Configuration from PersistenceProviderConfigSection. In order to do that, we have a built in support in the .Net Framework2.0 , that is, we will use ProvidersHelper class of System.Web.Configuration namespace. The &lt;span style="color: #2b91af"&gt;ProvidersHelper&lt;/span&gt;.InstantiateProviders method initializes the&amp;#160; concrete providers by calling the Intialize() method of the Concrete Providers (I will come back to this point in the next section again).&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Listing2.3 : Instantiation of the Providers :&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p class="csharpcode"&gt;&lt;font face="vER" size="2"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;        private static void &lt;/span&gt;Instantiate(&lt;span style="color: #2b91af"&gt;PersistenceProviderConfigSection &lt;/span&gt;configSection)
        {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(Providers == &lt;span style="color: blue"&gt;null&lt;/span&gt;)
                SetupProvider(configSection);
        }

        &lt;span style="color: blue"&gt;private static void &lt;/span&gt;SetupProvider(&lt;span style="color: #2b91af"&gt;PersistenceProviderConfigSection &lt;/span&gt;config)
        {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(config == &lt;span style="color: blue"&gt;null&lt;/span&gt;)
                &lt;span style="color: blue"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;PersistenceProvider are not configured to be used with this application&amp;quot;&lt;/span&gt;);

            Providers = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PersistenceProviderCollection&lt;/span&gt;();
            &lt;span style="color: #2b91af"&gt;ProvidersHelper&lt;/span&gt;.InstantiateProviders(config.Providers, Providers, &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;PersistenceProviderBase&lt;/span&gt;));
            DefaultProvider = Providers[config.DefaultProvider] &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PersistenceProviderBase&lt;/span&gt;;
        }&lt;/pre&gt;

&lt;pre class="code"&gt;&amp;#160;&lt;/pre&gt;

&lt;p&gt;&lt;font face="Ta" size="2"&gt;Hence, the DefaultProvider property in the will always refers to the default Concrete provider mentioned in the configuration. &lt;/font&gt;&lt;font face="Ta" size="2"&gt;Now, we will dive into the details of the Concrete provider and how it gets initialized when we call ProvidersHelper.InstantiateProviders(config.Providers, Providers, typeof(PersistenceProviderBase)). &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Ta" size="2"&gt;Note: If you are thinking: why would we add a reference to System.Web.Configuration namespace if it is not a web application, then you are right ;) ? However, we can easily implement class we need to avoid adding reference - ProvidersHelper.( We will come back to this point later.)&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Ta" size="2"&gt;Now, let's move to the most important 2 parts of the Provider Design Pattern that is ( you already know isn't it :) ?) - Application speciProviderBase and Concrete Providers . &lt;/font&gt;&lt;/p&gt;

&lt;h5&gt;&lt;a class="" title="_Concrete_Provider_and" name="_Concrete_Provider_and"&gt;&lt;/a&gt;&lt;img src="http://www.dotnetscraps.com/samples/bullets/032.gif" align="middle" mce_src="http://www.dotnetscraps.com/samples/bullets/032.gif" /&gt; &lt;u&gt;Application ProviderBase and Concrete Providers&lt;/u&gt;&lt;/h5&gt;

&lt;p&gt;&lt;font size="2"&gt;In shortcut, Application ProviderBase class/ Domain specific Provider Base provides the abstract version of the functionality exposed by the API class and the responsibilities of the concrete provider is to implement those API in their own way. As we can see from Figure 4 our Application ProviderBase - PersistenceProviderBase implements IPersistenceProvider&lt;em&gt; &lt;/em&gt;which noting but describes the API exposed by our API class. 

    &lt;br /&gt;

    &lt;br /&gt;&lt;/font&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/ClassDiagram2_2.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/ClassDiagram2_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="297" alt="ClassDiagram2" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/ClassDiagram2_thumb.png" width="411" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/ClassDiagram2_thumb.png" /&gt;&lt;/a&gt; 

  &lt;br /&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Figure4 : Application ProviderBase class - PersistenceProviderBase&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;About the ProviderBase &lt;em&gt;-&lt;/em&gt; a class of the Net framework's System.Configuration.Provider namespace which have all the members to be implemented by the concrete providers.&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;It&lt;strong&gt;&amp;#160;&lt;/strong&gt;contains properties to describe the concrete providers &amp;#8211; &lt;em&gt;Name&lt;/em&gt; and &lt;em&gt;Description&lt;/em&gt;. &lt;em&gt;Initialize() &lt;/em&gt;is used to initializes the provider.PersistenceProviderBase is the mirror of the API or Services that will be performed by Concrete Provider. It is the place to implement the members generic to the all concrete provider.&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="+0"&gt;&lt;font size="2"&gt;Concrete Providers overrides with the concrete implementation(Save/Get of the User) of the abstract API provided in the PersistenceProviderBase class.&lt;/font&gt; &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/ClassDiagram4_2.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/ClassDiagram4_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="352" alt="ClassDiagram4" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/ClassDiagram4_thumb.png" width="410" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/ClassDiagram4_thumb.png" /&gt;&lt;/a&gt; 

  &lt;br /&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Figure5 : Concrete Providers and their members&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In addition to that, in the Initalize() method, concrete providers also initialize the properties that are related to the concrete providers and configured through web.config. For example, &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;_PersistenceMediaPath of the concrete providers will be initialized with the value of&lt;em&gt;PersistenceMediaConnectionString&lt;/em&gt; from web.config. &lt;/li&gt;

  &lt;li&gt;Name and Description will be initialized. 
    &lt;br /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Following is the code related to the Initialize of SqlPersistenceProvider : 
  &lt;br /&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;
      &lt;br /&gt;Listing3.1 : Initialize() of Concrete Provider:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Initialize(&lt;span class="kwrd"&gt;string&lt;/span&gt; name, NameValueCollection config)
{
    name = &lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(name) ? &lt;span class="str"&gt;&amp;quot;SqlPersistanceProvider&amp;quot;&lt;/span&gt; : name.Trim();
    &lt;span class="kwrd"&gt;base&lt;/span&gt;.Setup(&lt;span class="str"&gt;&amp;quot;SqlPersistanceProvider&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;SqlPersistanceProvider saves the T to SQL DB&amp;quot;&lt;/span&gt;, config);
    _PersistenceMediaPath = config[PersistenceMediaPathKeyName];
    
    &lt;span class="rem"&gt;//Call the base class to initialize&lt;/span&gt;
    &lt;span class="kwrd"&gt;base&lt;/span&gt;.Initialize(name, config);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;












.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;font size="+0"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;Following diagram shows the Call Stack how the Concrete Providers' Initialize() method get called from the API class when first time it initializes the Providers:&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/callstack_2.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/callstack_2.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="157" alt="callstack" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/callstack_thumb.jpg" width="507" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/callstack_thumb.jpg" /&gt;&lt;/a&gt; 

  &lt;br /&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Figure6 : Call Stack - How all the concrete providers get initialized from API class&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;After initialization, we are only left with the Provider-specific implementation of the abstract functionality of the PersistenceProviderBase - Save/Get. Every provider will implement in their own way. For example , if we consider XmlPersistenceProvider , it will implement the Save/Get as Listing 3.2 &amp;amp; 3.3, where as , SqlPersistenceProvider will store and retrieve it from Sql Server -&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Listing3.2 : XmlPersistenceProvider's Save method&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Save&amp;lt;T&amp;gt;(T obj)
{
    &lt;span class="kwrd"&gt;string&lt;/span&gt; serailzedObj = SerializeHelper.Serialize(obj);
    File.WriteAllText(_PersistenceMediaPath, serailzedObj);
}&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Listing3.3 : XmlPersistenceProvider's Get method&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;font size="2"&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; T Get&amp;lt;T&amp;gt;()
{
    &lt;span class="kwrd"&gt;string&lt;/span&gt; stringContent = File.ReadAllText(_PersistenceMediaPath);
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (!String.IsNullOrEmpty(stringContent))
        &lt;span class="kwrd"&gt;return&lt;/span&gt; ((T)SerializeHelper.Deserialize(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(T), stringContent));
    &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;default&lt;/span&gt;(T);
}&lt;/pre&gt;
&lt;/font&gt;

&lt;p&gt;&lt;font size="2"&gt;Hence , we are done with implementation of the Provider Design Pattern. In the next section, we will look into some benefits that we will achieve by leveraging this Pattern.&lt;/font&gt;&lt;/p&gt;

&lt;h5&gt;&lt;a class="" title="_Advantage_of" name="_Advantage_of"&gt;&lt;/a&gt;3. Advantages of Provider Design Pattern&lt;/h5&gt;

&lt;p&gt;Here comes, moment of truth. Why would you implement Provider Design Pattern - to create loosely coupled components that are extensible from an application perspective.&lt;/p&gt;

&lt;p&gt;If we go back to Listing1.1 where we defined our custom configuration section, we set XmlPersistenceProvider as the default PersistenceProvider. Now, due to any reason, client of our API wants to use SqlPersistenceProvider that we provided with our API. What needs to be done , just change in the value of the defaultProvider in the web.config file and our client can start using the SqlPersistenceProvider. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Listing4.1 : Configuration Section with defaultProvider = SqlPersistenceProvider&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &amp;lt;PersistenceProvider defaultProvider=&lt;span style="color: #006080"&gt;&amp;quot;SqlPersistenceProvider&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;    &amp;lt;providers&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;      &amp;lt;add name=&lt;span style="color: #006080"&gt;&amp;quot;XmlPersistenceProvider&amp;quot;&lt;/span&gt; type=&lt;span style="color: #006080"&gt;&amp;quot;ProviderPattern.XmlPersistenceProvider, ProviderPattern&amp;quot;&lt;/span&gt; PersistenceMediaConnectionString=&lt;span style="color: #006080"&gt;&amp;quot;C:\PersistenceMedia\DocumentInfos.xml&amp;quot;&lt;/span&gt;/&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;      &amp;lt;add name=&lt;span style="color: #006080"&gt;&amp;quot;SqlPersistenceProvider&amp;quot;&lt;/span&gt; type=&lt;span style="color: #006080"&gt;&amp;quot;ProviderPattern.SqlPersistenceProvider, ProviderPattern&amp;quot;&lt;/span&gt; PersistenceMediaConnectionString=&lt;span style="color: #006080"&gt;&amp;quot;[Your database connection string]&amp;quot;&lt;/span&gt;/&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;    &amp;lt;/providers&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;  &amp;lt;/PersistenceProvider&amp;gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Now, due to some reason, our Client wants to develop provider based on , let's say, MySql. That is also pretty simple. They just need to create a Concrete Provider, MySqlPersistenceProvider inheriting from Application ProviderBase(Figure7) and implementing the APIs&amp;#160; by overrriding. In addition, They need to add a &amp;lt;add name = &amp;quot;MySqlPersistenceProvider&amp;quot; ... in the Custom Configuration Section, and they are done. :) Isn't it simple ? :)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/Extension_Of_Provider%20Pattern_2.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/Extension_Of_Provider%20Pattern_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="199" alt="Extension_Of_Provider Pattern" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/Extension_Of_Provider%20Pattern_thumb.png" width="421" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/testabc_F40F/Extension_Of_Provider%20Pattern_thumb.png" /&gt;&lt;/a&gt; 

  &lt;br /&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Figure7 : Extending PersistenceProviders&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;font color="#0000ff" size="1"&gt;Listing 4.2 : Configuration Section with MySqlPersistenceProvider&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &amp;lt;PersistenceProvider defaultProvider=&lt;span style="color: #006080"&gt;&amp;quot;MySqlPersistenceProvider&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;   &amp;lt;providers&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &amp;lt;add name=&lt;span style="color: #006080"&gt;&amp;quot;XmlPersistenceProvider&amp;quot;&lt;/span&gt; type=&lt;span style="color: #006080"&gt;&amp;quot;ProviderPattern.XmlPersistenceProvider, ProviderPattern&amp;quot;&lt;/span&gt; PersistenceMediaConnectionString=&lt;span style="color: #006080"&gt;&amp;quot;C:\PersistenceMedia\DocumentInfos.xml&amp;quot;&lt;/span&gt;/&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     &amp;lt;add name=&lt;span style="color: #006080"&gt;&amp;quot;SqlPersistenceProvider&amp;quot;&lt;/span&gt; type=&lt;span style="color: #006080"&gt;&amp;quot;ProviderPattern.SqlPersistenceProvider, ProviderPattern&amp;quot;&lt;/span&gt; PersistenceMediaConnectionString=&lt;span style="color: #006080"&gt;&amp;quot;[Your database connection string]&amp;quot;&lt;/span&gt;/&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;     &amp;lt;add name=&lt;span style="color: #006080"&gt;&amp;quot;MySqlPersistenceProvider&amp;quot;&lt;/span&gt; type=&lt;span style="color: #006080"&gt;&amp;quot;ProviderPatternExplored.MySqlPersistenceProvider, ProviderPatternExplored&amp;quot;&lt;/span&gt; PersistenceMediaConnectionString=&lt;span style="color: #006080"&gt;&amp;quot;[Your my sql database connection string]&amp;quot;&lt;/span&gt;/&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;   &amp;lt;/providers&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt; &amp;lt;/PersistenceProvider&amp;gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Using the same process, they can implement any PersistenceProvider they need. Moreover, in future, if we want to add any new Providers, it's just a piece of cake ;). That's make our component very extensible conforming to the Open-Close Principle of OOP.&lt;/p&gt;

&lt;p&gt;Last but not the least; these loosely coupled and extensible components results in a less code&amp;#160; to manage and less vocabulary to maintain, since framework is providing the basis for the Provider Design Pattern. Moreover, it gives your team members a familiarity with the existing built-in Providers in .Net Framework.&lt;/p&gt;

&lt;h5&gt;&lt;a class="" title="_4._Last_few" name="_4._Last_few"&gt;&lt;/a&gt;&lt;font face="vER"&gt;4. Last few words&amp;#8230;&lt;/font&gt;&lt;/h5&gt;

&lt;p&gt;&lt;font face="vER" size="2"&gt;In this example, we saw how we can leverage .Net Provider Design Pattern to make a component loosely couple and extensible.&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="vER" size="2"&gt;As I mentioned earlier also, one of the catch implementing provider pattern is that, we have to use ProvidersHelper class of System.Web,Configuration while building the component. But we can easily get rid of adding reference to System.Web namespace, by implementing ProvidersHelper class very easily. (I will try to cover it in one of my next post.) &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="vER" size="2"&gt;I tried to clarify the implementation details of Provider pattern in this article , however, still if there are any questions regarding this article, please feel free to ask me. I would really appreciate your feedback. &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 26px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-372a00c90846fea1.skydrive.live.com/embedrow.aspx/CodeDownload/ProviderPatternExplored.rar" frameborder="0" scrolling="no" mce_src="http://cid-372a00c90846fea1.skydrive.live.com/embedrow.aspx/CodeDownload/ProviderPatternExplored.rar"&gt;&lt;/iframe&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6704951" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AdilAkhtersWeblogs/~4/6DaYM2QtdK0" height="1" width="1"/&gt;</description><feedburner:origLink>http://weblogs.asp.net/adilakhter/archive/2008/11/02/ProviderDesignPattern.aspx</feedburner:origLink></item><item><title>More on Unit Testing : TestContext</title><link>http://feedproxy.google.com/~r/AdilAkhtersWeblogs/~3/hdmMmNT-DJk/more-on-unit-testing-testcontext.aspx</link><pubDate>Sun, 04 May 2008 10:24:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6156455</guid><dc:creator>Adil Akhter</dc:creator><slash:comments>7</slash:comments><wfw:commentRss>http://weblogs.asp.net/adilakhter/rsscomments.aspx?PostID=6156455</wfw:commentRss><wfw:comment>http://weblogs.asp.net/adilakhter/commentapi.aspx?PostID=6156455</wfw:comment><comments>http://weblogs.asp.net/adilakhter/archive/2008/05/04/more-on-unit-testing-testcontext.aspx#comments</comments><description>&lt;p&gt;&lt;font size="+0"&gt;&lt;font size="+0"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;&lt;font face="Arial"&gt;&lt;font size="5"&gt;I&lt;/font&gt;n Test Driven Development&amp;#160; as a developer we spend significant amount of time in writing unit tests. As improving coding coverage, testing all the boundary condition and ensuring the of quality code is significantly important, writing unit test effectively become one of the priority that we has to consider in software development. &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="+0"&gt;&lt;font size="+0"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font face="Arial" size="2"&gt;In our today's discussion, we will see what is TestContext of VSTS unit testing framework and how we can use TestContext&amp;#160; to leverage writing effective unit tests for our application.            &lt;br /&gt;            &lt;br /&gt;Prior to move forward with our today's Discussion on TestContext, I would really suggest you the following postings- &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;font size="+0"&gt;&lt;font size="+0"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;&lt;a href="http://weblogs.asp.net/adilakhter/archive/2008/04/18/why-unit-testing-is-so-important.aspx" target="_blank" mce_href="http://weblogs.asp.net/adilakhter/archive/2008/04/18/why-unit-testing-is-so-important.aspx"&gt;&lt;font face="Arial" color="#000000"&gt;Why unit testing is so important?&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt; &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;     &lt;p&gt;&lt;font size="2"&gt;&lt;a href="http://weblogs.asp.net/adilakhter/archive/2008/04/18/tdd-in-a-nutshell.aspx" target="_blank" mce_href="http://weblogs.asp.net/adilakhter/archive/2008/04/18/tdd-in-a-nutshell.aspx"&gt;&lt;font face="Arial" color="#000000"&gt;Test Driven Development in a Nutshell.&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;font face="Arial"&gt;So, let's begin with a brief description on what is TestContext. Then we will go through different scenarios where we can use TestContext. :)&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial" size="2"&gt;&lt;span style="color: #2b91af"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#000000"&gt;&lt;font face="Arial" color="#000000" size="2"&gt;&lt;span style="color: #2b91af"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;h4&gt;&lt;strong&gt;&lt;font face="Arial"&gt;What is TestContext?&lt;/font&gt;&lt;/strong&gt;&lt;/h4&gt;  &lt;p&gt;&lt;font color="#000000"&gt;&lt;font size="2"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #2b91af"&gt;TestContext &lt;/span&gt;is a abstract class of Microsoft.VisualStudio.TestTools.UnitTesting namespace that provides various information about the current test run. Purposes that has been served by TestContext Class - &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial" size="2"&gt;1.&amp;#160; To store information and provide information to the unit tests during Unit Test Run.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial" size="2"&gt;2.&amp;#160; Provide a mechanism to measure performance of your code being tested by the Unit Test.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial" size="2"&gt;3.&amp;#160; In &lt;/font&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms243399(VS.80).aspx" target="_blank" mce_href="http://msdn2.microsoft.com/en-us/library/ms243399(VS.80).aspx"&gt;&lt;font face="Arial" color="#000000" size="2"&gt;Testing the web service&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial" size="2"&gt; it stores the additional information, like server's URL.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial" size="2"&gt;4.&amp;#160; In &lt;/font&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms404696(VS.80).aspx" target="_blank" mce_href="http://msdn2.microsoft.com/en-us/library/ms404696(VS.80).aspx"&gt;&lt;font face="Arial" color="#000000" size="2"&gt;Asp.Net unit tests&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial" size="2"&gt;, it get holds of the Page object.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial" size="2"&gt;5.&amp;#160; For &lt;/font&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms404708(VS.80).aspx" target="_blank" mce_href="http://msdn2.microsoft.com/en-us/library/ms404708(VS.80).aspx"&gt;&lt;font face="Arial" color="#000000" size="2"&gt;Data Driven Unit Tests&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial" size="2"&gt; , it provides access to the data rows.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Arial"&gt;The class definition of the TestContext Class -&lt;/font&gt;&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 88.48%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; height: 210px; background-color: #f4f4f4"&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; TestContext&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;    {&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; AspNetDevelopmentServerPrefix = &lt;span style="color: #006080"&gt;&amp;quot;AspNetDevelopmentServer.&amp;quot;&lt;/span&gt;;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; TestContext();&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; UnitTestOutcome CurrentTestOutcome { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; DbConnection DataConnection { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; DataRow DataRow { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; IDictionary Properties { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; System.Web.UI.Page RequestedPage { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; TestDeploymentDir { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; TestDir { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; TestLogsDir { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; TestName { get; }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;&amp;#160; &lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; AddResultFile(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; fileName);&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; BeginTimer(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; timerName);&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; EndTimer(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; timerName);&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;        &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; WriteLine(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; format, &lt;span style="color: #0000ff"&gt;params&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;[] args);&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font color="#000000"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt;    }&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;font face="Arial"&gt;To start with the TestContext , &lt;font color="#000000"&gt;we need to add a property in our Unit Test class as -&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/ClassDiagram1_4.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/ClassDiagram1_4.jpg"&gt;&lt;font face="Arial"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="304" alt="ClassDiagram1" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/ClassDiagram1_thumb_1.jpg" width="402" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/ClassDiagram1_thumb_1.jpg" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt;&amp;#160;&amp;#160; &lt;br /&gt;&lt;/font&gt;&lt;font face="Arial"&gt;&lt;font size="2"&gt;&lt;font size="+0"&gt;&lt;font size="+0"&gt;&lt;span style="font-size: 9pt"&gt;&lt;strong&gt;Figure1: TestContext Property in Unit Test class&lt;/strong&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;font face="Arial" size="2"&gt;Now if we just add a simple test and debug it - we will find that the VSTS Unit Testing Framework actually using an instance of&amp;#160; &lt;strong&gt;UnitTestAdapterContext&lt;/strong&gt; which is derived from TestContext. This property TestContext is automatically initialized/assigned by the test run engine of VSTS when the Unit Test class is initialized after [ClassInitalize] method and before [TestInitalize] method.&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image1.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image1.png"&gt;&lt;font face="Arial" color="#000000"&gt;&lt;/font&gt;&lt;/a&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image1.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image1.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="319" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image1_thumb.png" width="560" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image1_thumb.png" /&gt;&lt;/a&gt;&lt;/a&gt;&lt;/a&gt;&lt;font face="Arial"&gt;&amp;#160; &lt;/font&gt;&lt;font size="2"&gt;&lt;font size="+0"&gt;&lt;font face="Arial" size="+0"&gt;&lt;span style="font-size: 9pt"&gt;&lt;strong&gt;Figure2 : UnitTestAdapterContext and its' properties in Debug Mode &lt;/strong&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;font size="+0"&gt;&lt;font face="Arial" size="+0"&gt;&lt;span style="font-size: 9pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Arial"&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Arial"&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;&lt;strong&gt;Want to know more about TestContext?&lt;/strong&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;

&lt;p&gt;&lt;font face="Arial"&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;It would be really hard to find the assembly&amp;#160; that contains UnitTestAdapterContext Class unless we search the private assemblies installed in &amp;lt;vs installation directory&amp;gt;\common7\IDE\PrivateAssemblies ; in my case which is &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;- C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies.The assembly that contains UnitTestAppterContextClass -&lt;em&gt;Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter.dll&lt;/em&gt;. &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Arial"&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;UnitTestAdapterContext class looks like following in reflector -&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_4.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_4.png"&gt;&lt;font face="Arial"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="554" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_thumb.png" width="485" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_thumb.png" /&gt;&lt;/font&gt;&lt;/a&gt; 

  &lt;br /&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure3 : UnitTestAdapterContext in Reflector&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;strong&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;&lt;strong&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/h4&gt;

&lt;h4&gt;&lt;strong&gt;&lt;font face="Arial"&gt;How can we use TestContext ?&lt;/font&gt;&lt;/strong&gt;&lt;/h4&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;Like I mentioned in the beginning , we can use TestContext in different cases writing unit tests. Now , we are going to look at some features of TestContext class that we can use very easily in our unit tests.&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;Scenario 1 : &lt;/strong&gt;&lt;u&gt;Getting path of the folder that current test run created for storing input and outputs &lt;/u&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;u&gt;&lt;/u&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;It's a really handy feature of TestContext. It provides you the path of the unique folder for current test run that VSTS unit testing framework creates in every test run. &lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;font size="2"&gt;In VSTS unit testing framework, every test run create a unique folder in&amp;#160; machine where it's running the test and generate a xml based test report ( *.trx) -&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_6.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_6.png"&gt;&lt;font face="Arial"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="169" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_thumb_2.png" width="244" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_thumb_2.png" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt; &lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 4 : Folders/Directories that are created by Test Run 
      &lt;br /&gt;

      &lt;br /&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;Additional input or output of unit test can be stored in this folder and also can be cleaned up before exiting the unit test(if required). Furthermore, it's the safest place to put the additional stuff related to unit tests because our application have full access to this folder ( just consider the situation where unit tests are running in a Build Machine or in a remote server where application might not have access to &amp;quot;C:\Temp\&amp;quot; folder :) ). &lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font size="2"&gt;&lt;span style="font-size: 9pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;So, how can we get the path of the folder of current test run? Simple - &lt;/font&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;font face="Arial"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; testDirectory = TestContext.TestDir;&lt;/font&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;








.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;We can get access to the deployment folder&amp;#160; and the folder that contain logs&amp;#160; as well -&lt;/font&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;font face="Arial"&gt;&lt;span style="color: blue"&gt;string &lt;/span&gt;deploymentDirectory = TestContext.TestDeploymentDir;
&lt;span style="color: blue"&gt;string &lt;/span&gt;logDirectory = TestContext.TestLogsDir;&lt;/font&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;Scenario 2 : &lt;/strong&gt;&lt;u&gt;Generating report how much time was elapsed to complete the Unit Tests&lt;/u&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;u&gt;&lt;/u&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;/em&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;TestContext Class has 2 public member &lt;strong&gt;BeginTimer&lt;/strong&gt; and &lt;strong&gt;EndTimer&lt;/strong&gt; which takes a string parameter as argument ( Name of the timer). Using this feature of TestContext class, how much time elapsed to run particular unit test can be measured very easily. This feature of TestContext might be useful in tracking how much time the code to be tested is consuming and whether or not it's going to meet speed criteria of nonfunctional requirements. &lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;








.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre class="alt"&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;TestContext.BeginTimer(&lt;span class="str"&gt;&amp;quot;longRunningProcess&amp;quot;&lt;/span&gt;);&lt;/font&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&amp;#160;&lt;/font&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;&lt;span class="rem"&gt;// Call the long running method here to test whether it meet the performance requirement&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;&lt;span class="rem"&gt;//....&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&lt;span class="rem"&gt;//&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;&amp;#160;&lt;/font&gt;&lt;/pre&gt;

  &lt;pre class="alt"&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;TestContext.EndTimer(&lt;span class="str"&gt;&amp;quot;longRunningProcess&amp;quot;&lt;/span&gt;);&lt;/font&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;font face="Arial"&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;          &lt;/font&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;font face="Arial"&gt;Result of the timer is shown as - &lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_8.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_8.png"&gt;&lt;font face="Arial"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="236" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_thumb_3.png" width="348" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/image_thumb_3.png" /&gt;&lt;/font&gt;&lt;/a&gt; 

  &lt;br /&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 5: Output from the Timer &lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;Scenario 3 : &lt;/strong&gt;&lt;u&gt;Adding additional information in Test Result&lt;/u&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;There is another cool property in the TestContext class which gives you flexibility to provide additional information in Test Result which will be stored in Test Result file( .trx extension stored as Xml). This could be really useful to provide additional information about the Test such as Test Environment, parameter and other details that might be important to store with test result. Lets consider a particular unit test - &lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;div&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; [TestMethod]&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ShouldCreateUser()&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; {&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     &lt;span style="color: #008000"&gt;// ... Unit Test Codes....&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; }&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt; [TestCleanup]&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; TestCleanup()&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt; {&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     TestContext.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;{0} : {1}&amp;quot;&lt;/span&gt;, TestContext.TestName ,TestContext.CurrentTestOutcome);&lt;/font&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;font face="Arial"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt; }&lt;/font&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;Using &lt;strong&gt;TestContext.WriteLine&lt;/strong&gt; , we can provide additional information [ For Example - just to show, in the above example at line 10 , we are writing the test name and test result] and that is visible to the test result viewer as -&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/testoutput.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/testoutput.jpg"&gt;&lt;font face="Arial"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="204" alt="testoutput" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/testoutput_thumb.jpg" width="320" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/testoutput_thumb.jpg" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt; &lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 6: Output from TestContext.WriteLine 
      &lt;br /&gt;

      &lt;br /&gt;

      &lt;br /&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;Scenario 4 : &lt;/strong&gt;&lt;u&gt;TestContext in Asp.Net Unit Testing&lt;/u&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;TestContext provides the access to the Asp.net Page object representing the current web request while unit testing Asp.net Web Application. How? TestContext has a property - RequestPage which is actually an instance of System.Web.UI.Page object and defined as- &lt;/font&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&amp;quot;...references the &lt;b&gt;Page&lt;/b&gt; object created by the URL used to invoke the test&amp;quot;&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TestContextInAspnet.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TestContextInAspnet.jpg"&gt;&lt;font face="Arial"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="251" alt="TestContextInAspnet" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TestContextInAspnet_thumb.jpg" width="482" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TestContextInAspnet_thumb.jpg" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;font face="Arial"&gt; &lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 7: TestContext.RequestPage 
      &lt;br /&gt;

      &lt;br /&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;This property is only valid for Asp.Net Unit Testing. After getting hold of Page Object of current web request, any control of the page can be accessed using &lt;a href="http://msdn.microsoft.com/en-us/library/486wc64h.aspx" target="_blank" mce_href="http://msdn.microsoft.com/en-us/library/486wc64h.aspx"&gt;FindControl&lt;/a&gt; method of the Page Object. Using &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.privateobject(VS.80).aspx" target="_blank" mce_href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.privateobject(VS.80).aspx"&gt;PrivateObject&lt;/a&gt; class, we can invoke the private/protected methods of the current .Aspx page represented by Page Object.&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;
    &lt;br /&gt;Example of an Asp.net Unit Test :&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; [TestMethod]&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; [HostType(&lt;span style="color: #006080"&gt;&amp;quot;Asp.Net&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; [UrlToTest(&lt;span style="color: #006080"&gt;&amp;quot;http://localhost/ourwebapplication&amp;quot;&lt;/span&gt;)]&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; TestMethod()&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     Page page = TestContext.RequestedPage;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;     PrivateObject privateObject = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; PrivateObject(page);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;     &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     Button button = (Button)page.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;Button1&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;     privateObject.Invoke(&lt;span style="color: #006080"&gt;&amp;quot;Button1_Click&amp;quot;&lt;/span&gt;, button, EventArgs.Empty);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;     Label label = (Label)page.FindControl(&lt;span style="color: #006080"&gt;&amp;quot;Label1&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;     Assert.AreEqual&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;(&lt;span style="color: #006080"&gt;&amp;quot;Hello World !!!!&amp;quot;&lt;/span&gt;, label.Text);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;
&lt;font face="Arial"&gt;
  &lt;p class="Tahoma10" style="margin: 0px"&gt;
    &lt;br /&gt;We have a label and button in our an .aspx web page. When a button click event occurs, the label text get changed to &amp;quot;Hello world !!!&amp;quot;. And another important things to note that we are using IIS to host our web application(line 3).Now, we are going to test this feature using Asp.Net Unit Test in the sample code above. 

    &lt;br /&gt;&lt;/p&gt;

  &lt;p class="Tahoma10" style="margin: 0px" mce_keep="true"&gt;&amp;#160;&lt;/p&gt;
&lt;/font&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;So, first we get hold of our Page object(Line 6) representing our current web request(UrlToTest in Line 3) through the TestContext.RequestPage which eventually enable us to access any control of the page object(e.g. Line 10 &amp;amp; 13). Using the PrivateObject( line 8), we could conveniently invoke any member of the page class as well (line 11). 
    &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;Hence, using TestContext, we can effective &lt;em&gt;leverage&lt;/em&gt; our codes inside Aspx page into Test5 Coverage.&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;
        &lt;br /&gt;Scenario 5: &lt;/strong&gt;&lt;u&gt;TestContext in Data Driven Unit Tests 
        &lt;br /&gt;

        &lt;br /&gt;&lt;/u&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;In Data Driven Unit Test, TestContext provides access to the current DataRow for which test is running and by that way, it provides access to every DataRow of the DataSource one by one. 
    &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;In the following example, we will see how the TestContext enable us to getting access to every DataRow in the DataSource - 
    &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;First, lets define our Table that contains few UserContacts with valid information. So, our unit test should create every one as a UserContact of our Application. But that's not our example's goal here. In this example , We will see how TestContext enables us to access every UserContact stored in the UserContact Table so easily.&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableDefinition.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableDefinition.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="177" alt="TableDefinition" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableDefinition_thumb.jpg" width="404" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableDefinition_thumb.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 7: UserContact Table Definition&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;Let's put some Valid User Contact Information in our Table - UserContact -&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableData.jpg" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableData.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="120" alt="TableData" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableData_thumb.jpg" width="547" border="0" mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TestContextmoreonVSTSunittesting_F4EB/TableData_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;strong&gt;Figure 7: Data in UserContact Table 
      &lt;br /&gt;

      &lt;br /&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;After that, let's write our unit test -&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; [DataSource(&lt;span style="color: #006080"&gt;&amp;quot;System.Data.SqlClient&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;[path to MDF]\&amp;quot;;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; Integrated Security=True;User Instance=True&amp;quot;&lt;/span&gt;, &lt;span style="color: #006080"&gt;&amp;quot;UserContact&amp;quot;&lt;/span&gt;, &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; DataAccessMethod.Sequential), TestMethod()]&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ShouldCreateUsers()&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; { &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userLoginName = (TestContext.DataRow[&lt;span style="color: #006080"&gt;&amp;quot;LoginName&amp;quot;&lt;/span&gt;].ToString());&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userFirstName = (TestContext.DataRow[&lt;span style="color: #006080"&gt;&amp;quot;FirstName&amp;quot;&lt;/span&gt;].ToString());&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userLastName = (TestContext.DataRow[&lt;span style="color: #006080"&gt;&amp;quot;LastName&amp;quot;&lt;/span&gt;].ToString());&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userEmailAddress = (TestContext.DataRow[&lt;span style="color: #006080"&gt;&amp;quot;EmailAddress&amp;quot;&lt;/span&gt;].ToString());&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; userDepartment = (TestContext.DataRow[&lt;span style="color: #006080"&gt;&amp;quot;Department&amp;quot;&lt;/span&gt;].ToString());&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;     TestContext.WriteLine(&lt;span style="color: #006080"&gt;&amp;quot;Creating user - Login Name :{0} Name : {1} {2} &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;                           EmailAddress : {3} &amp;quot;&lt;/span&gt;, userLoginName, userFirstName, &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;                           userLastName, userEmailAddress);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; successful = UserManger.CreateUser(userLoginName, &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt;                                           userFirstName, userLastName, &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  18:&lt;/span&gt;                                           userEmailAddress, userDepartment);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  19:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  20:&lt;/span&gt;     Assert.IsTrue(successful);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  21:&lt;/span&gt; }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/div&gt;

&lt;div&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/div&gt;

&lt;div&gt;&lt;font face="Arial"&gt;From the above example, we can see that (line 5&amp;#160; - 10 ) , TestContext is providing us access to the current DataRow for which the unit test is getting executed. We can see the output of TestContext.Writeline(line 12) and Result of the unit test for each DataRow below -&lt;/font&gt;&lt;/div&gt;

&lt;div&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/div&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;em&gt;&lt;strong&gt;Scenario 6: &lt;/strong&gt;&lt;u&gt;TestContext.AddResultFile&lt;/u&gt;&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;Last but not the least, TestContext has another useful member called AddResultFile which is defined as - &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;void &lt;/span&gt;AddResultFile(&lt;span style="color: blue"&gt;string &lt;/span&gt;filename)&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;Through TestContext.AddResulFile, additional files can be added with the test result. The additional file will be stored in the unique folder created for current test run.This might be useful in some cases, for example, if we are validating our objects with some external resource, like schema - we can store the schema with our test result so that we can validate our test result later on after test run. &lt;/p&gt;

&lt;h4&gt;Conclusion&lt;/h4&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;Hence, we can utilize the TestContext class in several cases to solve our problem in writing unit tests. But saying all this, I would like to emphasize on designing test cases and map it to a unit test carefully because &amp;quot;&lt;em&gt;Harnessing the power that is provided by the tool and utilizing it &lt;strong&gt;effectively&lt;/strong&gt; and every possible way&lt;/em&gt;&amp;quot; could only bring desirable result .&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font size="2"&gt;In our today's discussion, we went through several scenarios where we can leverage TestContext to write a better and precisely more effective unit test using the Unit Testing Framework provided with Visual Studio. Thanks for being with me so far and I would really appreciate comments or any suggestion. 
    &lt;br /&gt;&lt;/font&gt;&lt;font face="Arial"&gt;
    &lt;br /&gt;I would really appreciate any comments or suggestion on this topic. &lt;/font&gt;&lt;font face="Arial"&gt;&amp;#160;&lt;/font&gt;&lt;/p&gt;

&lt;p class="Tahoma10" style="margin: 0px"&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fadilakhter%2farchive%2f2008%2f05%2f04%2fmore-on-unit-testing-testcontext.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fadilakhter%2farchive%2f2008%2f05%2f04%2fmore-on-unit-testing-testcontext.aspx" border="0" /&gt;&lt;/a&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6156455" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AdilAkhtersWeblogs/~4/hdmMmNT-DJk" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/adilakhter/archive/tags/TDD/default.aspx">TDD</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/TestContext/default.aspx">TestContext</category><feedburner:origLink>http://weblogs.asp.net/adilakhter/archive/2008/05/04/more-on-unit-testing-testcontext.aspx</feedburner:origLink></item><item><title>Passing Parameter to a Predicate in .Net2.0</title><link>http://feedproxy.google.com/~r/AdilAkhtersWeblogs/~3/2lXXMJjWKNA/passing-parameter-to-a-predicate-in-net2-0.aspx</link><pubDate>Fri, 18 Apr 2008 14:34:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6110074</guid><dc:creator>Adil Akhter</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://weblogs.asp.net/adilakhter/rsscomments.aspx?PostID=6110074</wfw:commentRss><wfw:comment>http://weblogs.asp.net/adilakhter/commentapi.aspx?PostID=6110074</wfw:comment><comments>http://weblogs.asp.net/adilakhter/archive/2008/04/18/passing-parameter-to-a-predicate-in-net2-0.aspx#comments</comments><description>&lt;P&gt;In this post, we will see how to pass parameter to a method representing Predicate.&lt;/P&gt;
&lt;P&gt;Let's say, we have a collection of SprintBacklogItem and we want to filter all the SprintBacklogItem with Title start's with, let say "QA" or "Dev Task" depending on a input parameter. Now from &lt;A href="http://weblogs.asp.net/adilakhter/archive/2008/04/16/using-predicate-amp-action-of-net2-0.aspx" target=_blank mce_href="http://weblogs.asp.net/adilakhter/archive/2008/04/16/using-predicate-amp-action-of-net2-0.aspx"&gt;the previous post&lt;/A&gt; we know that , predicate only have 1 parameter of type T.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://adilakhter.files.wordpress.com/2008/01/image1.png" mce_href="http://adilakhter.files.wordpress.com/2008/01/image1.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; WIDTH: 151px; HEIGHT: 216px; BORDER-RIGHT-WIDTH: 0px" height=239 alt=image src="http://adilakhter.files.wordpress.com/2008/01/image-thumb1.png" width=194 border=0 mce_src="http://adilakhter.files.wordpress.com/2008/01/image-thumb1.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Then, how to pass a input parameter _HeaderToSearch in Predicate?&lt;/P&gt;
&lt;P&gt;1. To do that, we need to a new object called ListMatcher -&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ListMatcher 
   &lt;/SPAN&gt;{ 
       &lt;SPAN style="COLOR: blue"&gt;private string &lt;/SPAN&gt;_HeaderToSearch; 
       &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;ListMatcher(&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;headerToSearch) 
       { 
           _HeaderToSearch = headerToSearch; 
       }  

       &lt;SPAN style="COLOR: blue"&gt;public bool &lt;/SPAN&gt;Predicate(&lt;SPAN style="COLOR: #2b91af"&gt;SprintBacklogItem &lt;/SPAN&gt;item) 
       { 
           &lt;SPAN style="COLOR: blue"&gt;return &lt;/SPAN&gt;item.Title.StartsWith(_HeaderToSearch, &lt;SPAN style="COLOR: #2b91af"&gt;StringComparison&lt;/SPAN&gt;.InvariantCultureIgnoreCase); 
       }  

   }&amp;nbsp; &lt;/PRE&gt;
&lt;P&gt;&lt;BR&gt;2. Next , I initialized the ListMatcher object and use the HeaderToSearch&amp;nbsp; to filter the items- &lt;BR&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ListMatcher &lt;/SPAN&gt;matcher = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ListMatcher&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"QA"&lt;/SPAN&gt;); 
&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.FindAll(matcher.Predicate);&lt;/PRE&gt;
&lt;P&gt;&lt;BR&gt;Done.:)&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6110074" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AdilAkhtersWeblogs/~4/2lXXMJjWKNA" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/adilakhter/archive/tags/.Net2.0/default.aspx">.Net2.0</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/C_2300_/default.aspx">C#</category><feedburner:origLink>http://weblogs.asp.net/adilakhter/archive/2008/04/18/passing-parameter-to-a-predicate-in-net2-0.aspx</feedburner:origLink></item><item><title>TDD - In a Nutshell</title><link>http://feedproxy.google.com/~r/AdilAkhtersWeblogs/~3/qq9dNT1UjnE/tdd-in-a-nutshell.aspx</link><pubDate>Fri, 18 Apr 2008 12:58:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6109875</guid><dc:creator>Adil Akhter</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://weblogs.asp.net/adilakhter/rsscomments.aspx?PostID=6109875</wfw:commentRss><wfw:comment>http://weblogs.asp.net/adilakhter/commentapi.aspx?PostID=6109875</wfw:comment><comments>http://weblogs.asp.net/adilakhter/archive/2008/04/18/tdd-in-a-nutshell.aspx#comments</comments><description>&lt;BLOCKQUOTE&gt;
&lt;H5&gt;"One Picture's&amp;nbsp; Worth Thousands Words"&lt;/H5&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;A href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TDDInaNutshell_D277/image_2.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TDDInaNutshell_D277/image_2.png"&gt;&lt;IMG style="WIDTH: 191px; HEIGHT: 369px" height=653 alt=image src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TDDInaNutshell_D277/image_thumb.png" width=375 mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/TDDInaNutshell_D277/image_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT face="Times New Roman" size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;Benefits( from my personal experience): &lt;BR&gt;&lt;o:p&gt;&lt;/o:p&gt;1. Development can be done much quicker. You already jot down all the test cases before writing codes. By that way, you are giving much time in thinking how to solve problem. Codes become much more standard and organized because of the brainstorming.&lt;BR&gt;&lt;o:p&gt;&lt;/o:p&gt;2. Quality of code is far better and deterministic.&lt;BR&gt;&lt;o:p&gt;&lt;/o:p&gt;3. Tests are the first class document for how your code will eventually work. Any developer/tester can go through the test cases you covered and get the idea how the system should work in different cases. &lt;SPAN style="FONT-FAMILY: Wingdings; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: Wingdings"&gt;&lt;SPAN style="mso-char-type: symbol; mso-symbol-font-family: Wingdings"&gt;J&lt;/SPAN&gt;&lt;/SPAN&gt; Isn’t it too cool ?&lt;BR&gt;&lt;o:p&gt;&lt;/o:p&gt;4. Easier and risk free to change the code - you just need to run the tests, you will get to know where there might be some problem.&lt;o:p&gt;&lt;/o:p&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt; 
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;BR&gt;And so on...&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6109875" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AdilAkhtersWeblogs/~4/qq9dNT1UjnE" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/adilakhter/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><feedburner:origLink>http://weblogs.asp.net/adilakhter/archive/2008/04/18/tdd-in-a-nutshell.aspx</feedburner:origLink><enclosure url="http://feedproxy.google.com/~r/AdilAkhtersWeblogs/~5/ItU-AlX7B2A/6109875.ashx" length="36568" type="image/jpeg" /><feedburner:origEnclosureLink>http://weblogs.asp.net/adilakhter/attachment/6109875.ashx</feedburner:origEnclosureLink></item><item><title>Why Unit Testing is so important?</title><link>http://feedproxy.google.com/~r/AdilAkhtersWeblogs/~3/mAADECFXwcc/why-unit-testing-is-so-important.aspx</link><pubDate>Fri, 18 Apr 2008 11:47:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6109731</guid><dc:creator>Adil Akhter</dc:creator><slash:comments>6</slash:comments><wfw:commentRss>http://weblogs.asp.net/adilakhter/rsscomments.aspx?PostID=6109731</wfw:commentRss><wfw:comment>http://weblogs.asp.net/adilakhter/commentapi.aspx?PostID=6109731</wfw:comment><comments>http://weblogs.asp.net/adilakhter/archive/2008/04/18/why-unit-testing-is-so-important.aspx#comments</comments><description>&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#3c3c3c size=2&gt;Why writing unit tests are so important - lets consider a development team developing a module( call it - [&lt;STRONG&gt;A&lt;/STRONG&gt;])did not consider the unit testing that seriously. What happens to that module - &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#3c3c3c size=2&gt;1. [&lt;STRONG&gt;A]&lt;/STRONG&gt; produced lot of Bugs in the development phase since it was not tested adequately. And while fixing it- [&lt;STRONG&gt;A&lt;/STRONG&gt;] produced severe impact on other modules too because integration was failing again and again. So, the dependent module had to change as well to stabilize whole Delivery. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Lucida Sans Unicode" color=#3c3c3c&gt;2. That's not the end of misery. In the release testing, huge amount of bugs identified which also produced from the uncertain behavior of [&lt;STRONG&gt;A]&lt;/STRONG&gt;&amp;nbsp; and fixing those become a hell of a job for the developers. Just to show you one old basic diagram of software development life cycle - &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/WhyUnitTestingissoimportant_C1D7/image_4.png" mce_href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/WhyUnitTestingissoimportant_C1D7/image_4.png"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=286 alt=image src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/WhyUnitTestingissoimportant_C1D7/image_thumb_1.png" width=378 border=0 mce_src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/WhyUnitTestingissoimportant_C1D7/image_thumb_1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#3c3c3c size=2&gt;3. After the deliverable delivered to the client - Developers could not take pride for that because they were not confident whether they delivered a Good Product( from a developers perspective, I think its really crucial to deliver something from which you can take pride). &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#3c3c3c size=2&gt;4. [&lt;STRONG&gt;A&lt;/STRONG&gt;] became more susceptible and fragile day by day. And developers become really reluctant and was not comfortable to change the codes for any change request because of the code's inherent fragility.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT face="Lucida Sans Unicode" color=#3c3c3c&gt;5. Refactoring become very error-prone and troublesome. &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#3c3c3c size=2&gt;So, after some time - Developers started calling [&lt;STRONG&gt;A&lt;/STRONG&gt;] as "Dead Zone" or Legacy Code because [&lt;STRONG&gt;A&lt;/STRONG&gt;] become quite impossible to manage. &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#3c3c3c size=2&gt;Now if we go back to the days when the developers were planing or starting the &lt;/FONT&gt;&lt;FONT face="Lucida Sans Unicode" color=#3c3c3c size=2&gt;development process using our Time Traveler- what would you advise them?&amp;nbsp; :)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#3c3c3c size=2&gt;The situation that I just described,&amp;nbsp; its not new to most of the developers developing for a long time. That's why some intelligent people in agile world sit together and come up with some &lt;A href="http://www.extremeprogramming.org/rules.html" target=_blank mce_href="http://www.extremeprogramming.org/rules.html"&gt;basic rules and practices&lt;/A&gt; that we must follow to make our product worth taking pride. One of them is writing Unit Tests for your codes considering all the test criteria considering - &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Lucida Sans Unicode" color=#3c3c3c size=2&gt;1. Unit Tests are the first users of your Unit who ensure that your own Creation&amp;nbsp; is working that way you wanted to. Remember - "Taking pride". It become much easier to achieve.In addition, Learning Curve become much higher -because, you get to know very explicitly what are the cases you missed while writing unit tests initially that produce bugs. That way it makes you much mature developer day by day. &lt;BR&gt;&lt;BR&gt;2. Unit Tests are the living description how the Unit should work. Any one new to your unit as a developer , should just need some time to go through the Unit Tests to get the Idea how the unit should work. &lt;BR&gt;&lt;BR&gt;3. Unit Tests are the tools that make integration much easier. &lt;BR&gt;&lt;BR&gt;4.Last but not that least - Refactoring was never been so much easier if there were Unit Tests. &lt;BR&gt;&lt;BR&gt;Any comments or suggestions on this post is most welcome.&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6109731" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AdilAkhtersWeblogs/~4/mAADECFXwcc" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/adilakhter/archive/tags/TDD/default.aspx">TDD</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/Unit+Testing/default.aspx">Unit Testing</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/Agile/default.aspx">Agile</category><feedburner:origLink>http://weblogs.asp.net/adilakhter/archive/2008/04/18/why-unit-testing-is-so-important.aspx</feedburner:origLink></item><item><title>Using Predicate &amp; Action of .Net2.0</title><link>http://feedproxy.google.com/~r/AdilAkhtersWeblogs/~3/x1E-cMzzxlU/using-predicate-amp-action-of-net2-0.aspx</link><pubDate>Wed, 16 Apr 2008 16:30:14 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6103519</guid><dc:creator>Adil Akhter</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://weblogs.asp.net/adilakhter/rsscomments.aspx?PostID=6103519</wfw:commentRss><wfw:comment>http://weblogs.asp.net/adilakhter/commentapi.aspx?PostID=6103519</wfw:comment><comments>http://weblogs.asp.net/adilakhter/archive/2008/04/16/using-predicate-amp-action-of-net2-0.aspx#comments</comments><description>&lt;p&gt;While I started developing software, I faced this situation over and over again where I had to iterate thorough the whole collection and perform some action on each of the element of the collection or filter elements depending on some logic. It was really annoying to&amp;#160; write same for/foreach loop again and again.&lt;/p&gt;  &lt;p&gt;.Net framework2.0 resolve this issue where we can just tell the collection how to filter / how to perform some action on each element of the collection and it take care of the iteration part.&amp;#160; Let's check out the List&amp;lt;T&amp;gt; Class of &lt;a href="http://msdn2.microsoft.com/en-us/library/0sbxh9x2.aspx"&gt;System.Collections.Generic&lt;/a&gt; and what support it provides -&lt;/p&gt;  &lt;p&gt;&lt;a href="http://adilakhter.files.wordpress.com/2008/01/image.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="788" alt="image" src="http://adilakhter.files.wordpress.com/2008/01/image-thumb.png" width="219" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Huge support for Searching, Sorting and Filtering!!! If we look at the declaration of let's say - &lt;strong&gt;FindAll&lt;/strong&gt; and &lt;strong&gt;ForEach&lt;/strong&gt;&amp;#160; -&lt;/p&gt;  &lt;pre&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;T&amp;gt; FindAll(&lt;span style="color: #2b91af"&gt;Predicate&lt;/span&gt;&amp;lt;T&amp;gt; match);&lt;span style="color: blue"&gt;public void &lt;/span&gt;ForEach(&lt;span style="color: #2b91af"&gt;Action&lt;/span&gt;&amp;lt;T&amp;gt; action);&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here Predicate and Actor are the generic delegate which gives us the flexibility to provide a way to filter the collection or perform action to each and every element of the List. Let's dig deeper inside them -&lt;/p&gt;

&lt;h5&gt;Inside Predicate:&lt;/h5&gt;

&lt;p&gt;Predicate is a Generic Delegate which takes support from the new generic feature of .Net Framework2.0. It is defined -&lt;/p&gt;

&lt;pre&gt;&lt;span style="color: blue"&gt;delegate bool &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Predicate&lt;/span&gt;&amp;lt;T&amp;gt;(T obj)&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As per definition of MSDN, &lt;strong&gt;Predicate&lt;/strong&gt; -&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&amp;quot;represents a method that defines a set of criteria and determines whether the specific object meets this criteria.&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In short, Predicate is just a generic delegate that takes T as object and check whether the object fulfill some criteria and depending on that return true|false.&lt;/p&gt;

&lt;h6&gt;Example&lt;/h6&gt;

&lt;p&gt;In this example, by using Predicate, we are going to tell the Collection how to filter and Collection will handle the whole iteration and filtering process -&lt;/p&gt;

&lt;p&gt;Let's say, we have a collection of SprintBacklogItem and we want to filter them depending on there State == Closed, we can do it using predicate -&lt;/p&gt;

&lt;p&gt;1. Define a method that represents the Predicate -&lt;/p&gt;

&lt;pre&gt;&lt;span style="color: blue"&gt;private bool &lt;/span&gt;HasStateClosed(&lt;span style="color: #2b91af"&gt;SprintBacklogItem &lt;/span&gt;item) 
        { 
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(item.State == &lt;span style="color: #2b91af"&gt;SprintBackLogStatesStrings&lt;/span&gt;.CLOSED) 
                &lt;span style="color: blue"&gt;return true&lt;/span&gt;; 
            &lt;span style="color: blue"&gt;return false&lt;/span&gt;; 
        }&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This method simply checks whether the SprintBacklogItem's state is closed or not and depending on that , return true or false. Now, if we look at the declaration of the method , we are affirmative that we can use Predicate to represent this method.&lt;/p&gt;

&lt;p&gt;2.&amp;#160; Following line of code filters all the closed SprintBacklogItems -&lt;/p&gt;

&lt;pre&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;SprintBacklogItem&lt;/span&gt;&amp;gt; closedItems= _SprintBackLogsItems.FindAll(HasStateClosed);&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;Inside Action:&lt;/h5&gt;

&lt;p&gt;Similar to Predicate,&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&amp;quot;Action is also one kind of generic delegate which represents a method that take the object as input and perform some operation on that.&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Definition of Action delegate-&lt;/p&gt;

&lt;pre&gt;&lt;span style="color: blue"&gt;delegate void &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Action&lt;/span&gt;&amp;lt;T&amp;gt;(T obj);&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the signature of the delegate, it can represent the method with signature that must have one parameter passed to it and void as return type.&lt;/p&gt;

&lt;p&gt;In List&amp;lt;T&amp;gt; , the method represented by the Action delegate takes an input obj and perform actions on that.&lt;/p&gt;

&lt;h6&gt;Example&lt;/h6&gt;

&lt;p&gt;In this example, by using Action, we are going to perform some predefined actions( initializing ActualHour = 10) on each elements of the List -&lt;/p&gt;

&lt;p&gt;1. Define the method that will be represented by Action -&lt;/p&gt;

&lt;pre&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;InitActualHour(&lt;span style="color: #2b91af"&gt;SprintBacklogItem &lt;/span&gt;item) 
        { 
            item.ActualHour = 10; 
        }&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2. Following line of code initialize all the elements' Actual hour to 10 of the List -&lt;/p&gt;

&lt;pre&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.ForEach(InitActualHour);&lt;/pre&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Isn't it pretty cool and slick ? Instead of implementing methods for Actor and Predicate , we could have used Anonymous Delegate. I will cover that topic in my future posts. Bye for now. :)&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6103519" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AdilAkhtersWeblogs/~4/x1E-cMzzxlU" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/adilakhter/archive/tags/.Net2.0/default.aspx">.Net2.0</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/C_2300_/default.aspx">C#</category><feedburner:origLink>http://weblogs.asp.net/adilakhter/archive/2008/04/16/using-predicate-amp-action-of-net2-0.aspx</feedburner:origLink></item><item><title>Designing Efficient Immutable .Net2.0 Objects</title><link>http://feedproxy.google.com/~r/AdilAkhtersWeblogs/~3/crKgjGsVAEA/designing-efficient-immutable-net2-0-objects.aspx</link><pubDate>Wed, 16 Apr 2008 16:29:00 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6103518</guid><dc:creator>Adil Akhter</dc:creator><slash:comments>7</slash:comments><wfw:commentRss>http://weblogs.asp.net/adilakhter/rsscomments.aspx?PostID=6103518</wfw:commentRss><wfw:comment>http://weblogs.asp.net/adilakhter/commentapi.aspx?PostID=6103518</wfw:comment><comments>http://weblogs.asp.net/adilakhter/archive/2008/04/16/designing-efficient-immutable-net2-0-objects.aspx#comments</comments><description>&lt;H3&gt;&lt;FONT face=Arial&gt;&lt;A title=classdiagram2.jpg href="http://adilakhter.wordpress.com/files/2007/12/classdiagram2.jpg" mce_href="http://adilakhter.wordpress.com/files/2007/12/classdiagram2.jpg"&gt;&lt;/A&gt;&lt;A title=classdiagram1.jpg href="http://adilakhter.wordpress.com/files/2007/12/classdiagram1.jpg" mce_href="http://adilakhter.wordpress.com/files/2007/12/classdiagram1.jpg"&gt;&lt;/A&gt;What is an immutable object? &lt;/FONT&gt;&lt;/H3&gt;
&lt;P align=left&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;By definition immutable object is the object whose state can not be changed after it is created. That means, after creating the object, its publicly exposed members can not be changed from their initial assigned values. On the contrary, mutable objects are objects whose state can be changed at any point of time.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Every developer has to take a important decision whether to make a class mutable or immutable while designing the domain model. &lt;BR&gt;While taking this decision, careful considerations can make us avoid the potential pitfall of using immutable object.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Why &amp;amp; How using immutable .Net object – is our today’s discussion. Let’s begin with &lt;B&gt;How&lt;/B&gt; part .&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;H3&gt;&lt;FONT face=Arial&gt;How to implement .Net Immutable Object?&lt;/FONT&gt;&lt;/H3&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;The way I would implement an immutable .Net class –&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN&gt;-&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Make the fields &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;private&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt; &lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;. &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN&gt;-&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Provide a Public property with &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;get&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt; accessor. &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN&gt;-&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;If the class is no longer needed to inherited – making it &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;sealed&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;.&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Like in the following example, I am implementing an immutable class &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;User&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN&gt;&lt;FONT face="Times New Roman"&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;Contact &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;which will be inherited in &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;User &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;–&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN&gt;&lt;A title=classdiagram2.jpg href="http://adilakhter.wordpress.com/files/2007/12/classdiagram2.jpg" mce_href="http://adilakhter.wordpress.com/files/2007/12/classdiagram2.jpg"&gt;&lt;/A&gt;&lt;A title=classdiagram1.jpg href="http://adilakhter.wordpress.com/files/2007/12/classdiagram1.jpg" mce_href="http://adilakhter.wordpress.com/files/2007/12/classdiagram1.jpg"&gt;&lt;IMG style="WIDTH: 442px; HEIGHT: 216px" height=171 alt=classdiagram1.jpg src="http://adilakhter.wordpress.com/files/2007/12/classdiagram1.jpg" width=438 mce_src="http://adilakhter.wordpress.com/files/2007/12/classdiagram1.jpg"&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN&gt;&lt;FONT face="Times New Roman"&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Here is the Implementation of the Immutable classes – &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;public&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: #2b91af"&gt;UserContact&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;FONT color=#000000&gt; _Name;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;FONT color=#000000&gt; Name&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;&lt;FONT color=#000000&gt; { &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;FONT color=#000000&gt; _Name; }&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;FONT color=#000000&gt; _EmailAddress;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;FONT color=#000000&gt; EmailAddress&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;&lt;FONT color=#000000&gt; { &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;&lt;FONT color=#000000&gt; _EmailAddress; }&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt;&lt;FONT color=#000000&gt; UserContact( &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;FONT color=#000000&gt; name , &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt;&lt;FONT color=#000000&gt; emailAddress)&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;_EmailAddress = emailAddress;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;_Name = name;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;UserContact&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;FONT color=#000000&gt; get inherited by &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;User&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;FONT color=#000000&gt; as follows [Since User class is no longer inherited – we make it &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;sealed&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;FONT color=#000000&gt;] - &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt; &lt;SPAN style="COLOR: blue"&gt;sealed&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;User&lt;/SPAN&gt; : &lt;SPAN style="COLOR: #2b91af"&gt;UserContact&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;readonly&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; _UserName;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; UserName&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;{&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; _UserName; }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; User(&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; name, &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; email, &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; userName)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;: &lt;SPAN style="COLOR: blue"&gt;base&lt;/SPAN&gt;(name, email) { }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;So, isn’t it really easy to implement a Truly Immutable class in .Net framework? &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: wingdings"&gt;&lt;SPAN&gt;J&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Now the question pops into our mind – why we will be using immutable .net objects , what would be benefits of that ? Let’s explore that – &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;&lt;FONT face=Arial&gt;Why use immutable object?&lt;/FONT&gt;&lt;/H3&gt;
&lt;P&gt;&lt;FONT face="Times New Roman"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Protection: &lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;From the definition we know, &lt;B&gt;Immutable&lt;/B&gt; objects can not be changed after its being initialized. So, while using inside application, immutable object can flow in different layers of the application without getting worried about being altered by different layers. &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Performance: &lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Copying object will be much easier, we just need to copy the reference instead of copying the whole object. It would be much faster to copy reference than the whole object. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;User&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt; user = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;User&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"adil"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"adil.bd@hotmail.com"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"adak"&lt;/SPAN&gt;); &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;User&lt;/SPAN&gt; userTemp = user;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;In case of mutable object, we would need to create defensive copy of the object and in .Net term, we need to create a &lt;B&gt;Deep Copy&lt;/B&gt; of object otherwise, changing a property in the actual mutable object would reflect everywhere where the object is referenced.&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;For example, let’s consider &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;User&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt; as mutable; then changing any thing in &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;user &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;object will have same impact on &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;userTemp &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;as well which is not intended.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;To avoid this situation, in case of mutable object, we need to make a Deep Copy of the object which is a costly operation. However, for immutable object, copying the reference would be enough since its state can’t be changed.&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Scalability: &lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Thread synchronization is an issue of concern while designing multithreaded application. Overhead of synchronizing immutable object is far less than mutable object. By default , an individual immutable object does not need to be synchronized as its state will be not be modified by any thread. However, since the immutable object will still be accessed thorough reference , it would require some synchronization. In complex sync scenarios, immutable object would perform far better then mutable version.&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Consistency:&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt; &lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0px; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;If we consider inheritance hierarchy, immutability provides a way for the sub-class to maintain consistency in inheritance hierarchy. Consider following mutable objects– &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN&gt;&lt;A title=classdiagram2.jpg href="http://adilakhter.wordpress.com/files/2007/12/classdiagram2.jpg" mce_href="http://adilakhter.wordpress.com/files/2007/12/classdiagram2.jpg"&gt;&lt;STRONG&gt;&lt;IMG alt=classdiagram2.jpg src="http://adilakhter.wordpress.com/files/2007/12/classdiagram2.jpg" mce_src="http://adilakhter.wordpress.com/files/2007/12/classdiagram2.jpg"&gt;&lt;/STRONG&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;/SPAN&gt; 
&lt;P class=MsoNormal style="MARGIN: 0px; TEXT-ALIGN: justify"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;When we instantiate the &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;StudentMutable &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;object, the AccountType is automatically set to &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: consolas"&gt;Student Account – &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: consolas"&gt;&lt;STRONG&gt;public&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt; StudentMutable(&lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; name , &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; email , &lt;SPAN style="COLOR: blue"&gt;string&lt;/SPAN&gt; userName ) &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;: &lt;SPAN style="COLOR: blue"&gt;base&lt;/SPAN&gt;(name ,email , userName,&lt;SPAN style="COLOR: #a31515"&gt;"Student Account"&lt;/SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;{&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;}&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Now, we can write following lines by which the AccountType property could be anything other than &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: consolas"&gt;"Student Account” which&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt; is completely inconsistent -&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: consolas"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: consolas"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; COLOR: #2b91af; FONT-FAMILY: consolas"&gt;StudentMutable&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt; mutable = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;StudentMutable&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"Adil"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"Adil.bd@hotmai.com"&lt;/SPAN&gt;, &lt;SPAN style="COLOR: #a31515"&gt;"adil"&lt;/SPAN&gt;);&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;mutable.AccountType = &lt;SPAN style="COLOR: #a31515"&gt;"whatever account"&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: consolas"&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;But if we use Immutable object in inheritance – the object hierarchy will always be consistent.:)&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;&lt;FONT face=Arial&gt;What to consider while designing Immutable objects?&lt;/FONT&gt;&lt;/H3&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;Intantiation of immutable object might be considered an operation that will be done more frequently. Then the allocation and freeing the resource for the immutable object would be the most recurrent opertaion which might result as performace overhead. Incase of regular objects , it seems that syncronization is far more costly operation from CPU perspective than allocating and freeing resource. &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;For objects that require significant time to initialize , we may consider to implement Object Pool or Flyweight pattern to enhance reusability.&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;H3&gt;&lt;SPAN&gt;&lt;FONT face=Arial&gt;Conclusion&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H3&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;So , We can achive much faster and efficient code if we use Immutable object. But by saying all this , definitly we need to design accordingly and carefully so that immutable object can perform to its best. In this article , we learn how to implement immutable object in .Net and what’s its benefits and what we need to consider while implementing immutable object. In my next post , I am thinking to write something about reusing the immutable object to enhance efficiency. Thanks for visiting the the blog. Let me know your comments and feedbacks. Bye &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: wingdings"&gt;&lt;SPAN&gt;J&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt; . &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: tahoma"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;A href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fweblogs.asp.net%2fadilakhter%2farchive%2f2008%2f04%2f16%2fdesigning-efficient-immutable-net2-0-objects.aspx"&gt;&lt;IMG alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fweblogs.asp.net%2fadilakhter%2farchive%2f2008%2f04%2f16%2fdesigning-efficient-immutable-net2-0-objects.aspx" border=0&gt;&lt;/A&gt; &lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6103518" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AdilAkhtersWeblogs/~4/crKgjGsVAEA" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/adilakhter/archive/tags/.Net2.0/default.aspx">.Net2.0</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/Immutable/default.aspx">Immutable</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/Design/default.aspx">Design</category><feedburner:origLink>http://weblogs.asp.net/adilakhter/archive/2008/04/16/designing-efficient-immutable-net2-0-objects.aspx</feedburner:origLink></item><item><title>Visual Studio2008 Themes</title><link>http://feedproxy.google.com/~r/AdilAkhtersWeblogs/~3/8hwo9uQJmfM/visual-studio2008-themes.aspx</link><pubDate>Wed, 16 Apr 2008 16:22:40 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6103514</guid><dc:creator>Adil Akhter</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://weblogs.asp.net/adilakhter/rsscomments.aspx?PostID=6103514</wfw:commentRss><wfw:comment>http://weblogs.asp.net/adilakhter/commentapi.aspx?PostID=6103514</wfw:comment><comments>http://weblogs.asp.net/adilakhter/archive/2008/04/16/visual-studio2008-themes.aspx#comments</comments><description>&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:1162b715-c7b3-41f0-aca1-ccff1bc2658f" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/Vs2008%20Themes" rel="tag"&gt;Vs2008 Themes&lt;/a&gt;&lt;/div&gt;  &lt;p&gt;If you are also fond of changing the look and feel of Visual Studio using cools themes, here is some cool links for you - &lt;/p&gt;  &lt;p&gt;1. &lt;a href="http://www.hanselman.com/blog/ChangingYourColorsInVisualStudioNETBlackVersusWhite.aspx" target="_blank"&gt;A list of Cool themes in Scott Hanselman's blog&lt;/a&gt;     &lt;br /&gt;2. &lt;a href="http://www.agileprogrammer.com/dotnetguy/archive/2006/09/07/19030.aspx" target="_blank"&gt;Dark Visual Studio&lt;/a&gt;     &lt;br /&gt;3. &lt;a href="http://www.zdjecienakomorke.za.pl/ZenBurnExt.vssettings"&gt;ZenBurn-based Visual Studio 2005 theme supporting HTML,CSS and XML&lt;/a&gt;     &lt;br /&gt;4. &lt;a href="http://weblogs.asp.net/infinitiesloop/archive/2006/08/06/Join-the-Dark-Side-of-Visual-Studio.aspx" target="_blank"&gt;Join the Dark Side of Visual Studio&lt;/a&gt; by Dave Reed     &lt;br /&gt;5. &lt;a href="http://blog.wekeroad.com/2007/10/17/textmate-theme-for-visual-studio-take-2/" target="_blank"&gt;TextMate Theme For Visual Studio, Take 2&lt;/a&gt; &lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:0e674c5d-2973-4c94-933e-9f86d066c98c" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/Vs2008%20Themes" rel="tag"&gt;Vs2008 Themes&lt;/a&gt;&lt;/div&gt;  &lt;p&gt;How to change your Visual Studio 2008 Theme - &lt;/p&gt;  &lt;p&gt;1. &lt;a href="http://www.hanselman.com/blog/ChangingYourColorsInVisualStudioNETBlackVersusWhite.aspx" target="_blank"&gt;Changing your colors in Visual Studio.NET - Black versus White By Scott Hanselman&lt;/a&gt;     &lt;br /&gt;2. &lt;a href="http://www.agileprogrammer.com/dotnetguy/archive/2006/09/07/19030.aspx" target="_blank"&gt;Dark Visual Studio - By Brad Wilson&lt;/a&gt;     &lt;br /&gt;3. &lt;a href="http://www.codinghorror.com/blog/archives/000417.html" target="_blank"&gt;Pimp MY IDE by Jeff Atwood&lt;/a&gt;     &lt;br /&gt;4. &lt;a href="http://www.codinghorror.com/blog/archives/000340.html" target="_blank"&gt;Code Colorizing and readability by Jeff Atwood&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Download LInks -&lt;/p&gt;  &lt;p&gt;1. &lt;a href="http://www.codinghorror.com/blog/files/exported-font-and-colors-for-jeff-atwood-sept-19.zip"&gt;Download Jeff's scheme&lt;/a&gt;     &lt;br /&gt;2. &lt;a href="http://www.codinghorror.com/blog/files/exported-font-and-colors-zenburn.zip"&gt;Download &amp;quot;Zenburn&amp;quot; scheme&lt;/a&gt;     &lt;br /&gt;3. &lt;a href="http://www.lnbogen.com/ct.ashx?id=fc104328-6299-4eb1-a203-84b686aa4c5b&amp;amp;url=http%3a%2f%2fwww.lnbogen.com%2fcontent%2fbinary%2fOrenEllenbogen_DarkSchema.rar"&gt;OrenEllenbogen_DarkSchema.rar (58 KB)&lt;/a&gt;     &lt;br /&gt;4. &lt;a href="http://idehotornot.ning.com/" target="_blank"&gt;Is You IDE HOT or Not?&lt;/a&gt;     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;How to change your themes : &lt;/p&gt;  &lt;p&gt;Step - 1 : Click on the Import And Export Settings :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/VisualStudio2008Themes_F955/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="262" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/VisualStudio2008Themes_F955/image_thumb.png" width="404" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Step -2:&amp;#160; Select &lt;strong&gt;Import Selected Environment settings and click on Next&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/VisualStudio2008Themes_F955/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="406" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/VisualStudio2008Themes_F955/image_thumb_2.png" width="404" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Step -3: You get the option to save your current setting. I would suggest to save it. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/VisualStudio2008Themes_F955/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="402" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/VisualStudio2008Themes_F955/image_thumb_3.png" width="404" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Step-4: Click Browse and select the *.vssettings file and click Next - &lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/VisualStudio2008Themes_F955/image_10.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="290" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/VisualStudio2008Themes_F955/image_thumb_4.png" width="439" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Step-5: Check the boxes the setting you want to change and click finish. You are done with you brand new theme. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/VisualStudio2008Themes_F955/image_12.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="396" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/VisualStudio2008Themes_F955/image_thumb_5.png" width="404" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;If any error occurs or you dont feel like using your new theme, you can always get back to your old setting by getting upto Step4 and setting your themes to import is the one you saved in step - 3 -&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/VisualStudio2008Themes_F955/image_14.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="382" alt="image" src="http://weblogs.asp.net/blogs/adilakhter/WindowsLiveWriter/VisualStudio2008Themes_F955/image_thumb_6.png" width="404" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;And you also have the option to reset all the settings [Step-1]. &lt;/p&gt;  &lt;p&gt;Have fun with the themes. &lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6103514" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AdilAkhtersWeblogs/~4/8hwo9uQJmfM" height="1" width="1"/&gt;</description><category domain="http://weblogs.asp.net/adilakhter/archive/tags/Themes/default.aspx">Themes</category><category domain="http://weblogs.asp.net/adilakhter/archive/tags/Vs2008/default.aspx">Vs2008</category><feedburner:origLink>http://weblogs.asp.net/adilakhter/archive/2008/04/16/visual-studio2008-themes.aspx</feedburner:origLink></item></channel></rss>
