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

<channel>
	<title>Codelog</title>
	<atom:link href="http://codelog.blogial.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codelog.blogial.com</link>
	<description>foreach(Snippet aSnippet in CodeLog){ aSnippet.GetSolution(); }</description>
	<pubDate>Mon, 01 Feb 2010 04:45:06 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>DoUNo: XAML gets compiled in to a BAML</title>
		<link>http://codelog.blogial.com/2010/02/01/douno-xaml-gets-compiled-in-to-a-baml/</link>
		<comments>http://codelog.blogial.com/2010/02/01/douno-xaml-gets-compiled-in-to-a-baml/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 04:43:44 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[DoUNo]]></category>

		<category><![CDATA[UI]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[xaml]]></category>

		<category><![CDATA[baml]]></category>

		<guid isPermaLink="false">http://codelog.blogial.com/?p=507</guid>
		<description><![CDATA[What does a xaml file gets compiled in to ? It gets compiled in to a baml (binary xaml). More @ wikipedia.
You can find the .baml file in the \obj\Debug folder.
]]></description>
			<content:encoded><![CDATA[<p>What does a xaml file gets compiled in to ? It gets compiled in to a baml (binary xaml). More @ <a href="http://en.wikipedia.org/wiki/BAML" onclick="javascript:pageTracker._trackPageview('/outbound/article/en.wikipedia.org');" target="_blank">wikipedia</a>.</p>
<p>You can find the .baml file in the \obj\Debug folder.</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2010/02/01/douno-xaml-gets-compiled-in-to-a-baml/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Transparent background with opaque controls on top of it in wpf</title>
		<link>http://codelog.blogial.com/2010/01/13/transparent-background-with-opaque-controls-on-top-of-it/</link>
		<comments>http://codelog.blogial.com/2010/01/13/transparent-background-with-opaque-controls-on-top-of-it/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 04:04:59 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[Tips 'n' Tricks]]></category>

		<category><![CDATA[UI]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[xaml]]></category>

		<category><![CDATA[Window]]></category>

		<guid isPermaLink="false">http://codelog.blogial.com/?p=491</guid>
		<description><![CDATA[Ever felt like having a transparent window background and still opaque controls inside the window? It can be easily done in wpf.

Set the window&#8217;s AllowsTransparency to True
Set the window&#8217;s Background to Transparent
Add a Rectangle to the parent panel of the window
Set the opacity of the rectangle to some value &#60; 1 (0.7, &#8230;)
Add your controls [...]]]></description>
			<content:encoded><![CDATA[<p>Ever felt like having a transparent window background and still opaque controls inside the window? It can be easily done in wpf.</p>
<ol>
<li>Set the window&#8217;s <strong>AllowsTransparency</strong> to <em>True</em></li>
<li>Set the window&#8217;s <strong>Background</strong> to <em>Transparent</em></li>
<li><strong>Add a Rectangle </strong>to the parent panel of the window</li>
<li>Set the <strong>opacity</strong> of the rectangle to some value <em>&lt; 1 </em>(0.7, &#8230;)</li>
<li><strong>Add your controls </strong>to the parent panel</li>
<li>You are one step away form seeing a transparent background with opaque controls on top of it. Go ahead, run the application now</li>
</ol>
<p>Sample window,</p>
<p>&lt;Window x:Class=&#8221;BackgroundWindow.Transparent.Samples.WPF.Window1&#8243;<br />
xmlns=&#8221;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#8221;<br />
xmlns:x=&#8221;http://schemas.microsoft.com/winfx/2006/xaml&#8221;<br />
Title=&#8221;Window1&#8243; Height=&#8221;300&#8243; Width=&#8221;300&#8243; AllowsTransparency=&#8221;True&#8221; Background=&#8221;Transparent&#8221; WindowStyle=&#8221;None&#8221;&gt;<br />
&lt;Grid&gt;<br />
&lt;Rectangle Fill=&#8221;Gray&#8221; Opacity=&#8221;0.7&#8243; /&gt;<br />
&lt;Button Width=&#8221;100&#8243; Height=&#8221;100&#8243;&gt;Click this on&lt;/Button&gt;<br />
&lt;/Grid&gt;<br />
&lt;/Window&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2010/01/13/transparent-background-with-opaque-controls-on-top-of-it/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DoUNo: MDI in WPF</title>
		<link>http://codelog.blogial.com/2010/01/13/douno-mdi-is-missing-in-wpf/</link>
		<comments>http://codelog.blogial.com/2010/01/13/douno-mdi-is-missing-in-wpf/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 03:37:19 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[DoUNo]]></category>

		<category><![CDATA[General Programming]]></category>

		<category><![CDATA[Tips 'n' Tricks]]></category>

		<category><![CDATA[UI]]></category>

		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://codelog.blogial.com/?p=488</guid>
		<description><![CDATA[WPF, out of the box doesn&#8217;t have provision for MDI windows. The reason is quite simple, MDI windows are outdated and most of the applications have been using tabbed documents, proving they are really easy to use. Although the framework is flexible enough for you to make such a feature, its better to move to [...]]]></description>
			<content:encoded><![CDATA[<p>WPF, out of the box doesn&#8217;t have provision for MDI windows. The reason is quite simple, MDI windows are outdated and most of the applications have been using tabbed documents, proving they are really easy to use. Although the framework is flexible enough for you to make such a feature, its better to move to tab based interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2010/01/13/douno-mdi-is-missing-in-wpf/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Mashing Twitter and FSO</title>
		<link>http://codelog.blogial.com/2009/12/06/mashing-twitter-and-fso/</link>
		<comments>http://codelog.blogial.com/2009/12/06/mashing-twitter-and-fso/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 14:46:59 +0000</pubDate>
		<dc:creator>sup3rkiddo</dc:creator>
		
		<category><![CDATA[General Programming]]></category>

		<category><![CDATA[Python]]></category>

		<category><![CDATA[Tips 'n' Tricks]]></category>

		<category><![CDATA[freerunner]]></category>

		<category><![CDATA[freesmartphone]]></category>

		<category><![CDATA[freesmartphone.org]]></category>

		<category><![CDATA[fso]]></category>

		<category><![CDATA[gta02]]></category>

		<category><![CDATA[neo]]></category>

		<category><![CDATA[openmoko]]></category>

		<guid isPermaLink="false">http://codelog.blogial.com/?p=483</guid>
		<description><![CDATA[

I really love Twitter and it didn’t make any sense to me to shell out a rupee for every tweet sent through my Airtel Mobile. Moreover, I am on one of those monthly booster packs which allows you to send 22000 text messages for free. I simply had to exploit this by setting up my [...]]]></description>
			<content:encoded><![CDATA[<div class="itemtext">
<div class="snap_preview">
<p>I really love Twitter and it didn’t make any sense to me to shell out a rupee for every tweet sent through my Airtel Mobile. Moreover, I am on one of those monthly booster packs which allows you to send 22000 text messages for free. I simply had to exploit this by setting up my own little ‘OC’ twitter forwarder written in python. (I know of smstweet.in service but I am still charged 1.50 for every tweet I send)</p>
<p>Its insanely simple to write such a ‘forwarder’ in python using the services provided by the FSO (<a href="http://wiki.freesmartphone.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/wiki.freesmartphone.org');">freesmartphone.org</a>) Framework,</p>
<ol>
<li>Send messages to your old/unused number whose SIM is in the <a href="http://openmoko.com/freerunner.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/openmoko.com');">Freerunner</a> (or any other device supported by the <a href="http://wiki.freesmartphone.org/" onclick="javascript:pageTracker._trackPageview('/outbound/article/wiki.freesmartphone.org');">FSO</a> framework)</li>
<li>Handle the incoming messages and use <a href="http://code.google.com/p/python-twitter/" onclick="javascript:pageTracker._trackPageview('/outbound/article/code.google.com');">python-twitter</a> API (or) raw urllib2 to post updates. Of course, the device should be connected to the internet, you can <a href="http://wiki.openmoko.org/wiki/Usb_networking" onclick="javascript:pageTracker._trackPageview('/outbound/article/wiki.openmoko.org');">tether</a> this device to an old unused computer. Simply put, the Freerunner should be able to access the internet.</li>
</ol>
<p>I know this is dumb given cheap GPRS and all, but what the heck; Sundays _are_ reserved for dumb things and I wanted to show off how easy it is to develop and conjure up simple but powerful scripts using open hackable hardware like the Freerunner. So take off your pedantic hats <img class="wp-smiley" src="http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif" alt=";)" /></p>
<p>Here is the actual python code,</p>
<p>–</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># Written By Sudharshan S, http://sudharsh.wordpress.com</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> dbus
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">logging</span>
<span style="color: #ff7700;font-weight:bold;">import</span> twitter
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> gobject
<span style="color: #ff7700;font-weight:bold;">from</span> gobject <span style="color: #ff7700;font-weight:bold;">import</span> MainLoop
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> dbus.<span style="color: black;">mainloop</span>.<span style="color: black;">glib</span> <span style="color: #ff7700;font-weight:bold;">import</span> DBusGMainLoop
DBusGMainLoop <span style="color: black;">&#40;</span>set_as_default = <span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Use OAUTH?</span>
USERNAME = <span style="color: #483d8b;">&quot;username&quot;</span>
PASSWORD = <span style="color: #483d8b;">&quot;password&quot;</span>
&nbsp;
log = <span style="color: #dc143c;">logging</span>.<span style="color: black;">getLogger</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;TweetForwarder&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> TweetForwarder:
&nbsp;
   <span style="color: #483d8b;">&quot;&quot;&quot;Process Incoming messages and update twitter status
      if the message startswith 'tweet'
   &quot;&quot;&quot;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, username, password<span style="color: black;">&#41;</span>:
       log.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Starting up....&quot;</span><span style="color: black;">&#41;</span>
       <span style="color: #008000;">self</span>.<span style="color: black;">twitter_api</span> = twitter.<span style="color: black;">Api</span><span style="color: black;">&#40;</span>username=username, password=password<span style="color: black;">&#41;</span>
&nbsp;
       <span style="color: #808080; font-style: italic;"># Get proxies and add signal handlers</span>
       bus = dbus.<span style="color: black;">SystemBus</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
       _usage = bus.<span style="color: black;">get_object</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;org.freesmartphone.ousaged&quot;</span>,
                               <span style="color: #483d8b;">&quot;/org/freesmartphone/Usage&quot;</span><span style="color: black;">&#41;</span>
       _proxy = bus.<span style="color: black;">get_object</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;org.freesmartphone.ogsmd&quot;</span>, \
                               <span style="color: #483d8b;">&quot;/org/freesmartphone/GSM/Device&quot;</span><span style="color: black;">&#41;</span>
       <span style="color: #008000;">self</span>.<span style="color: black;">usage_iface</span> = dbus.<span style="color: black;">Interface</span><span style="color: black;">&#40;</span>_usage, <span style="color: #483d8b;">&quot;org.freesmartphone.Usage&quot;</span><span style="color: black;">&#41;</span>
       <span style="color: #008000;">self</span>.<span style="color: black;">usage_iface</span>.<span style="color: black;">RequestResource</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'GSM'</span><span style="color: black;">&#41;</span>
       <span style="color: #008000;">self</span>.<span style="color: black;">sms_iface</span> = dbus.<span style="color: black;">Interface</span> <span style="color: black;">&#40;</span>_proxy, <span style="color: #483d8b;">&quot;org.freesmartphone.GSM.SMS&quot;</span><span style="color: black;">&#41;</span>
       <span style="color: #008000;">self</span>.<span style="color: black;">sms_iface</span>.<span style="color: black;">connect_to_signal</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;IncomingMessage&quot;</span>, <span style="color: #008000;">self</span>.<span style="color: black;">onIncomingMessage</span><span style="color: black;">&#41;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> onIncomingMessage<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, sender, message, kwargs<span style="color: black;">&#41;</span>:
       log.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Received SMS from %s:%s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>sender, message<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
       <span style="color: #808080; font-style: italic;"># We don't ALL messages to this number to be tweeted</span>
       <span style="color: #ff7700;font-weight:bold;">if</span> message.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;tweet &quot;</span><span style="color: black;">&#41;</span>:
           log.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Trying to update status : %s&quot;</span> <span style="color: #66cc66;">%</span> message<span style="color: black;">&#91;</span><span style="color: #ff4500;">6</span>:<span style="color: black;">&#93;</span>.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
           <span style="color: #008000;">self</span>.<span style="color: black;">twitter_api</span>.<span style="color: black;">PostUpdate</span><span style="color: black;">&#40;</span>message<span style="color: black;">&#91;</span><span style="color: #ff4500;">6</span>:<span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
           log.<span style="color: black;">warning</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Updated Status&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
   <span style="color: #ff7700;font-weight:bold;">def</span> run<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
       loop = MainLoop<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
       loop.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    <span style="color: #dc143c;">logging</span>.<span style="color: black;">basicConfig</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    server = TweetForwarder<span style="color: black;">&#40;</span>USERNAME, PASSWORD<span style="color: black;">&#41;</span>
    server.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
--</pre></div></div>

<p>Make sure you have python-netclient and python-json installed on your Freerunner. These can be installed using the ‘opkg install’ command.</p>
<p>The script and the accompanying dependency can be downloaded from <a href="http://gitorious.org/dumb-scripts/dumb-scripts/archive-tarball/master" onclick="javascript:pageTracker._trackPageview('/outbound/article/gitorious.org');">here</a>. Just change the USERNAME and PASSWORD accordingly after scp’ing the tarball to your device.</p>
<p>Some useful links,</p>
<p>[1]: <a href="http://git.freesmartphone.org/?p=specs.git;a=tree;f=html;h=bb7b2226c03c13b7c930e119c0df4bd0c91c06bb;hb=2a40169edbec7a2fcb804aa45e496df01aeba782" onclick="javascript:pageTracker._trackPageview('/outbound/article/git.freesmartphone.org');">The FSO API reference</a></p>
<p>[2]: <a href="http://dbus.freedesktop.org/doc/dbus-tutorial.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/dbus.freedesktop.org');">DBus Tutorial</a></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2009/12/06/mashing-twitter-and-fso/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DoUNo: Popup animation in wpf</title>
		<link>http://codelog.blogial.com/2009/12/03/douno-popup-animation-in-wpf/</link>
		<comments>http://codelog.blogial.com/2009/12/03/douno-popup-animation-in-wpf/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 04:58:24 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[Controls]]></category>

		<category><![CDATA[DoUNo]]></category>

		<category><![CDATA[Tips 'n' Tricks]]></category>

		<category><![CDATA[UI]]></category>

		<category><![CDATA[WPF]]></category>

		<category><![CDATA[Animation]]></category>

		<guid isPermaLink="false">http://codelog.blogial.com/?p=480</guid>
		<description><![CDATA[Every time I try adding a default animation (Slide, Fade, &#8230;) to a pop up in WPF, I find it not to be working. Today, I went thru&#8217; MSDN (breaking my laziness  ) and found that the popup animation shall work only if the AllowsTransparency of the popup is set to true. Really weird [...]]]></description>
			<content:encoded><![CDATA[<p>Every time I try adding a default animation (Slide, Fade, &#8230;) to a pop up in WPF, I find it not to be working. Today, I went thru&#8217; MSDN (breaking my laziness <img src='http://codelog.blogial.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) and found that the popup animation shall work only if the <a href="http://msdn.microsoft.com/en-us/library/ms749018.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank"><em>AllowsTransparency</em> of the popup is set to <em>true</em></a>. Really weird !!</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2009/12/03/douno-popup-animation-in-wpf/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DoUNo: Setting expectations on nullable type, NMock2</title>
		<link>http://codelog.blogial.com/2009/11/06/douno-setting-expectations-on-nullable-type-nmock2/</link>
		<comments>http://codelog.blogial.com/2009/11/06/douno-setting-expectations-on-nullable-type-nmock2/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 03:38:15 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[DoUNo]]></category>

		<category><![CDATA[General Programming]]></category>

		<category><![CDATA[Testing]]></category>

		<category><![CDATA[Tips 'n' Tricks]]></category>

		<category><![CDATA[unittest]]></category>

		<category><![CDATA[nmocks]]></category>

		<guid isPermaLink="false">http://codelog.blogial.com/?p=469</guid>
		<description><![CDATA[Ever had a problem of setting an expectation for nullable objects?
If you wanna return false when .HasValue of a nullable object is called, then you cannot do it with the normal expect statement. Rather, try not returning any values, because NMock2 returns default value of HasValue (False) if nothing is set as return values in [...]]]></description>
			<content:encoded><![CDATA[<p>Ever had a problem of setting an expectation for nullable objects?</p>
<p>If you wanna return false when .HasValue of a nullable object is called, then you cannot do it with the normal expect statement. Rather, try not returning any values, because NMock2 returns default value of HasValue (False) if nothing is set as return values in expect statements.</p>
<p>Here is a sample,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IProduct  <span style="color: #008080; font-style: italic;">//Interface that has a nullable member</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #FF0000;">int</span><span style="color: #008000;">?</span> ProductNo  <span style="color: #008080; font-style: italic;">//Member that I wanna test and I wish to test the scenario in which this will be null</span>
  <span style="color: #000000;">&#123;</span>
    get<span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">IProduct aProduct<span style="color: #008000;">=</span> myMockery.<span style="color: #0000FF;">NewMock</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>IProduct<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">//Stub.On(aProduct).GetProperty(&quot;ProductNo&quot;).Will(Return.Value(default(int?));  //this statement produces a runtime exception, so we have to use the following instead</span>
Stub.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>aProduct<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetProperty</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ProductNo&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>  <span style="color: #008080; font-style: italic;">//no return value is set, nmock2 returns false when .HasValue is queries</span></pre></div></div>

<p>Hope this helped you.</p>
<p>Sudarsan Srinivasan<br />
- on behalf of my friends (they found this hack <img src='http://codelog.blogial.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2009/11/06/douno-setting-expectations-on-nullable-type-nmock2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Settings expectations in NMock2</title>
		<link>http://codelog.blogial.com/2009/09/03/settings-expectations-in-nmock2/</link>
		<comments>http://codelog.blogial.com/2009/09/03/settings-expectations-in-nmock2/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 08:54:20 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[Testing]]></category>

		<category><![CDATA[unittest]]></category>

		<category><![CDATA[nmocks]]></category>

		<guid isPermaLink="false">http://codelog.blogial.com/?p=449</guid>
		<description><![CDATA[One of our previous articles would have given an introduction to NMocks. In here, we will try out various methods of setting expectations when we do a unit test.
note &#8212; this article considers that you know the basics of unit testing. check out our previous article if you would like to know the basics of [...]]]></description>
			<content:encoded><![CDATA[<p>One of our <a href="http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/"  target="_blank">previous articles </a>would have given an introduction to NMocks. In here, we will try out various methods of setting expectations when we do a unit test.</p>
<p><span style="color: #808080">note &#8212; this article considers that you know the basics of unit testing. check out our previous article if you would like to know the basics of nmock2</span></p>
<p>In NMock2, you have a wide variety of setting expectations on mocked objects.</p>
<p><strong>Stubs</strong></p>
<p>Stubs are expectations whose occurrences are unknown. We use stubs when we are not sure the number of times it might be called. So generally Stubs are used when expectations needs to be set 0 or more times</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Stub.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockedObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>  <span style="color: #008080; font-style: italic;">//Use this only when you are unaware of the occurrences,</span>
                                            <span style="color: #008080; font-style: italic;">//otherwise you end up writing a bad UT</span></pre></div></div>

<p><strong>Expect</strong></p>
<p>We use the Expect class when the number of calls to the method or property of the mock objects are known.</p>
<p><em>For example, </em></p>
<p>If number of occurrences are 7 on the method called, &#8220;<strong>GetName</strong>&#8220;, then use,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Exactly</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">7</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span>...</pre></div></div>

<p>If the number of occurrence is 1 on the method called, &#8220;<strong>GetName</strong>&#8220;, then use,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Once</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span>...</pre></div></div>

<p>or</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Exactly</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span>...</pre></div></div>

<p>You can even set negative expectations. For example,<br />
If you are pretty sure that the method &#8220;<strong>GetName</strong>&#8220;, will not/should not be called in your unit test, then use,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Never</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span>...</pre></div></div>

<p><strong>Expectation With Parameters</strong></p>
<p>If you are unit testing a method that makes a call to an interface which inturn takes two params and if you know the values of those params, you could set expectation on the mock object for the method with the known params.</p>
<p><em>For example, </em></p>
<p>If &#8220;GetName&#8221; method takes two params and if the param values are &#8220;foo&#8221; and &#8220;bar&#8221; according to the unit test case, then we can write an expectation as,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Once</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">With</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;foo&quot;</span>, <span style="color: #666666;">&quot;bar&quot;</span><span style="color: #000000;">&#41;</span>...</pre></div></div>

<p><strong>Expectation On Events</strong></p>
<p>You can add expectation on events of the mock object with the <strong>EventAdd </strong>method.</p>
<p><em>For example, </em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Foo
<span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> EventHandler ObjectChanged<span style="color: #008000;">;</span>
  ...
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> FooBarBaz
<span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">private</span> Foo myFoo<span style="color: #008000;">;</span>
  ...
  <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> SomeMethod<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    myFoo.<span style="color: #0000FF;">ObjectChanged</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> EventHandler<span style="color: #000000;">&#40;</span>Foo__ObjectChanged<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    ...
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>If you are writing a unit test for the method <strong>SomeMethod</strong>, then you shall add an expectation of the following form,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect.<span style="color: #0000FF;">Once</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>myMockObject<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">EventAdd</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ObjectChanged&quot;</span>, <span style="color: #008000;">Is</span>.<span style="color: #0000FF;">Anything</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p><strong>Expecting Exceptions</strong></p>
<p>You could also expect exceprions by adding the attribute, ExpectedException on top of your unit test.</p>
<p><em>For example, </em></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>Test<span style="color: #000000;">&#40;</span>Description<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Test case method that will test whether the ArgumentNullException is raised&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#91;</span>ExpectedException<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>ArgumentNullException<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> TestExceptionalScenario<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  ...
  <span style="color: #008080; font-style: italic;">//call the method that is supposed to throw the ArgumentNullException</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>These are the commonly used expectations. If you have used something really weird, I <span style="color: #ff6600"><strong>expect </strong>you share it with us     <img src='http://codelog.blogial.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />        <img src='http://codelog.blogial.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </span></p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2009/09/03/settings-expectations-in-nmock2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Accessing Command Prompt from C#</title>
		<link>http://codelog.blogial.com/2009/08/31/accessing-command-prompt-from-c/</link>
		<comments>http://codelog.blogial.com/2009/08/31/accessing-command-prompt-from-c/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 12:14:37 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[General Programming]]></category>

		<category><![CDATA[Tips 'n' Tricks]]></category>

		<guid isPermaLink="false">http://codelog.blogial.com/?p=446</guid>
		<description><![CDATA[Recently, I wanted to write a program in c# that should start the command prompt in the background (it should not show the cmd window), give inputs from my C# program and get the results redirected back to my C# application. I was googling around a bit and then came up with a solution.
Its damn [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I wanted to write a program in c# that should start the command prompt in the background (it should not show the cmd window), give inputs from my C# program and get the results redirected back to my C# application. I was googling around a bit and then came up with a solution.</p>
<p>Its damn simple. Usually to start any process from C# applications, we use the <em>Process </em>object. The process object has two properties called <strong>StandardInput </strong>and <strong>StandardOutput</strong>. These properties will allow the C# application to get the input stream of the process that needs to be started. So to mock inputs and outputs, we need to do the following,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Process aProcess <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Process<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
ProcessStartInfo aStartInfo <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ProcessStartInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
aStartInfo.<span style="color: #0000FF;">FileName</span> <span style="color: #008000;">=</span> Environment.<span style="color: #0000FF;">GetFolderPath</span><span style="color: #000000;">&#40;</span>Environment.<span style="color: #0000FF;">SpecialFolder</span>.<span style="color: #000000;">System</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\\</span>cmd.exe&quot;</span><span style="color: #008000;">;</span>
aProcess.<span style="color: #0000FF;">StartInfo</span> <span style="color: #008000;">=</span> aStartInfo<span style="color: #008000;">;</span>
aProcess.<span style="color: #0000FF;">StandardInput</span>.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;dir&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>  <span style="color: #008080; font-style: italic;">//will open a cmd process and feed the command &quot;dir&quot; to it</span></pre></div></div>

<p>By this way you could give inputs to a process that you start from C#. What if you wanna see output of the cmd prompt in your own prompt ?? For this we use the <strong>StandardOutput</strong> property. But there is yet another simple way to get the output from the command prompt. This is done by subscribing for the event, <strong>OutputDataReceived</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">aProcess.<span style="color: #0000FF;">OutputDataReceived</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> DataReceivedEventHandler<span style="color: #000000;">&#40;</span>Process_OutputDataReceived<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> Process_OutputDataReceived<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, DataReceivedEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  textBox1.<span style="color: #0000FF;">AppendText</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Data</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  textBox1.<span style="color: #0000FF;">AppendText</span><span style="color: #000000;">&#40;</span>Environment.<span style="color: #0000FF;">NewLine</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><strong>Note: These ways are possible only if, </strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">aProcess.<span style="color: #0000FF;">RedirectStandardOutput</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
aProcess.<span style="color: #0000FF;">UseShellExecute</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
aProcess.<span style="color: #0000FF;">BeginOutputReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>are set to the mentioned values. <strong>BeginOutputReadLine </strong>method will start async read operations from the C# application stream instead of the standard input devices. So next time you wanna clone a command prompt, start the cmd process and give your own look and feel to it.</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2009/08/31/accessing-command-prompt-from-c/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using NMock2 in C#</title>
		<link>http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/</link>
		<comments>http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 04:34:52 +0000</pubDate>
		<dc:creator>praseodeveloper</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[Testing]]></category>

		<category><![CDATA[unittest]]></category>

		<category><![CDATA[mocks]]></category>

		<category><![CDATA[nmocks]]></category>

		<guid isPermaLink="false">http://codelog.blogial.com/?p=442</guid>
		<description><![CDATA[As many would know, mocking is a useful and inevitable part of unit testing. The intention behind mocking of objects is to isolate the functionality of one method from its dependencies, For e.g. a method call from within the target test method being handled in an external interface.
This approach will help us focus on the [...]]]></description>
			<content:encoded><![CDATA[<p>As many would know, mocking is a useful and inevitable part of unit testing. The intention behind mocking of objects is to isolate the functionality of one method from its dependencies, For e.g. a method call from within the target test method being handled in an external interface.<br />
This approach will help us focus on the unit being tested, rather than arranging for dependency invocation (which might be really complex at times).<br />
I would like to share a basic tutorial here on mocking .net objects using NMock2 (available at http://nmock.org)</p>
<p>Steps to be followed are as follows.</p>
<p>1) Download the NMock2 package from <a href="http://nmock.org/download.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/nmock.org');" target="_blank">http://nmock.org/download.html</a></p>
<p>2) Create a console application and add NMock2.dll from the downloaded package, as a reference.</p>
<p>3) Consider that you have a simple interface defined as follows.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IPerson
<span style="color: #000000;">&#123;</span>
  <span style="color: #FF0000;">string</span> GetName<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>4) A class Hello has the following definition</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> Hello
<span style="color: #000000;">&#123;</span>
  IPerson person<span style="color: #008000;">;</span></pre></div></div>

<pre>  //--This method invokes the interface method.
  public String Greet()
  {
    return "Hello " + person.GetName();
    //If you were to write a ut for this method (without nmocks), you should have created an
    //actual object of person and your inputs should be capable of navigating
    //thru' GetName() of Person class
  }
}</pre>
<p>5) Our intention is to unit test the method Hello.Greet(). This is not straight forward as definition of IPerson.GetName() is not known. Moreover, it should not be of our concern when we are testing Greet() method&#8217;s functionality.</p>
<p>6) This is where we mock the Interface IPerson and hardcode a return value for the method GetName() so as to concentrate on the functionality of the method Greet() alone while testing. Let us see how we can do that.</p>
<p>7) We create a test case class, say HelloTestCases and write a method to test Greet()<br />
i) Make use of a class named Mockery (supplied by NMock2) to create a mock object.<br />
ii) Create a mocked interface object for IPerson using the NewMock() method.<br />
iii) Set up a mocked result  for any method/property by hardcoding of your choice.<br />
iv) Mock the result for one execution of the mocked method.<br />
v) Create an object of the target test class.<br />
vi) Invoke the target test method using the object instance created in (v) and check the results with Assert statements of NUnit.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Test_GreetPositive<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">//--i. Creating a mockery object.</span>
  Mockery personMock <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Mockery<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008080; font-style: italic;">//--ii. Mocking the IPerson interface using Mockery object.</span>
  IPerson p <span style="color: #008000;">=</span> personMock.<span style="color: #0000FF;">NewMock</span><span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span>IPerson<span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008080; font-style: italic;">//--iii. Setting the mocked return value.</span>
  <span style="color: #FF0000;">string</span> returnValue <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Pradeep&quot;</span><span style="color: #008000;">;</span>
  <span style="color: #008080; font-style: italic;">//--iv. Mocking the result for method call IPerson.GetName() method.</span>
  Expect.<span style="color: #0000FF;">Once</span>.<span style="color: #0000FF;">On</span><span style="color: #000000;">&#40;</span>p<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;GetName&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">WithNoArguments</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Will</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">Return</span>.<span style="color: #0000FF;">Value</span><span style="color: #000000;">&#40;</span>returnValue<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008080; font-style: italic;">//--v. Creating the target class object.</span>
  Hello h <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Hello<span style="color: #000000;">&#40;</span>p<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008080; font-style: italic;">//--vi. Invoking the target test method.</span>
  Assert.<span style="color: #0000FF;">AreEqual</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Hello Pradeep&quot;</span>,h.<span style="color: #0000FF;">Greet</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>So simple, isn&#8217;t it? This was a simple example. There is much more to add as feathers to NMock2.</p>
<p>NMock2 also provides a wide variety of Expectatons, like,</p>
<p><em>Expect.Once, Expect.Excatly(&lt;number of times a method is called&gt;), Stub (0 or many times), Expect.Never </em>and so on. You could also expect exceptions by adding an attribute called <em>[ExpectedException(typeof(&lt;exception class&gt;)] </em>before the unit test method for the target method that throws an exception. In other words, NMocks2 is really an awesome lib to do a perfect unit  test for your libraries. Try it out and share your experiences.</p>
<p>Thanks! See you all soon.<br />
Praseo</p>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2009/08/19/using-nmock2-in-c/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DoUNo: When to use StringFormatFlags.DirectionRightToLeft and StringAlignment.Far</title>
		<link>http://codelog.blogial.com/2009/07/07/douno-when-to-use-stringformatflagsdirectionrighttoleft-and-stringalignmentfar/</link>
		<comments>http://codelog.blogial.com/2009/07/07/douno-when-to-use-stringformatflagsdirectionrighttoleft-and-stringalignmentfar/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 03:35:35 +0000</pubDate>
		<dc:creator>sudarsanyes</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[DoUNo]]></category>

		<category><![CDATA[UI]]></category>

		<category><![CDATA[Graphics]]></category>

		<guid isPermaLink="false">http://codelog.blogial.com/?p=437</guid>
		<description><![CDATA[Recently I had a trouble displaying some values in a custom painted ListViewControl. I had to display some numbers right aligned. But I mistook this alignment with direction of the string, leading me to write the code as,

theArgs.Graphics.DrawString&#40;&#34;100&#34;,
FONT_ISOVALUE_VALUE, Brushes.Black,
new Point&#40;theArgs.Bounds.X + LOCATION_X_OFFSET, theArgs.Bounds.Y + LOCATION_Y_OFFSET&#41;,
new StringFormat&#40;StringFormatFlags.DirectionRightToLeft&#41;&#41;;

This was working properly for positive values, but for negative [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had a trouble displaying some values in a custom painted ListViewControl. I had to display some numbers <em>right aligned</em>. But I mistook this alignment with direction of the string, leading me to write the code as,</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">theArgs.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">DrawString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;100&quot;</span>,
FONT_ISOVALUE_VALUE, Brushes.<span style="color: #0000FF;">Black</span>,
<span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span>theArgs.<span style="color: #0000FF;">Bounds</span>.<span style="color: #0000FF;">X</span> <span style="color: #008000;">+</span> LOCATION_X_OFFSET, theArgs.<span style="color: #0000FF;">Bounds</span>.<span style="color: #0000FF;">Y</span> <span style="color: #008000;">+</span> LOCATION_Y_OFFSET<span style="color: #000000;">&#41;</span>,
<span style="color: #008000;">new</span> StringFormat<span style="color: #000000;">&#40;</span>StringFormatFlags.<span style="color: #0000FF;">DirectionRightToLeft</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>This was working properly for positive values, but for negative values, the - sign comes after the number. i.e., instead of -100, it was displayed as 100-, thats when I understood the difference between RightToLeft text and right aligned texts. So replacing the above snippet with the following snippet does the work.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">StringFormat aStringFormat <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringFormat<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
aStringFormat.<span style="color: #0000FF;">Alignment</span> <span style="color: #008000;">=</span> StringAlignment.<span style="color: #0000FF;">Far</span><span style="color: #008000;">;</span>
theArgs.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">DrawString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;-100&quot;</span>,
FONT_ISOVALUE_VALUE, Brushes.<span style="color: #0000FF;">Black</span>,
<span style="color: #008000;">new</span> Point<span style="color: #000000;">&#40;</span>theArgs.<span style="color: #0000FF;">Bounds</span>.<span style="color: #0000FF;">X</span> <span style="color: #008000;">+</span> LOCATION_X_OFFSET, theArgs.<span style="color: #0000FF;">Bounds</span>.<span style="color: #0000FF;">Y</span> <span style="color: #008000;">+</span> LOCATION_Y_OFFSET<span style="color: #000000;">&#41;</span>,
aStringFormat <span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<blockquote><p>So alignment is different and direction of text is different. Use <strong>StringFormat.Alignment </strong>for alignment and <strong>StringFormatFlags </strong>for direction</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://codelog.blogial.com/2009/07/07/douno-when-to-use-stringformatflagsdirectionrighttoleft-and-stringalignmentfar/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
