<?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: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/" version="2.0">

<channel>
	<title>chadly.net</title>
	
	<link>http://chadly.net</link>
	<description>Putting the C into C#</description>
	<lastBuildDate>Tue, 28 Feb 2012 18:41:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/chadly" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="chadly" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Creating NHibernate Linq Query from arbitrary Criteria</title>
		<link>http://chadly.net/2009/10/creating-nhibernate-linq-query-from-arbitrary-criteria/</link>
		<comments>http://chadly.net/2009/10/creating-nhibernate-linq-query-from-arbitrary-criteria/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 05:46:43 +0000</pubDate>
		<dc:creator>chad</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">/post/2009/10/30/Creating-NHibernate-Linq-Query-from-arbitrary-Criteria.aspx</guid>
		<description><![CDATA[I just added this gem to NHibernate.Linq (of the NHContrib variety – not to be confused with that other one).  I’ll let the test speak for itself: My specific reason for adding this has to do with a custom ICriterion (more on that later) I needed to use in one of our criteria queries that [...]]]></description>
			<content:encoded><![CDATA[<p>I just added this gem to NHibernate.Linq (of the NHContrib variety – not to be confused with <a href="http://blogs.imeta.co.uk/sstrong/archive/2009/10/22/791.aspx">that other one</a>).  I’ll let the test speak for itself:</p>
<pre class="brush: csharp; title: ; notranslate">
[Test]
public void can_create_linq_query_from_arbitrary_criteria_query()
{
    var criteria = session.CreateCriteria&lt;User&gt;();
    criteria.Add(Restrictions.Le(&quot;RegisteredAt&quot;, new DateTime(2000, 1, 1)));

    var query = session.Linq&lt;User&gt;(criteria)
        .Where(u =&gt; u.Name == &quot;nhibernate&quot; || u.Name == &quot;ayende&quot;);

    var list = query.ToList();
    Assert.AreEqual(1, list.Count);
    Assert.AreEqual(&quot;nhibernate&quot;, list.Single().Name);
}
</pre>
<p>My specific reason for adding this has to do with a custom ICriterion (more on that later) I needed to use in one of our criteria queries that I wanted to expose as an IQueryable.  This method of being able to build a linq query from an arbitrary criteria seemed to solve my problem rather elegantly.</p>
<p>Let me know if you think this is crazy or if you like.</p>
<p>As of now, it is available in the trunk r1099.</p>
]]></content:encoded>
			<wfw:commentRss>http://chadly.net/2009/10/creating-nhibernate-linq-query-from-arbitrary-criteria/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Many Pitfalls of NHibernate.Linq</title>
		<link>http://chadly.net/2009/08/the-many-pitfalls-of-nhibernate-linq/</link>
		<comments>http://chadly.net/2009/08/the-many-pitfalls-of-nhibernate-linq/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 08:54:40 +0000</pubDate>
		<dc:creator>chad</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">/post/2009/08/26/The-Many-Pitfalls-of-NHibernateLinq.aspx</guid>
		<description><![CDATA[Working with the recently released NHibernate.Linq is not without its (many) pitfalls.  In one of my current projects, we are using the specification pattern to build dynamic linq queries based off of persistable specification objects.  This has led to more than one hair-pulling session on the limitations of the current NH Linq provider.  For instance, [...]]]></description>
			<content:encoded><![CDATA[<p>Working with the <a href="http://chadly.net/post/2009/07/27/NHibernateLinq-10-is-out-and-about.aspx">recently released NHibernate.Linq</a> is not without its (many) pitfalls.  In one of my current projects, we are using the specification pattern to build dynamic linq queries based off of persistable specification objects.  This has led to more than one hair-pulling session on the limitations of the current NH Linq provider.  For instance, did you know that this query will work just fine:</p>
<pre class="brush: csharp; title: ; notranslate">
(from p in db.Patients
from r in p.PatientRecords
where r.Type.TypeCode == 7
select r).Sum(r =&gt; r.Amount);
</pre>
<p>yet, this query (which is equivalent) will blow up in your face:</p>
<pre class="brush: csharp; title: ; notranslate">
db.Patients.SelectMany(p =&gt; p.PatientRecords)
    .Where(r =&gt; r.Type.TypeCode == 7).Sum(r =&gt; r.Amount);
</pre>
<p>The reason it fails is very implementation-specific.  Under the covers, the C# compiler will convert that first query into an expression looking something like this:</p>
<pre class="brush: csharp; title: ; notranslate">
db.Patients.SelectMany(p =&gt; p.PatientRecords, (p, r) =&gt; new { p = p, r = r })
    .Where(pr =&gt; pr.r.Type.TypeCode == 7).Sum(pr =&gt; pr.r.Amount);
</pre>
<p>Our second query which uses the overload of SelectMany that doesn’t specify the result selector fails because NHibernate.Linq specifically requires that result selector in order to know which alias to use for that subcriteria for the rest of the query (yes, this is a really bad implementation and requires that you use the same lambda parameter names throughout your query).</p>
<p>Simple enough, let’s just drive around the pothole and explicitly state our parameter name by changing our second query to look like this:</p>
<pre class="brush: csharp; title: ; notranslate">
db.Patients.SelectMany(p =&gt; p.PatientRecords, (p, r) =&gt; r)
    .Where(r =&gt; r.Type.TypeCode == 7).Sum(r =&gt; r.Amount);
</pre>
<p>Ahh,explosions still abound.  That query will generate an error similar to: “Type is not an association” or “Could not resolve property: Type”.</p>
<p>It turns out,that NHibernate.Linq’s SelectMany support depends on that anonymous type leading the entity types in the query (pr.r in the compiled first query).  Without this leading anonymous type, the parser does not assign a subcriteria to that many-to-one traversal through r.Type.  That is highly upsetting because the query that we are writing is actually more like this:</p>
<pre class="brush: csharp; title: ; notranslate">
db.Patients.SelectMany(p =&gt; p.PatientRecords, (p, r) =&gt; r)
    .Where(specification.IsSatisfied()).Sum(r =&gt; r.Amount);
</pre>
<p>where specification.IsSatisfied() returns a dynamically generated Expression&lt;Func&lt;PatientRecord, bool&gt;&gt;.  I can’t rewrite those specifications to use some query-specific anonymous type and I shouldn’t have to.</p>
<p>On a mission, I fired up the NHibernate.Linq source code and hacked away at it until this specific scenario was supported.  There is still the limitation that you must use the second overload of SelectMany that accepts the result selector.  There is no way of easily getting around that with the current implementation based off of the Criteria API.  However, despite all of NHibernate.Linq’s shortcomings, my specifications now work just fine (running some pretty complex queries).</p>
<p>If you are having similar frustrations, go grab the <a href="https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/src/NHibernate.Linq/">latest trunk r1010</a>.</p>
<p>…until the next bug</p>
<p>P.S. I am very much looking forward to NH.Linq 2.0 using relinq and the new AST parser.</p>
]]></content:encoded>
			<wfw:commentRss>http://chadly.net/2009/08/the-many-pitfalls-of-nhibernate-linq/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>NHibernate.Linq 1.0 is out and about!</title>
		<link>http://chadly.net/2009/07/nhibernate-linq-1-0-is-out-and-about/</link>
		<comments>http://chadly.net/2009/07/nhibernate-linq-1-0-is-out-and-about/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 07:40:18 +0000</pubDate>
		<dc:creator>chad</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">/post/2009/07/27/NHibernateLinq-10-is-out-and-about.aspx</guid>
		<description><![CDATA[In case you haven’t heard, NHibernate.Linq v1.0 has been released.  This has been a long time in the making and Tuna has put the final touches on it to make it possible.  You can get the binaries from the NHibernate download area. Here are some informal release notes: The implementation uses the NHibernate Criteria API [...]]]></description>
			<content:encoded><![CDATA[<p>In case you haven’t heard, NHibernate.Linq v1.0 has been released.  This has been a long time in the making and Tuna has put the final touches on it to make it possible.  You can get the binaries from the <a href="http://sourceforge.net/projects/nhibernate/files/">NHibernate download area</a>.</p>
<p>Here are some informal release notes:</p>
<p>The implementation uses the NHibernate Criteria API under the covers, so anything it doesn’t support, NH.Linq won’t support.  Other things were just too hard to implement using the Criteria API.  Some major things this includes are group joins, subqueries in select clauses, and groupby.</p>
<p>However, despite that, limited subqueries are supported in the where clause.  Namely, using Count, Sum, Max, Min,Avg,and Any methods.  You can also use SelectMany queries (rather than GroupJoin) to do queries like this:</p>
<pre class="brush: csharp; title: ; notranslate">
from o in db.Orders
from ol in o.LineItems
where ol.Price &gt; 10
select o;
</pre>
<p>or this:</p>
<pre class="brush: csharp; title: ; notranslate">
from o in db.Orders
where o.LineItems.Any(ol =&gt; ol.Price &gt; 10)
select o;
</pre>
<p>All in all, it is a tried and tested implementation.  It has been used on number of projects in production for two years now.  As long as you know where the pitfalls are and how to avoid them, it is a useful addition to your NH toolkit.</p>
<p>Now, if you are saying to yourself, “well, that sucks, I really wanted to use GroupJoin and I want to nest other queries in my select clause.”  Fear not, this is where <a href="http://blogs.imeta.co.uk/sstrong/archive/2009/06/11/708.aspx">Steve Strong</a> and the <a href="http://www.re-motion.org/">re-linq guys</a> come in to save the day.  Steve has done <span style="text-decoration: line-through;">a lot of</span> all of the work on porting over the current HQL parser that is active in NHibernate 2.1.  The new linq implementation will interact with it natively (rather than use the Criteria API as an intermediary).  The current implementation has pretty much reached its upper limit on what it can do – limited by what the Criteria API can do.  The new implementation has much more grandiose plans than the current release.  It is the future, but, as most of us live in the present, <a href="http://sourceforge.net/projects/nhibernate/files/NHibernate/2.1.0.GA/NHibernate.Linq-1.0.0.GA-bin.zip/download">this release is now</a>.</p>
<p>For all intents and purposes, consider this a stopgap release.  Again, that doesn’t mean its not capable – just don’t expect major new features from this implementation.</p>
<p>Thanks to <a href="http://tunatoksoz.com/">Tuna</a> and <a href="http://ayende.com/">Oren</a> for pushing this release out the door.</p>
]]></content:encoded>
			<wfw:commentRss>http://chadly.net/2009/07/nhibernate-linq-1-0-is-out-and-about/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>We make shitty software (and so do you!)</title>
		<link>http://chadly.net/2009/07/we-make-shitty-software-and-so-do-you/</link>
		<comments>http://chadly.net/2009/07/we-make-shitty-software-and-so-do-you/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 05:34:04 +0000</pubDate>
		<dc:creator>chad</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">/post/2009/07/09/we-make-shitty-software-and-so-do-you.aspx</guid>
		<description><![CDATA[I just ran across this little gem and it made me laugh: An old software slogan at Living Videotext: &#34;We Make Shitty Software... With Bugs!&#34; It makes me laugh! We never ran this slogan in an ad. People wouldn''t understand. But it''s the truth. We make shitty software. And so do you! Software is a [...]]]></description>
			<content:encoded><![CDATA[<p>I just ran across this <a href="http://davenet.scripting.com/1995/09/03/wemakeshittysoftware">little gem</a> and it made me laugh:</p>
<blockquote><p>An old software slogan at Living Videotext: &quot;We Make Shitty Software... With Bugs!&quot; It makes me laugh! We never ran this slogan in an ad. People wouldn''t understand. But it''s the truth. We make shitty software. And so do you! </p>
<p>Software is a process, it''s never finished, it''s always evolving. That''s its nature. We know our software sucks. But it''s shipping! Next time we''ll do better, but even then it will be shitty. The only software that''s perfect is one you''re dreaming about. Real software crashes, loses data, is hard to learn and hard to use. But it''s a process. We''ll make it less shitty. Just watch! </p>
<p>Talking with an unhappy customer, first validate their belief that you''ve let them down. I agree that our software isn''t perfect. You won''t get an argument here. Let''s move on, find a workaround, a way to get your data back. And we promise to take a look at this problem and, if possible, fix it in the next release.</p>
</blockquote>
<p>And that is back from 1995.&#160; Wow, I was only 10 years old back then…</p>
]]></content:encoded>
			<wfw:commentRss>http://chadly.net/2009/07/we-make-shitty-software-and-so-do-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dependency Injection with NHibernate and Autofac</title>
		<link>http://chadly.net/2009/05/dependency-injection-with-nhibernate-and-autofac/</link>
		<comments>http://chadly.net/2009/05/dependency-injection-with-nhibernate-and-autofac/#comments</comments>
		<pubDate>Thu, 28 May 2009 08:38:46 +0000</pubDate>
		<dc:creator>chad</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">/post/2009/05/28/Dependency-Injection-with-NHibernate-and-Autofac.aspx</guid>
		<description><![CDATA[Fabio just recently committed changes to NHibernate which centralize all of NHibernate’s Activator.CreateInstance calls to an IObjectsFactory instance.  This is exciting because this gives us an opportunity to provide dependency injection services to all of those NHibernate-specific infrastructure types (IUserType, etc.). To give you a concrete example of what I am talking about, check back [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://fabiomaulo.blogspot.com">Fabio</a> just recently committed changes to NHibernate which centralize all of NHibernate’s Activator.CreateInstance calls to an IObjectsFactory instance.  This is exciting because this gives us an opportunity to provide dependency injection services to all of those NHibernate-specific infrastructure types (IUserType, etc.).</p>
<p>To give you a concrete example of what I am talking about, check back to <a href="http://ayende.com/Blog/archive/2008/07/31/Entities-dependencies-best-practices.aspx">Ayende’s EncryptedStringUserType</a>.  Rather than getting an instance of ICryptoProvider via a singleton accessor, it is now possible to have NHibernate inject the ICryptoProvider dependency through the constructor.  This is very valuable in cases where the ICryptoProvider has other dependencies or has some parameters that need to come from configuration.  You get full support from the container for that.</p>
<p>Fabio wrote up a post describing the <a href="http://fabiomaulo.blogspot.com/2009/05/nhibernate-ioc-integration.html">implementations for Castle and Spring</a>.  So, I thought I’d follow suit with an implementation for my new favorite container, <a href="http://code.google.com/p/autofac/">Autofac</a> (why it is my new favorite container will be a topic for another post).</p>
<p>To use it, make sure you are using the latest trunk of NHibernate.  Then, just add a reference in your project to Autofac.Integration.NHibernate.  At this time, the only way to configure the BytecodeProvider is programmatically.  So, <strong>BEFORE</strong> you call new NHibernate.Cfg.Configuration().Configure(), you need to set the BytecodeProvider to the AutofacBytecodeProvider.</p>
<pre class="brush: csharp; title: ; notranslate">
containerProvider = new ContainerProvider(builder.Build());

Environment.BytecodeProvider = new AutofacBytecodeProvider(
    containerProvider.ApplicationContainer, new ProxyFactoryFactory());
</pre>
<p>Then just enjoy the DI goodness integrated with NH.  If any type NHibernate needs is not registered with the container,it will fall back to creating the type with Activator.CreateInstance.</p>
<p><span style="text-decoration: line-through;">The code can be found here.  I am going to contact the Autofac guys and see about putting this into the Autofac.Contrib project.</span></p>
<p><strong>Update: </strong>This is now included in the <a href="http://code.google.com/p/autofac/downloads/list">Autofac.Contrib project</a> – <a href="http://code.google.com/p/autofac/source/browse/#svn/trunk/contrib/Source/AutofacContrib.NHibernate">check it out here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://chadly.net/2009/05/dependency-injection-with-nhibernate-and-autofac/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>BDD with xUnit.net</title>
		<link>http://chadly.net/2009/04/bdd-with-xunit-net/</link>
		<comments>http://chadly.net/2009/04/bdd-with-xunit-net/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 19:54:37 +0000</pubDate>
		<dc:creator>chad</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">/post/2009/04/20/BDD-with-xUnit.aspx</guid>
		<description><![CDATA[I’ve been looking a lot into Behavior Driven Development lately as a better way to structure my TDD tests.  If you’ve never heard of BDD, check here for an intro (or here for another good one).  What it boils down to is a way to organize and name your tests in a way that makes [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been looking a lot into Behavior Driven Development lately as a better way to structure my TDD tests.  If you’ve never heard of BDD, check here for <a href="http://www.lostechies.com/blogs/sean_chambers/archive/2008/12/07/starting-with-bdd-vs-starting-with-tdd.aspx">an intro</a> (or here for <a href="http://codebetter.com/blogs/ian_cooper/archive/2009/03/31/seizing-the-bdd-nettle.aspx">another good one</a>).  What it boils down to is a way to organize and name your tests in a way that makes it explicit what it is – an executable specification for what the code under test <em>should</em> do.</p>
<p>One particular quote that stood out in my mind when getting to know BDD was this:</p>
<blockquote><p>Language you use shapes how you think... and if you want to change how you think it can help to first change your language.</p></blockquote>
<p>It is true in that just changing seemingly insignificant things like the language and syntax of your tests can affect how you think about your tests and ultimately how and what tests you end up writing.</p>
<p>I set out to find a solution to help me start writing BDD-style tests (ehh, I mean specs) in an existing project which already used xUnit.net.  I really liked some of the things from <a href="http://code.google.com/p/specunit-net/">SpecUnit</a>, but I didn’t want to be tied to NUnit.  I also found the <a href="http://code.google.com/p/xunitbddextensions/">xUnit BDD Extensions</a> project on Google Code – but I took issue with some of the syntax with that.  Also, it seemed to be trying to do too much.  I just wanted simple BDD style integration with xUnit without any excess baggage.</p>
<p>One of the things I really like about xUnit (and the reason why I use it over MBUnit and NUnit) is its simplicity.  It is clean, elegant, and efficient at what it does.  It provides exactly what you need and nothing more.  It also makes use of native C# semantics for its syntax.  For instance, rather than relying on a TestSetup or TestTearDown attribute for a setup method to a test, it relies on C# constructors and the IDisposable interface to handle such things.  When writing test cases with this syntax, it feels much more natural.</p>
<p>Anyway, I ended up finding this <a href="http://iridescence.no/post/Extending-xUnit-with-a-Custom-ObservationAttribute-for-BDD-Style-Testing.aspx">BDD solution for xUnit</a> by Fredrik Kalseth.  This was almost exactly what I was looking for, except that I didn’t like having to override InitializeContext in my spec classes.  I wanted to include the context in the constructor of the class like normal xUnit test classes.</p>
<p>Also,some of my current test code relies on test base classes for some of its functionality – and I didn’t want to force my tests to inherit from a Specification class just to get BDD style testing done.</p>
<p>Last but not least,up until the latest 1.1 release of xUnit, the xunit.extensions assembly contained these nice .Net 3.5 extension methods for assertions in a very BDD style way.  It allowed you to write code like this:</p>
<pre class="brush: csharp; title: ; notranslate">customer.Email.ShouldEqual(&quot;test@example.com&quot;);</pre>
<p>With the latest release, however, these extension methods were deemed unworthy and moved to the xUnit Samples project.  Boo I say to you.  I want, neigh, <em>need</em> these extension methods back.</p>
<p>Long story short, I ended up taking elements from all three of these solutions along with the extension methods from the samples project and created my own.  I present to you <a href="http://code.google.com/p/xunit-bdd-extensions/">Chad’s version of xUnit BDD Extensions</a>.</p>
<p>Some of the design goals of this project:</p>
<ul>
<li>Use natural C# constructs to control things such as BDD contexts and concerns.  For example, the context of the specification is defined in the class constructor and the concern for the fixture is defined by its namespace.</li>
<li>Don’t force me to inherit from any base class to get BDD style tests working.  There is an interface ISpecification with one method Observe() to accomplish this.  A Specification base class is also provided for convenience.</li>
</ul>
<p>For completeness, I am including the cliché BDD example of an account transfer fixture using this framework.</p>
<pre class="brush: csharp; title: ; notranslate">
namespace Banking.Specs.FundsTransferSpecs
{
    public abstract class behaves_like_bank_account_transfer : Specification
    {
        protected readonly Account fromAccount;
        protected readonly Account toAccount;

        public behaves_like_bank_account_transfer()
        {
            fromAccount = new Account { Balance = 1m };
            toAccount = new Account { Balance = 1m };
        }
    }

    public class when_transferring_between_two_accounts
        : behaves_like_bank_account_transfer
    {
        protected override void Observe()
        {
            fromAccount.Transfer(1m, toAccount);
        }

        [Observation]
        public void should_debit_the_from_account_by_the_amount_transferred()
        {
            fromAccount.Balance.ShouldEqual(0m);
        }

        [Observation]
        public void should_credit_the_to_account_by_the_amount_transferred()
        {
            toAccount.Balance.ShouldEqual(2m);
        }
    }

    public class when_transfering_amount_greater_than_balance_of_from_account
        : behaves_like_bank_account_transfer
    {
        private Exception exception;

        protected override void Observe()
        {
            exception = ((MethodThatThrows)delegate
            {
                fromAccount.Transfer(2m, toAccount);
            })
            .GetException();
        }

        [Observation]
        public void should_not_allow_the_transfer()
        {
            exception.ShouldNotBeNull();
        }

        [Observation]
        public void should_raise_argument_out_of_range_exception()
        {
            exception.ShouldBeType&lt;ArgumentOutOfRangeException&gt;();
        }
    }
}

namespace Banking
{
    public class Account
    {
        public decimal Balance { get; set; }

        public void Transfer(decimal amount, Account toAccount)
        {
            if (amount &gt; Balance)
            {
                throw new ArgumentOutOfRangeException(&quot;amount&quot;, amount,
                    String.Format(@&quot;Cannot transfer ${0}.
                        The available balance is ${1}.&quot;, amount, Balance));
            }

            Balance -= amount;
            toAccount.Balance += amount;
        }
    }
}
</pre>
<p>Note the use of the namespace Banking.Specs.FundsTransferSpecs to denote the current concern – funds transfer.  Also note the use of how easily it is to reuse context setup code via constructor overrides.  Its nothing new as far as BDD goes, it just puts a nicer xUnit-style syntax on it.</p>
<p>It is a very simple project.  All credit goes to the authors of the previous three solutions.  I just cobbled together the best (at least what I think is the best) of those solutions.</p>
<p>The code for this (in cased you missed it before) can be found on the <a href="http://code.google.com/p/xunit-bdd-extensions/">BDD Extensions project on Google Code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://chadly.net/2009/04/bdd-with-xunit-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tortoise SVN Settings for Beyond Compare 3</title>
		<link>http://chadly.net/2009/04/tortoise-svn-settings-for-beyond-compare-3/</link>
		<comments>http://chadly.net/2009/04/tortoise-svn-settings-for-beyond-compare-3/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 05:33:56 +0000</pubDate>
		<dc:creator>chad</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">/post/2009/04/13/Tortoise-SVN-Settings-for-Beyond-Compare-3.aspx</guid>
		<description><![CDATA[This is for future reference for me – for some reason this is a huge pain in the ass for me to find whenever I need it. Here is the official documentation on how to integrate BC3 with TortoiseSVN. Here are my settings (on 64 bit machine): Diff Viewer "C:\Program Files (x86)\Beyond Compare 3\BComp.exe" %base [...]]]></description>
			<content:encoded><![CDATA[<p>This is for future reference for me – for some reason this is a huge pain in the ass for me to find whenever I need it.</p>
<p>Here is the official documentation on how to <a href="http://www.scootersoftware.com/support.php?c=kb_vcs.php">integrate BC3 with TortoiseSVN</a>.</p>
<p>Here are my settings (on 64 bit machine):</p>
<h4>Diff Viewer</h4>
<p>"C:\Program Files (x86)\Beyond Compare 3\BComp.exe" %base %mine /title1=%bname /title2=%yname /leftreadonly</p>
<p>Put the SAME THING for both “comparing different revisions of files” and “comparing different revisions of properties”.</p>
<h4>Merge Tool</h4>
<p>"C:\Program Files (x86)\Beyond Compare 3\BComp.exe" %mine %theirs %base %merged /title1=%yname /title2=%tname /title3=%bname /title4=%mname</p>
]]></content:encoded>
			<wfw:commentRss>http://chadly.net/2009/04/tortoise-svn-settings-for-beyond-compare-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developing with Passion</title>
		<link>http://chadly.net/2009/03/developing-with-passion/</link>
		<comments>http://chadly.net/2009/03/developing-with-passion/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 16:56:00 +0000</pubDate>
		<dc:creator>chad</dc:creator>
				<category><![CDATA[Personal]]></category>

		<guid isPermaLink="false">/post/2009/03/29/Developing-with-Passion.aspx</guid>
		<description><![CDATA[I was going through my feed reader today catching up on some of the blogs I read and I came across this post from Casey Charlton.&#160; I was pretty astonished when I read it &#8211; this coming from Mr. DDD.&#160; Not only that, but this is the second reference I&#8217;ve seen to software developers not [...]]]></description>
			<content:encoded><![CDATA[<p>I was going through my feed reader today catching up on some of the blogs I read and I came across <a href="http://devlicio.us/blogs/casey/archive/2009/03/29/job-satisfaction-and-making-the-world-a-better-place.aspx">this post</a> from Casey Charlton.&nbsp; I was pretty astonished when I read it &ndash; this coming from <a href="http://dddstepbystep.com/">Mr. DDD</a>.&nbsp; Not only that, but this is the <a href="http://twitter.com/jeremydmiller/status/1389628577">second reference</a> I&rsquo;ve seen to software developers not being happy with software development in the past few days.</p>
<p>It got me to thinking of how I feel about this whole software thing.&nbsp; I&rsquo;ve been on a <a href="/post/2009/03/09/Its-Tough-Times-Out-There.aspx">few interviews</a> recently and one comment that I received a few times that stuck out in my head was &ldquo;you are obviously very passionate about what you do.&rdquo;&nbsp; Hmm, does it really show that much? :,,)</p>
<p>I remember at one point in my life, I was dead-set on becoming an astronaut.&nbsp; I was going to go to <a href="http://www.erau.edu/">Embry-Riddle</a> for a degree in Aerospace Engineering &ndash; then I was going to join the Air Force and eventually become an astronaut and go out and fly in space.&nbsp; Ahh, I&rsquo;m not really sure what happened to those plans.</p>
<p>I ended up going to <a href="http://www.lsu.edu/">LSU</a> instead (mostly because I think I was too afraid of moving away from home) and I ended up majoring in Computer Engineering.&nbsp; I remember the reason I gave for picking Computer Engineering was that I was good at working with computers and I knew I <strong><em>definitely</em></strong> did not want to do something with software &ndash; I wanted to work with hardware.&nbsp; Ha!</p>
<p>At some point in college (near the beginning), I eventually found the need for money.&nbsp; I wanted to buy things and most people accepted money for the things I wanted.&nbsp; I didn&rsquo;t want to get a job &ndash; who the hell wants to do work?&nbsp; I eventually found that people would pay me to build websites for them.&nbsp; After all, I dabbled in HTML and Flash back then and enjoyed building little websites.&nbsp; This eventually lead to me learning PHP and later on .Net.</p>
<p>So I guess you could say I &ldquo;fell into&rdquo; the field.&nbsp; But, really, who hasn&rsquo;t &ldquo;fallen&rdquo; into whatever they are doing now?&nbsp; Who says when they are a little kid &ldquo;I want to write software when I grow up&rdquo; or &ldquo;I want to be an investment banker&rdquo; or &ldquo;I want to be a construction manager&rdquo;?&nbsp; No, you usually want to be a police man, or a fireman, or a doctor, or maybe even an astronaut when you are a kid.&nbsp; When it comes down to it, we all just do what we are good at.</p>
<p>I still feel like I could be a million different things.&nbsp; I used to love making little home videos (<a href="http://vimeo.com/user675031">still do actually</a>) &ndash; I could have worked somewhere in the movie industry.&nbsp; I definitely had the test scores and brains to be a doctor.&nbsp; I could have been a brain surgeon.&nbsp; I might have even joined the Air Force and flew a fighter jet.&nbsp; But I didn&rsquo;t do any of those things, I wrote some software instead.</p>
<p>Bottom line is that I don&rsquo;t see myself as a Software Developer.&nbsp; I spend most of my time writing software, but I still feed my interests for other things with my hobbies.&nbsp; I enjoy what I do and I am good at it.&nbsp; And <a href="http://www.archoninfosys.com/">some people</a> even pay me to do what I enjoy doing.&nbsp; What more can somebody ask for?</p>
]]></content:encoded>
			<wfw:commentRss>http://chadly.net/2009/03/developing-with-passion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Asp.Net MVC and Sealed Classes</title>
		<link>http://chadly.net/2009/03/asp-net-mvc-and-sealed-classes/</link>
		<comments>http://chadly.net/2009/03/asp-net-mvc-and-sealed-classes/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 14:05:10 +0000</pubDate>
		<dc:creator>chad</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">/post/2009/03/14/AspNet-MVC-and-Sealed-Classes.aspx</guid>
		<description><![CDATA[I just created a project from the Asp.Net MVC default template (yes, I am a little late to this game – sorry, I have been living happily with Monorail) and ran across this in the AccountController class: The FormsAuthentication type is sealed and contains static members, so it is difficult to unit test code that [...]]]></description>
			<content:encoded><![CDATA[<p>I just created a project from the Asp.Net MVC default template (yes, I am a little late to this game – sorry, I have been living happily with Monorail) and ran across this in the AccountController class:</p>
<blockquote><p>The FormsAuthentication type is sealed and contains static members, so it is difficult to unit test code that calls its members. The interface and helper class below demonstrate how to create an abstract wrapper around such a type in order to make the AccountController code unit testable.</p>
</blockquote>
<p>Ha, after experiencing the pain so many times in so many ways running into these sealed / internal classes when trying to unit test, I find it somewhat satisfying to see MS have to workaround their own issues.</p>
<p>I am just glad that it seems like the paradigm is finally shifting at Microsoft and that maybe, just maybe, we’ll start to see less internal sealed classes and more unit testable frameworks (unit testable from my – the user’s – point of view).</p>
]]></content:encoded>
			<wfw:commentRss>http://chadly.net/2009/03/asp-net-mvc-and-sealed-classes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Custom MonoRailHttpHandlerFactory to handle 404s gracefully</title>
		<link>http://chadly.net/2009/03/custom-monorailhttphandlerfactory-to-handle-404s-gracefully/</link>
		<comments>http://chadly.net/2009/03/custom-monorailhttphandlerfactory-to-handle-404s-gracefully/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 15:31:30 +0000</pubDate>
		<dc:creator>chad</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">/post/2009/03/10/Custom-MonorailHttpHandlerFactory-to-handle-404s-gracefully.aspx</guid>
		<description><![CDATA[Problem I need to display user-friendly 404 pages when a request is made for a controller that cannot be found.  Monorail provides a built-in way to handle this.  When faced with a request for a controller it cannot find, Monorail will look for a view named 404 in the rescues folder and render that.  That [...]]]></description>
			<content:encoded><![CDATA[<h3>Problem</h3>
<p>I need to display user-friendly 404 pages when a request is made for a controller that cannot be found.  Monorail provides a built-in way to handle this.  When faced with a request for a controller it cannot find, Monorail will look for a view named 404 in the rescues folder and render that.  That is good enough for most people, I guess.  It wasn''t good enough for me.  I needed my 404 view to use a layout (dynamically chosen based on some configuration settings) and to display some data.</p>
<p>To give you an example of what I am talking about, consider an ecommerce site.  When someone requests a page that doesn''t exist, you would want to show them a friendly error page that shows some featured products - some products that the user might be interested in.  We don''t want to turn the user away or show a sparsely populated page when our poor, unsuspecting user types a wrong URL.</p>
<p>First of all, I set out to use a <a href="http://justinram.wordpress.com/2009/01/09/monorail-custom-rescue-controller-irescuecontroller/">custom rescue controller</a> to solve all my problems.  Here is the relevant code:</p>
<pre class="brush: csharp; title: ; notranslate">
[Layout(&quot;Default&quot;)]
public class RescueController : SmartDispatcherController, IRescueController
{
    public void Rescue(Exception exception, IController controller, IControllerContext controllerContext)
    {
        if (Is404(exception))
        {
            Handle404();
            return;
        }

        RenderSharedView(&quot;rescues\\general&quot;, true);
    }

    private bool Is404(Exception ex)
    {
        var httpEx = ex as HttpException;
        var mrEx = ex as MonoRailException;

        return (httpEx != null &amp;&amp; httpEx.GetHttpCode() == 404)
            || (mrEx != null &amp;&amp; mrEx.HttpStatusCode.GetValueOrDefault() == 404);
    }

    public void Handle404()
    {
        BindFeaturedProductsToView();

        Response.StatusCode = 404;
        Response.StatusDescription = &quot;Not found&quot;;
        RenderSharedView(&quot;rescues\\404&quot;);
    }

    private void BindFeaturedProductsToView()
    {
        /* bind some data to the view here */
    }
}
</pre>
<p>I then append this little attribute to all of my controllers (or to the base class that all of my controllers inherit from - if you happen to have one of those...):</p>
<pre class="brush: csharp; title: ; notranslate">[Rescue(typeof(RescueController))]</pre>
<p>That actually got me 90% of the way there.  A request for an action that didn''t exist on any controller would now be handled by my custom RescueController which could attach a layout and bind any necessary data that the 404 view needs.</p>
<h3>The Devil is in the Details</h3>
<p>Back to the original problem of this post - I need to be able to show this same view (and render it with the same logic) when a request is made for a controller that does not exist.  After digging through the Monorail source code a bit, and after a lot of trial and error,I eventually found a way to accomplish this.  First of all,I had to make my Handle404 method on RescueController public so that it could be accessible via a URL.  Then I ended up sub-classing MonoRailHttpHandlerFactory to handle the case of a missing controller.</p>
<pre class="brush: csharp; title: ; notranslate">
public class CustomHttpHandlerFactory : MonoRailHttpHandlerFactory
{
    public override IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
    {
        IHttpHandler handler = base.GetHandler(context, requestType, url, pathTranslated);

        if (handler is NotFoundHandler)
        {
            //The default NotFoundHandler renders the 404 view in the
            //rescues folder if it finds one, otherwise it throws an exception.
            //We want to reuse our 404-handling logic in RescueController.
            context.RewritePath(&quot;~/rescue/handle404&quot;);
            return base.GetHandler(context, requestType, url, pathTranslated);
        }

        return handler;
    }
}
</pre>
<p>Note the use of context.RewritePath.  This keeps the requested URL the same in the user''s browser and simply reroutes the request internally to our RescueController.  We don''t want to just do a redirect to our RescueController as this would be very bad for SEO purposes.  We want to send a 404 status code to the user when they request our missing page - we just want to do it in a user-friendly way.</p>
<h3>Gotchas</h3>
<p>Make sure you update your web.config to use this new handler instead of the default Monorail one.  Also note that I am using routing to route <em>/rescue/handle404</em> to the Handle404 action on RescueController.  If you were not using routing, you could change that URL to <em>~/rescue/handle404.castle</em> or <em>~/rescue/handle404.rails</em> depending on your configuration.  Overall, I like this solution very much.  It is very <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a> and accomplishes everything I wanted to accomplish.</p>
]]></content:encoded>
			<wfw:commentRss>http://chadly.net/2009/03/custom-monorailhttphandlerfactory-to-handle-404s-gracefully/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

