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

<channel>
	<title>Chris Johnston &#187; .NET</title>
	<atom:link href="http://www.fuzzylizard.com/archives/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fuzzylizard.com</link>
	<description>Web development and design with a little VFX thrown in for fun</description>
	<lastBuildDate>Sun, 30 Oct 2011 14:23:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Lessons Learned: Why Unit tests just won&#8217;t cut it</title>
		<link>http://www.fuzzylizard.com/archives/2008/07/17/955/</link>
		<comments>http://www.fuzzylizard.com/archives/2008/07/17/955/#comments</comments>
		<pubDate>Thu, 17 Jul 2008 07:13:47 +0000</pubDate>
		<dc:creator>Chris Johnston</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.fuzzylizard.com/?p=955</guid>
		<description><![CDATA[Over the last few days, I have had the wonderful experience of trying to implement a story just to find out, near the end, that nothing in it really worked. I had written unit tests and they all passed. My methods were hitting the dependencies and executing code exactly how I expected. And yet, my [...]]]></description>
			<content:encoded><![CDATA[<p>Over the last few days, I have had the wonderful experience of trying to implement a story just to find out, near the end, that nothing in it really worked. I had written unit tests and they all passed. My methods were hitting the dependencies and executing code exactly how I expected. And yet, my code wasn&#8217;t working. Worse was the fact that the code was throwing runtime exceptions preventing anything on the site from working.</p>
<p>The problem was that my code was trying to do a sort against data returned from a database call done via LING to SQL. And none of my unit tests exercised that call to the DB.</p>
<p>I was trying to generalized some sorts that I was doing through a builder class that returned a generic sort object. This sort object then performed that required sort on the Queryable. This meant that I had several methods like this:</p>
<pre name="code" class="c-sharp">
public Sort&lt;t&gt; BuildSort(string sortBy) {
    // some condition to figure out the proper sort
    return new Sort&lt;t&gt;(properSortMethod());
}
private Expression&lt;func &lt;User, object&gt;&gt; SortByName() {
    return user =&gt; user.Name;
}

private Expression&lt;func &lt;User, object&gt;&gt; SortByCreatedDate() {
    return user =&gt; user.CreatedDate;
}

private Expression&lt;func &lt;User, object&gt;&gt; SortByIsActive() {
    return user =&gt; user.IsActive;
}
</pre>
<p>The return value of each of these methods was then stored in a Sorts class which performs the sort.</p>
<pre name="code" class="c-sharp">
private Expression&lt;func &lt;User, object&gt;&gt; sort;

public Sort(Expression&lt;func &lt;User, object&gt;&gt; sort) {
    this.sort = sort;
}
public IQueryable&lt;t&gt; ApplySort(IQueryable&lt;t&gt; queryable) {
    return queryable.OrderBy(sort);
}
</pre>
<p>To me, this all makes sense. And when applied to an in memory Queryable list, it works fine. When applied to a database, it croaks.</p>
<p>I learned two lessons out of this: first, always code in small chunks and check those small chunks into Subversion and second, when dealing with database code, always do integration tests early.</p>
<p>For reference, the problem was that LINQ cannot create a Query when the second part of the Expression is set <code>object</code>. It needs to explicitly typed as <code>string</code>, <code>bool</code> or <code>DateTime?</code>. However, using the pattern above, I don&#8217;t know how to properly store the sort in such a way that each builder method can return a specific sort and have those applied using a general method. if anyone has any ideas, please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fuzzylizard.com/archives/2008/07/17/955/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Playing with C# 3.0 and .NET 3.5</title>
		<link>http://www.fuzzylizard.com/archives/2008/07/02/949/</link>
		<comments>http://www.fuzzylizard.com/archives/2008/07/02/949/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 05:00:28 +0000</pubDate>
		<dc:creator>Chris Johnston</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.fuzzylizard.com/?p=949</guid>
		<description><![CDATA[It has been quite a while since my last post. Mostly that is because I have been fairly busy with a new project and busy trying to get my sorry butt into shape (it is amazing how much time exercising can take up). Anyway, the new project uses C# 3.0 and .NET 3.5, ASP.NET MVC [...]]]></description>
			<content:encoded><![CDATA[<p>It has been quite a while since my last post. Mostly that is because I have been fairly busy with a new project and busy trying to get my sorry butt into shape (it is amazing how much time exercising can take up). Anyway, the new project uses C# 3.0 and .NET 3.5, <a href="http://www.asp.net/mvc/">ASP.NET MVC</a> and <a href="http://jquery.com/">jQuery</a>. All three are new to me and I have to say that I really like all three.</p>
<p>C# 3.0 is a really nice language. It seems to have gotten generics correct making for some really nice code, especially were the database layer is concerned. We are using LINQ to SQL and we have been able to implement a single class for the repository which works with whatever model object type we give it. I also really like the inclusion of Lambdas and delegates, which make for some very clean code constructs and are much cleaner then anonymous methods in Java.</p>
<p>The second new technology to me is <a href="http://www.asp.net/mvc/">ASP.NET MVC</a>. This allows us to do ASP.NET without actually using ASP.NET. Currently, it is still in preview releases, but it is definitely heading in the right direction. Everything (with the possible exception of views) is completely and easily testable. This means no more having to hide functionality behind presenters or controllers and hoping it works in the code behind. Controllers are completely testable right down to testing what views or redirects they return.</p>
<p>The last new thing I am using is <a href="http://jquery.com/">jQuery</a>. I fully understand why it is becoming the defacto Javascript library. To do most things only require a few lines of jQuery Javascript and its AJAX and JSON capabilities are incredible. One nice thing about ASP.NET MVC is that it is capable of returning JSON results with a single line of code. This makes working with <a href="http://jquery.com/">jQuery</a> seamless.</p>
<p>If you are starting a new .NET web project, definitely check out <a href="http://www.asp.net/mvc/">ASP.NET MVC</a>, C# 3.0 and <a href="http://jquery.com/">jQuery</a>. If you are new to C# 3.0 then check out the book <a href="http://www.manning.com/skeet/">C# in Depth</a>. It highlights all the changes since 1.1 in a nice concise format that will bring you up to speed quickly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fuzzylizard.com/archives/2008/07/02/949/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

