<?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>MotoWilliams &#187; Continuous Improvement</title>
	<atom:link href="http://www.motowilliams.com/tag/continuous-improvement/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.motowilliams.com</link>
	<description>I&#039;m Trying, Honestly I Am...</description>
	<lastBuildDate>Mon, 07 Jun 2010 01:48:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Extension Methods:  Improving the quality of Life</title>
		<link>http://www.motowilliams.com/extension-methods-improving-the-quality-of-life/</link>
		<comments>http://www.motowilliams.com/extension-methods-improving-the-quality-of-life/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 07:25:22 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[Asp.Net MVC]]></category>
		<category><![CDATA[Continuous Improvement]]></category>
		<category><![CDATA[Extension Methods]]></category>

		<guid isPermaLink="false">http://www.motowilliams.com/?p=81</guid>
		<description><![CDATA[Extension methods, such a simple idea that can totally make the small things in your application or at least the un-DRY portions of it cleaner. AddModelError and Multiple ValidationResults Here is a simple example (taken from a custom model binder): foreach( var validationResult in validationResults ) { bindingContext.ModelState .AddModelError( validationResult.MemberNames.FirstOrDefault(), validationResult.ErrorMessage ); } not too bad, but when working in [...]]]></description>
			<content:encoded><![CDATA[<p><img class="imagefloatright" src="http://www.motowilliams.com/wp-content/uploads/2010/03/checkmark.png" alt="" /><br />
Extension methods, such a simple idea that can totally make the small things in your application or at least the un-<a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" target="_blank">DRY</a> portions of it cleaner.</p>
<h5>AddModelError and Multiple ValidationResults</h5>
<p>Here is a simple example (taken from a custom model binder):</p>
<div style="width:600px;">
<pre class="brush: csharp;">foreach( var validationResult in validationResults )
{
  bindingContext.ModelState
    .AddModelError( validationResult.MemberNames.FirstOrDefault(), validationResult.ErrorMessage );
}</pre>
</div>
<p>not too bad, but when working in a block of code where you might have a few instances of it you tend to see the noise a little bit.</p>
<p>How about a little reduction and also centralize some logic so your entire code base can leverage it?</p>
<pre class="brush: csharp;">bindingContext.ModelState.AddModelErrors(validationResults);</pre>
<p>Now that everything you thought was upright in the world is all in question, ok, not really &#8211; not even close.  In fact we&#8217;ve only saved three lines of code where such things are being used but I would argue if you try to keep small things like this in mind that over time your code base will start to reap the benefits.</p>
<p>Here is how I implemented the extension method.  Your mileage may vary.</p>
<pre class="brush: csharp;">
public static class ModelStateExtensions
{
    public static void AddModelErrors(this ModelStateDictionary values, IEnumerable&lt;ValidationResult&gt; validationResults)
    {
        foreach (var validationResult in validationResults)
            values.AddModelError(validationResult.MemberNames.FirstOrDefault(), validationResult.ErrorMessage);
    }
}
</pre>
<h5>DataAnnotations and the Validator class</h5>
<p>Another area that might not be Asp.net MVC specific is if you are using the DataAnnotaions directly on your models and you use the static Validator class to validation the model.  In this case the TryValidateObject is being used for the bool that is returned from the operation.</p>
<pre class="brush: csharp;">
ValidationContext validationContext = new ValidationContext( someEditModel, null, null );
List&lt;ValidationResult&gt; validationResults = new List&lt;ValidationResult&gt;();
bool isValid = Validator.TryValidateObject( someEditModel, validationContext, validationResults );
if( !isValid )
{
  //do something maybe ...
  bindingContext.ModelState.AddModelErrors(validationResults);
}
</pre>
<p>I think I prefer this a little more</p>
<pre class="brush: csharp;">
List&lt;ValidationResult&gt; validationResults = someEditModel.ValidateAnnotations();
if( validationResults.Count() &gt; 0 )
  bindingContext.ModelState.AddModelErrors(validationResults);
</pre>
<p>Where ValidateAnnotations is implemented as follows.  Also you if you prefer to change the where this can be used you can change the accessibility or change what this method extends to limit it&#8217;s exposure.</p>
<pre class="brush: csharp;">
public static class ValidationExtensions
{
    public static List&lt;ValidationResult&gt; ValidateAnnotations&lt;T&gt;(this T value) where T : class
    {
        if(value == null) return new List&lt;ValidationResult&gt;();

        var validationContext = new ValidationContext(value, null, null);
        var validationResults = new List&lt;ValidationResult&gt;();
        Validator.TryValidateObject(value, validationContext, validationResults, true);
        return validationResults;
    }
}
</pre>
<p>Hopefully these two little nuggets will help someone out.  Both of these are just a means to end, where I think that end is a transformation to a code base even beyond simple changes like this.  After all it is all about the journey not the destination.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.motowilliams.com/extension-methods-improving-the-quality-of-life/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C4MVC:  Reason #42 to Join</title>
		<link>http://www.motowilliams.com/c4mvc-reason-42-to-join/</link>
		<comments>http://www.motowilliams.com/c4mvc-reason-42-to-join/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 05:19:15 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[Asp.Net MVC]]></category>
		<category><![CDATA[Continuous Improvement]]></category>

		<guid isPermaLink="false">http://www.motowilliams.com/?p=64</guid>
		<description><![CDATA[What is C4MVC?  Well per the about us page it is: Our Vision is to share knowledge and best practices around using the framework, as well as encourage community contributions that serve the greater good. Through interactive sessions, projects, and aggregated blog feeds we hope to provide: A way for new developers to use the [...]]]></description>
			<content:encoded><![CDATA[<p><img class="imagefloatright" src="http://www.motowilliams.com/wp-content/uploads/2010/03/c4mvclogo.png" alt="" /></p>
<p>What is C4MVC?  Well per the about us page it is:</p>
<blockquote><p>Our Vision is to share knowledge and best practices around using the framework, as well as encourage community contributions that serve the greater good.</p>
<p>Through interactive sessions, projects, and aggregated blog feeds we hope to provide:</p>
<ul>
<li>A way for new developers to use the framework the right way.</li>
<li>Techniques and tools to allow experienced developers to develop with less friction.</li>
<li>A self supporting community.</li>
</ul>
</blockquote>
<p>Per my definition:</p>
<blockquote><p>A virtual user group on Wednesday mornings where I can listen in on the Asp.Net MVC big guns discuss the topic of the framework that I need to learn better.</p></blockquote>
<p><img class="imagefloatleft" src="http://www.motowilliams.com/wp-content/uploads/2010/03/somegrenade.png" alt="" /><br />
Besides the great free content such as last weeks<a href="http://www.c4mvc.net/Home/Events" target="_blank"> Advanced MVC2</a> topic sometimes, just sometimes, you can win some stuff.  In my case, I loves me some 30 day subscription to <a href="http://www.tekpub.com/" target="_blank">TekPub</a> which also happens to have a lengthy <a href="http://www.tekpub.com/preview/aspmvc" target="_blank">Asp.NET MVC series</a>. Now the only problem I have is finding the correct window to pull the pin this content grenade so that I can put together 30 days of <s>face melting guitar solo</s> mind melding content assimilation.  Parent of 3 (4 and under) makes that a <a href="http://www.davidco.com/what_is_gtd.php" target="_blank">GTD</a> challenge.</p>
<p>The C4MVC.NET (google) group is open to anyone to <a href="http://groups.google.com/group/c4mvc" target="_blank">join</a> so come and <a href="http://groups.google.com/group/c4mvc" target="_blank">join</a> the group to get some good nuggets of Asp.net MVC knowledge on!  No really, <a href="http://groups.google.com/group/c4mvc" target="_blank">join now</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.motowilliams.com/c4mvc-reason-42-to-join/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Testing, Just Do It!</title>
		<link>http://www.motowilliams.com/unit-testing-just-do-it/</link>
		<comments>http://www.motowilliams.com/unit-testing-just-do-it/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 02:27:50 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[Continuous Improvement]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://www.motowilliams.com/unit-testing-just-do-it/</guid>
		<description><![CDATA[I used to be the ConsoleApplication132 type of developer and no big surprise my projects didn’t have any unit tests in them, if any at all.&#160; To try and remedy this I took a 3 week TestProject1 challenge.&#160; Instead of doing quick spikes to a .NET console application to ‘try something out’ I spun up [...]]]></description>
			<content:encoded><![CDATA[<p>I used to be the ConsoleApplication132 type of developer and no big surprise my projects didn’t have any unit tests in them, if any at all.&#160; To try and remedy this I took a 3 week TestProject1 challenge.&#160; Instead of doing quick spikes to a .NET console application to ‘try something out’ I spun up a Test Project.</p>
<p><img class="imagefloatleft" title="bell" alt="bell" src="http://www.motowilliams.com/wp-content/uploads/2010/03/bell.jpg" width="150" height="143" /></p>
<p>So where am I now?&#160; Well my stuff has tests, but I’m in some bell curve of using Mocks improperly and over specifying my tests.&#160; I really like the naming style of BDD but flirted around with class name test method convention is about as deep as I have got into that realm so far.</p>
<p>… to be continued … over many years, I’m sure …</p>
]]></content:encoded>
			<wfw:commentRss>http://www.motowilliams.com/unit-testing-just-do-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
