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

<channel>
	<title>JG Vimalan&#039;s Blog</title>
	<atom:link href="https://jgvimalan.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://jgvimalan.wordpress.com</link>
	<description>its all about coding!</description>
	<lastBuildDate>Thu, 26 Jan 2012 01:44:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jgvimalan.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://s-ssl.wordpress.com/i/buttonw-com.png</url>
		<title>JG Vimalan&#039;s Blog</title>
		<link>https://jgvimalan.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://jgvimalan.wordpress.com/osd.xml" title="JG Vimalan&#039;s Blog" />
	<atom:link rel='hub' href='https://jgvimalan.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Remove empty values in string array</title>
		<link>https://jgvimalan.wordpress.com/2011/10/10/remove-empty-values-in-string-array/</link>
		<comments>https://jgvimalan.wordpress.com/2011/10/10/remove-empty-values-in-string-array/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 17:49:59 +0000</pubDate>
		<dc:creator>JG Vimalan</dc:creator>
				<category><![CDATA[C#.NET]]></category>

		<guid isPermaLink="false">http://jgvimalan.wordpress.com/?p=596</guid>
		<description><![CDATA[I got a task where I need to read values from a text file which are separated by line break \r\n. When I read the file using C#, I found empty entry after each element with value. Here is the code block, TextReader fileReader = new StreamReader(@&#8221;C:\members.txt&#8221;); string fileText = fileReader.ReadToEnd(); char[] newLineChar = Environment.NewLine.ToCharArray(); string[] memberIds [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgvimalan.wordpress.com&amp;blog=8798048&amp;post=596&amp;subd=jgvimalan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I got a task where I need to read values from a text file which are separated by line break \r\n.</p>
<p>When I read the file using C#, I found empty entry after each element with value. Here is the code block,</p>
<p>TextReader fileReader = new StreamReader(@&#8221;C:\members.txt&#8221;);</p>
<p>string fileText = fileReader.ReadToEnd();</p>
<p>char[] newLineChar = Environment.NewLine.ToCharArray();</p>
<p>string[] memberIds = fileText.Split(newLineChar, StringSplitOptions.RemoveEmptyEntries);</p>
<p>In order to remove the empty elements, in the Split method, I passed the  StringSplitOptions.RemoveEmptyEntries, which gave the desired result.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgvimalan.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgvimalan.wordpress.com/596/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgvimalan.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgvimalan.wordpress.com/596/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgvimalan.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgvimalan.wordpress.com/596/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgvimalan.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgvimalan.wordpress.com/596/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgvimalan.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgvimalan.wordpress.com/596/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgvimalan.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgvimalan.wordpress.com/596/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgvimalan.wordpress.com/596/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgvimalan.wordpress.com/596/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgvimalan.wordpress.com&amp;blog=8798048&amp;post=596&amp;subd=jgvimalan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://jgvimalan.wordpress.com/2011/10/10/remove-empty-values-in-string-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/67d5c0dc003686af14e4f74e2571af91?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgvimalan</media:title>
		</media:content>
	</item>
		<item>
		<title>Cannot bind to the new display member. Parameter name: newDisplayMember</title>
		<link>https://jgvimalan.wordpress.com/2011/09/27/cannot-bind-to-the-new-display-member-parameter-name-newdisplaymember/</link>
		<comments>https://jgvimalan.wordpress.com/2011/09/27/cannot-bind-to-the-new-display-member-parameter-name-newdisplaymember/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 22:34:26 +0000</pubDate>
		<dc:creator>JG Vimalan</dc:creator>
				<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Windows Forms]]></category>

		<guid isPermaLink="false">http://jgvimalan.wordpress.com/?p=587</guid>
		<description><![CDATA[I got this error when I was trying to bind datasource in a combobox and set values in the &#8216;DisplayMember&#8217; and &#8216;ValueMember&#8217;. Here is the code snippet, public class ClinicInfo { internal string ClinicID { get; set; } internal string ClinicName { get; set; } public override string ToString() { return ClinicName; } } //Code for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgvimalan.wordpress.com&amp;blog=8798048&amp;post=587&amp;subd=jgvimalan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I got this error when I was trying to bind datasource in a combobox and set values in the &#8216;DisplayMember&#8217; and &#8216;ValueMember&#8217;.</p>
<p><a href="http://jgvimalan.files.wordpress.com/2011/09/err.png"><img class="alignnone size-medium wp-image-588" title="err" src="http://jgvimalan.files.wordpress.com/2011/09/err.png?w=300&#038;h=167" alt="" width="300" height="167" /></a></p>
<p>Here is the code snippet,</p>
<p>public class ClinicInfo<br />
{<br />
internal string ClinicID { get; set; }<br />
internal string ClinicName { get; set; }</p>
<p>public override string ToString()<br />
{<br />
return ClinicName;<br />
}<br />
}</p>
<p>//Code for binding the data into ComboBox</p>
<p>IEnumerable&lt;ClinicInfo&gt; clinics = DBGateway.GetActiveClinics();</p>
<p>ClinicCmbBox.DataSource = clinics;<br />
ClinicCmbBox.ValueMember = &#8220;ClinicID&#8221;;<br />
ClinicCmbBox.DisplayMember = &#8220;ClinicName&#8221;;</p>
<p>Everything was looking good except the Access Modifiers (internal) for the properties in ClinicInfo class.</p>
<p>When I changed that to public as shown below, everything worked fine.</p>
<p>public string ClinicID { get; set; }<br />
public string ClinicName { get; set; }</p>
<p>So, the properties you are setting in &#8216;ValueMember&#8217; and &#8216;DisplayMember&#8217; should be public.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgvimalan.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgvimalan.wordpress.com/587/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgvimalan.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgvimalan.wordpress.com/587/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgvimalan.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgvimalan.wordpress.com/587/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgvimalan.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgvimalan.wordpress.com/587/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgvimalan.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgvimalan.wordpress.com/587/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgvimalan.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgvimalan.wordpress.com/587/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgvimalan.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgvimalan.wordpress.com/587/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgvimalan.wordpress.com&amp;blog=8798048&amp;post=587&amp;subd=jgvimalan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://jgvimalan.wordpress.com/2011/09/27/cannot-bind-to-the-new-display-member-parameter-name-newdisplaymember/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/67d5c0dc003686af14e4f74e2571af91?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgvimalan</media:title>
		</media:content>

		<media:content url="http://jgvimalan.files.wordpress.com/2011/09/err.png?w=300" medium="image">
			<media:title type="html">err</media:title>
		</media:content>
	</item>
		<item>
		<title>Binding DirectoryInfo in TreeView</title>
		<link>https://jgvimalan.wordpress.com/2011/09/26/binding-directoryinfo-in-treeview/</link>
		<comments>https://jgvimalan.wordpress.com/2011/09/26/binding-directoryinfo-in-treeview/#comments</comments>
		<pubDate>Mon, 26 Sep 2011 06:56:01 +0000</pubDate>
		<dc:creator>JG Vimalan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#.NET]]></category>

		<guid isPermaLink="false">http://jgvimalan.wordpress.com/?p=584</guid>
		<description><![CDATA[The following code block will give an idea on binding directoryinfo in TreeView control. protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadLeftNav(); } } private void LoadLeftNav() { string root = @&#8221;D:\Projects&#8221;; DirectoryInfo rootDirectory = new DirectoryInfo(root); TreeNode rootNode = new TreeNode(rootDirectory.Name); rootNode.Value = rootDirectory.FullName; rootNode.ToolTip = rootDirectory.Name; TreeView1.Nodes.Add(rootNode); LoadOcean(rootNode, rootDirectory); } [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgvimalan.wordpress.com&amp;blog=8798048&amp;post=584&amp;subd=jgvimalan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The following code block will give an idea on binding directoryinfo in TreeView control.</p>
<p>protected void Page_Load(object sender, EventArgs e)<br />
{<br />
if (!IsPostBack)<br />
{<br />
LoadLeftNav();<br />
}<br />
}</p>
<p>private void LoadLeftNav()<br />
{<br />
string root = @&#8221;D:\Projects&#8221;;<br />
DirectoryInfo rootDirectory = new DirectoryInfo(root);<br />
TreeNode rootNode = new TreeNode(rootDirectory.Name);<br />
rootNode.Value = rootDirectory.FullName;<br />
rootNode.ToolTip = rootDirectory.Name;<br />
TreeView1.Nodes.Add(rootNode);<br />
LoadOcean(rootNode, rootDirectory);<br />
}</p>
<p>private void LoadProjects(TreeNode rootNode, DirectoryInfo rootDirectory)<br />
{<br />
DirectoryInfo[] compaines = rootDirectory.GetDirectories();</p>
<p>foreach (DirectoryInfo company in compaines)<br />
{<br />
TreeNode node = new TreeNode(company.Name);<br />
node.Value = company.FullName;<br />
rootNode.ChildNodes.Add(node);<br />
node.ToolTip = company.Name;<br />
this.LoadOcean(node, company);<br />
}<br />
}</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgvimalan.wordpress.com/584/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgvimalan.wordpress.com/584/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgvimalan.wordpress.com/584/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgvimalan.wordpress.com/584/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgvimalan.wordpress.com/584/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgvimalan.wordpress.com/584/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgvimalan.wordpress.com/584/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgvimalan.wordpress.com/584/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgvimalan.wordpress.com/584/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgvimalan.wordpress.com/584/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgvimalan.wordpress.com/584/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgvimalan.wordpress.com/584/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgvimalan.wordpress.com/584/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgvimalan.wordpress.com/584/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgvimalan.wordpress.com&amp;blog=8798048&amp;post=584&amp;subd=jgvimalan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://jgvimalan.wordpress.com/2011/09/26/binding-directoryinfo-in-treeview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/67d5c0dc003686af14e4f74e2571af91?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgvimalan</media:title>
		</media:content>
	</item>
		<item>
		<title>The communication object, System.ServiceModel.ChannelFactory&#8230;, cannot be used for communication because it is in the Faulted state.</title>
		<link>https://jgvimalan.wordpress.com/2011/09/08/the-communication-object-system-servicemodel-channelfactory-cannot-be-used-for-communication-because-it-is-in-the-faulted-state/</link>
		<comments>https://jgvimalan.wordpress.com/2011/09/08/the-communication-object-system-servicemodel-channelfactory-cannot-be-used-for-communication-because-it-is-in-the-faulted-state/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 18:42:09 +0000</pubDate>
		<dc:creator>JG Vimalan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://jgvimalan.wordpress.com/?p=578</guid>
		<description><![CDATA[I got the error message (The communication object, System.ServiceModel.ChannelFactory&#8230;, cannot be used for communication because it is in the Faulted state.) in the production system, which was working fine for months. I found that, the WCF service is up and running and it is able to connect to database and is connected to the application [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgvimalan.wordpress.com&amp;blog=8798048&amp;post=578&amp;subd=jgvimalan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I got the error message (The communication object, System.ServiceModel.ChannelFactory&#8230;, cannot be used for communication because it is in the Faulted state.) in the production system, which was working fine for months. I found that, the WCF service is up and running and it is able to connect to database and is connected to the application as well. So, to fix this issue I followed the steps given below.</p>
<p>a. Stop the application pool of the application which is consuming the WCF service.</p>
<p>b. Browse to the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files</p>
<p>c. Delete the temp folder of the application which is using the WCF service. (The reason is, even though you restart IIS, the corrupted files will be here and it will cause the issue)</p>
<p>e. Start the application pool.</p>
<p>That&#8217;s it! This resolved my issue and the application started to work normally. Although, I am not clear on what exactly happened to cause this issue, I found the solution.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgvimalan.wordpress.com/578/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgvimalan.wordpress.com/578/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgvimalan.wordpress.com/578/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgvimalan.wordpress.com/578/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgvimalan.wordpress.com/578/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgvimalan.wordpress.com/578/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgvimalan.wordpress.com/578/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgvimalan.wordpress.com/578/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgvimalan.wordpress.com/578/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgvimalan.wordpress.com/578/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgvimalan.wordpress.com/578/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgvimalan.wordpress.com/578/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgvimalan.wordpress.com/578/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgvimalan.wordpress.com/578/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgvimalan.wordpress.com&amp;blog=8798048&amp;post=578&amp;subd=jgvimalan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://jgvimalan.wordpress.com/2011/09/08/the-communication-object-system-servicemodel-channelfactory-cannot-be-used-for-communication-because-it-is-in-the-faulted-state/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/67d5c0dc003686af14e4f74e2571af91?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgvimalan</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting css class with javascript</title>
		<link>https://jgvimalan.wordpress.com/2011/09/06/setting-css-class-with-javascript/</link>
		<comments>https://jgvimalan.wordpress.com/2011/09/06/setting-css-class-with-javascript/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 00:11:07 +0000</pubDate>
		<dc:creator>JG Vimalan</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://jgvimalan.wordpress.com/?p=575</guid>
		<description><![CDATA[In this post, I am going to explain about setting css class for controls using javascript. The following javascript will give you an idea of setting css class to a control for IE and other browsers. //Javascript var anchl = document.getElementById(&#8216;largeFontSwitch&#8217;); //Id of the control //Remove class anchl.setAttribute(&#8220;class&#8221;, &#8220;&#8221;); //Other browsers anchl.className = &#8220;&#8221;; //IE [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgvimalan.wordpress.com&amp;blog=8798048&amp;post=575&amp;subd=jgvimalan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this post, I am going to explain about setting css class for controls using javascript.</p>
<p>The following javascript will give you an idea of setting css class to a control for IE and other browsers.</p>
<p>//Javascript</p>
<p>var anchl = document.getElementById(&#8216;largeFontSwitch&#8217;); //Id of the control</p>
<p>//Remove class<br />
anchl.setAttribute(&#8220;class&#8221;, &#8220;&#8221;); //Other browsers<br />
anchl.className = &#8220;&#8221;; //IE</p>
<p>//Set class</p>
<p>anchl.setAttribute(&#8220;class&#8221;, &#8220;selectedFont&#8221;); //Other browsers<br />
anchl.className = &#8220;selectedFont&#8221;; //IE</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgvimalan.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgvimalan.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgvimalan.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgvimalan.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgvimalan.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgvimalan.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgvimalan.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgvimalan.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgvimalan.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgvimalan.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgvimalan.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgvimalan.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgvimalan.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgvimalan.wordpress.com/575/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgvimalan.wordpress.com&amp;blog=8798048&amp;post=575&amp;subd=jgvimalan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://jgvimalan.wordpress.com/2011/09/06/setting-css-class-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/67d5c0dc003686af14e4f74e2571af91?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgvimalan</media:title>
		</media:content>
	</item>
		<item>
		<title>Unit test for Http Handler</title>
		<link>https://jgvimalan.wordpress.com/2011/08/30/unit-test-for-http-handler/</link>
		<comments>https://jgvimalan.wordpress.com/2011/08/30/unit-test-for-http-handler/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 22:27:03 +0000</pubDate>
		<dc:creator>JG Vimalan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[VS 2010]]></category>

		<guid isPermaLink="false">http://jgvimalan.wordpress.com/?p=564</guid>
		<description><![CDATA[In this post, I will discuss about creating unit tests for http handlers. The functionality of my http handler is, it receives request from an ASP.NET page, processes it and sends back a response . When I right clicked the &#8216;Process Request&#8217; method in Http Handler and selected &#8216;Create unit tests&#8230;&#8217;, Visual Studio created unit [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgvimalan.wordpress.com&amp;blog=8798048&amp;post=564&amp;subd=jgvimalan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this post, I will discuss about creating unit tests for http handlers.</p>
<p>The functionality of my http handler is, it receives request from an ASP.NET page, processes it and sends back a response .</p>
<p>When I right clicked the &#8216;Process Request&#8217; method in Http Handler and selected &#8216;Create unit tests&#8230;&#8217;, Visual Studio created unit test methods for me. But, when I tried to run those tests, I got the following error message, &#8220;The test adapter &#8216;WebHostAdapter&#8217; threw an exception while running test&#8230;&#8221;.</p>
<p>So, the elegant way I can think of testing my custom http handler is, post data to the http handler url using HttpWebRequest and get the response back using HttpWebResponse.</p>
<p>Here is the unit test which I have written and it is working perfectly,</p>
<p><span style="color:#000000;">[TestMethod]</span><br />
<span style="color:#000000;"> public void AuthTest()</span><br />
<span style="color:#000000;"> {</span><br />
<span style="color:#000000;"> ASCIIEncoding encoding = new ASCIIEncoding();</span><br />
<span style="color:#000000;"> string postData = postData += (&#8220;&amp;username=&#8221; + &#8220;<a href="mailto:testuser@gmail.com"><span style="color:#000000;">testuser@gmail.com</span></a>&#8220;);</span><br />
<span style="color:#000000;"> postData += (&#8220;&amp;password=&#8221; + &#8220;testpassword&#8221;);</span></p>
<p><span style="color:#000000;">byte[] data = encoding.GetBytes(postData);</span></p>
<p><span style="color:#000000;">HttpWebRequest myRequest =</span><br />
<span style="color:#000000;"> (HttpWebRequest)WebRequest.Create(&#8220;<a href="https://customerdemoserver/WebApplication2/Auth.ashx"><span style="color:#000000;">https://customerdemoserver/WebApplication2/Auth.ashx</span></a>&#8220;);</span><br />
<span style="color:#000000;"> myRequest.Method = &#8220;POST&#8221;;</span><br />
<span style="color:#000000;"> myRequest.ContentType = &#8220;application/x-www-form-urlencoded&#8221;;</span><br />
<span style="color:#000000;"> myRequest.ContentLength = data.Length;</span><br />
<span style="color:#000000;"> myRequest.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;</span></p>
<p><span style="color:#000000;">Stream newStream = myRequest.GetRequestStream();</span></p>
<p><span style="color:#000000;">newStream.Write(data, 0, data.Length);</span><br />
<span style="color:#000000;"> newStream.Close();</span></p>
<p><span style="color:#000000;">HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();</span><br />
<span style="color:#000000;"> Stream stream = myResponse.GetResponseStream();</span><br />
<span style="color:#000000;"> StreamReader reader = new StreamReader(stream);</span><br />
<span style="color:#000000;"> string result = reader.ReadToEnd();</span></p>
<p><span style="color:#000000;">Assert.IsNotNull(result);</span><br />
<span style="color:#000000;"> }</span></p>
<p>Now, I am able to verify the functionality of my custom http handler, using the above unit test.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jgvimalan.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jgvimalan.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jgvimalan.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jgvimalan.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jgvimalan.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jgvimalan.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jgvimalan.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jgvimalan.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jgvimalan.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jgvimalan.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jgvimalan.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jgvimalan.wordpress.com/564/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jgvimalan.wordpress.com/564/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jgvimalan.wordpress.com/564/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jgvimalan.wordpress.com&amp;blog=8798048&amp;post=564&amp;subd=jgvimalan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://jgvimalan.wordpress.com/2011/08/30/unit-test-for-http-handler/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/67d5c0dc003686af14e4f74e2571af91?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jgvimalan</media:title>
		</media:content>
	</item>
	</channel>
</rss>
