<?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>NOthingyoumissed &#187; .NET</title>
	<atom:link href="http://georgemauer.net/blog/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://georgemauer.net/blog</link>
	<description>George Mauer is on the net</description>
	<lastBuildDate>Sat, 15 May 2010 16:13:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hey, I Think I&#8217;ve Invented a New Pattern</title>
		<link>http://georgemauer.net/blog/hey-i-think-ive-invented-a-new-pattern/</link>
		<comments>http://georgemauer.net/blog/hey-i-think-ive-invented-a-new-pattern/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 07:58:12 +0000</pubDate>
		<dc:creator>togakangaroo</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://georgemauer.net/blog/?p=119</guid>
		<description><![CDATA[Ok maybe not totally new, I am sure that its just a projection of something I once noticed subcionscioiusly in a F# project. But in the C# space, I&#8217;ve yet to see something quite like it.  
The problem is that programs are complicated.  I don&#8217;t tend to help the issue.  In a [...]]]></description>
			<content:encoded><![CDATA[<p>Ok maybe not totally new, I am sure that its just a projection of something I once noticed subcionscioiusly in a F# project. But in the C# space, I&#8217;ve yet to see something quite like it.  </p>
<p>The problem is that programs are complicated.  I don&#8217;t tend to help the issue.  In a flash I don&#8217;t hesitate to layer on additional complexity with domain models, frameworks, and complex infrastructures.  Entities, sevices, repositories and aggregate roots &#8211; they&#8217;re the tools that we reach for all too often.  That is not to say that Domain Driven Design is a poor paradigm &#8211; I&#8217;m a big fan &#8211; it&#8217;s just not always necessary.</p>
<p>Take for example a typical scenario. You are given an integer which uniquely identifies a customer and are asked to generate a report of all their orders, export it to a pdf file and return as a Stream.  My first impulse is to start with the customer and order objects, identify the bounded context, figure out the aggregate roots, start writing data access mapping code, and so on.  If I&#8217;m lucky, I only do this for a few hours before hearing the voice of an incorporeal Ted Neward yelling at me to <strong>STOP</strong>.  I was not asked to build a domain model, I do not need to keep track of state, there is no validation, or (much) business logic.  The problems that DDD is intended to solve are simply not present here.  I need to do one thing and one thing only, map an integer to a Stream!  </p>
<p>And yes, I do realize that this is exactly what the CQRS guys have been harping on for years.</p>
<p>My Solution:</p>
<p>Each of my last few projects has contained a very simple interface.</p>
<pre name="code" class="c-sharp">
public IMapper&lt;INPUT_TYPE, OUTPUT_TYPE&gt; {
  OUTPUT_TYPE Map(INPUT_TYPE obj);
}
</pre>
<p>Get it? Put in an integer, get back a Stream, what could be simpler?  Ok, maybe that&#8217;s too simple.  Any change at all would require modifying the implementation.  This is all that icky procedural programming stuff.  What about reusability, encapsulation, separation of concerns, and our other OO goodies?   Fortunately, we don&#8217;t have to give these up.  All we have to do is introduce a couple of obvious seams.  We no longer transform an integer directly to a Stream.  Instead we:</p>
<ol>
<li>Take the id and map it to a DataSet that contains the report data.</li>
<li>Map a DataSet to the appropriate fully built Crystal Reports ReportDocument.</li>
<li>Map a ReportDocument to a MemoryStream of a pdf file.</li>
</ol>
<pre name="code" class="c-sharp">
IMapper&lt;int, DataSet&gt; _dataProvider;
IMapper&lt;DataSet, ReportDocument&gt; _reportGenerator;
IMapper&lt;ReportDocument, Stream&gt; _pdfReportExporter;

public Stream GetCustomerReport(int customerId) {
  return _pdfReportExporter.Map(
           _reportGenerator.Map(
             _dataProvider.Map(customerId)));
}
</pre>
<p>Pretty nice huh?   Well not that nice.  If you&#8217;re a naming perfectionist like I this should make you shiver.  When it comes to maintainability, good intention-revealing namespace, class, and method names are worth a million unit tests and n-tier architectures.  Forget requirements docs and self-documenting code, proper naming is the number one tool for communicating our intent.</p>
<p>I lecture my team on this constantly and yet I allow myself the use of the the term &#8220;Map&#8221;?!  A generic term that could indicate anything except (unless you&#8217;re a cartographer) a concept from your ubiquitous langauge.  I should be ashamed.</p>
<p>We want to keep our generic IMapper interface though, it&#8217;s so slick, allows us to write minimal code and you you could easily imagine it coming in handy.  For example, perhaps as the domain itself becomes more complicated, it becomes useful to break our IMapper&lt;int, DataSet&gt; down further.<br />
 1. The integer is get mapped to a Customer entity.<br />
 2. This gets mapped to a ReportSpecification.<br />
 3. The ReportSpecification is evaluated and mapped to a StoredProcedureInvocation<br />
 4. The procedure is executed and finally returns our DataSet. </p>
<p>You could imagine all sorts of neat little tricks you could play with our IoC container &#8211; we could have it automatically link transforms together or subsitute out implemenations.  Simply by knowing that all these components transform one object to another we could configure automatic caching, deferred execution proxies, and so on.  All things that are made far easier because all transformations are achieved via IMapper.Map.</p>
<p>What we really need is a way to introduce aliases for the Map() method.  Preferably ones that depend on the input and output type.  So why sit there scratching our heads?  C# is a flexible enough language, let&#8217;s just let&#8217;s do that thing that I just said.</p>
<pre name="code" class="c-sharp">
public CustomerOrderReportGenerator : IMapper&lt;DataSet, ReportDocument&gt; {
  public ReportDocument Map(DataSet data) {
    // implementation
  }
}
public partial static class AliasExtensions {
  public static ReportDocument GenerateReportFrom(this IMapper&lt;ReportDocument, DataSet&gt; mapper, DataSet ds) {
    return mapper.Map(ds); }
}
</pre>
<p>And now we have aliases:</p>
<pre name="code" class="c-sharp">
  _pdfReportExporter.Export(
    _reportGenerator.GenerateReportFrom(
      _dataProvider.GetOrderDataFor(customerId)));
</pre>
<p>The poor readability of this bothers me.  The LISPers among us might not mind reading backwards through a stack of nested parentheses but as a fan of fluent interfaces I&#8217;d like to see my code read as close to natural english as possible.  </p>
<p>Same trick, now featuring double dispatch!</p>
<pre name="code" class="c-sharp">
public partial static class AliasExtensions {
  public static ReportDocument ComposeIntoReportUsing(this DataSet ds, IMapper&lt;ReportDocument, DataSet&gt; mapper) {
    return mapper.Map(ds); }
}
</pre>
<p>Allows us to do:</p>
<pre name="code" class="c-sharp">
  return _dataProvider
    .GetOrderDataFor(customerId)
    .ComposeIntoReportUsing(_reportGenerator)
    .ToStreamUsing(_pdfReportExporter);
</pre>
<p>And there you have it.  Nice, fluent, and composable. </p>
<p>What do you guys think?  <b>Aliased Maps</b> a good name?</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fgeorgemauer.net%2fblog%2fhey-i-think-ive-invented-a-new-pattern%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fgeorgemauer.net%2fblog%2fhey-i-think-ive-invented-a-new-pattern%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://georgemauer.net/blog/hey-i-think-ive-invented-a-new-pattern/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Re: What is Unit Testing?</title>
		<link>http://georgemauer.net/blog/re-what-is-unit-testing/</link>
		<comments>http://georgemauer.net/blog/re-what-is-unit-testing/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 01:04:02 +0000</pubDate>
		<dc:creator>togakangaroo</dc:creator>
				<category><![CDATA[ALT.Net]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[uint-testing]]></category>

		<guid isPermaLink="false">http://nothingyoumissed.wordpress.com/?p=22</guid>
		<description><![CDATA[In a post last month Zachariah Young posts that 
&#8230; unit tests &#8230; verify that the business logic is correct.  I believe that for it to be unit testing it has to use a testing framework like nunit or junit.
I say thar be dragons!  Tying your understanding of unit testing to a specific tool allows you to neatly sidestep [...]]]></description>
			<content:encoded><![CDATA[<p>In a post last month <a href="http://zachariahyoung.com/zy/post/2008/12/What-is-Unit-Testing.aspx">Zachariah Young posts</a> that </p>
<blockquote><p>&#8230; unit tests &#8230; verify that the business logic is correct.  I believe that for it to be unit testing it has to use a <a href="http://en.wikipedia.org/wiki/Test_harness">testing framework</a> like nunit or junit.</p></blockquote>
<p>I say thar be dragons!  Tying your understanding of unit testing to a specific tool allows you to neatly sidestep thinking about what<img class="  alignleft" style="margin-left:10px;margin-right:10px;border:2px solid black;" title="Thar be dragons" src="http://www.videogamesblogger.com/wp-content/uploads/2006/09/here-be-dragons.jpg" alt="Thar be dragons" width="180" height="180" />  testing actually does.  Additionally, you deny credit to an excellent tool like <a href="http://www.nunit.org/index.php">NUnit </a>by pigeonholing its purpose.</p>
<p>Consider for a minute what NUnit actually is.  Yes their own website claims that they are specifically a &#8220;unit testing framework for all&#8221; but what does it actually do?  In my opinion it is a framework for setting up an application&#8217;s state, executing code, and then asserting that the resulting state is as you expected. That&#8217;s pretty broad.  Way broader than the confines of mere unit testing.  </p>
<p>Take the excellent <a href="http://watin.sourceforge.net/">WatiN </a>or (no longer maintained) <a href="http://nunitasp.sourceforge.net/">NUnitASP </a>tools.  Both can be run using NUnit but neither is used to build a true unit test.  WatiN for example remote controls your browser to investigate how your page will react to certain stiumuli.  What unit does WatiN test?  Your Page_Load method?  Your page renderer?  Whether the viewstate persists that you had entered some text halfway up the page before submitting and the text is not cleared when your page returns with a validation error?  The localhost routing mechanism on your PC?  Or does it test the <a title="Integration Testing" href="http://en.wikipedia.org/wiki/Integration_testing">integration </a>of all of these?</p>
<p>I made the same exact mistake myself when I decided to &#8217;see what this TDD thing&#8217; is all about last April.  I ultimately had to delete my entire testing project after I came to the realization that each test bit off far too large a chunk making it utterly impossible to maintain once true refactoring started.  I nearly cried that day.</p>
<p>But out of the ashes I was reborn with what I hope (but don&#8217;t really expect) to be the final zen-like understanding of this unit testing thing.  The first aha moment was when I finally caved in and decided to learn <a href="http://ayende.com/projects/rhino-mocks.aspx">Rhino Mocks</a> and my understanding sharpened when I caved again and looked into the new <a href="http://ayende.com/Blog/archive/2008/05/16/Rhino-Mocks--Arrange-Act-Assert-Syntax.aspx">Rhino Mocks 3.5 AAA syntax.</a>  Overall the lesson seems to be that I&#8217;m always wrong and I will eventually give in on everything and like it.  My girlfriend will be happy to hear that.</p>
<p>Let me tell you how I understand unit testing now.  Imagine a room.  You are standing on the outside and can comunicate with its ouccupants through a two way loudspeaker.  This room is your unit &#8211; if it helps you can imagine the room as painted <a href="http://en.wikipedia.org/wiki/Black_box_testing">black</a>.  Now in testing you present your unit with a problem:</p>
<blockquote><p>Given that you are on 735 Bourbon St New Orleans, Louisiana how far is it to my grandmother&#8217;s house?</p></blockquote>
<p>I used to think that unit testing involved merely waiting for the answer:</p>
<blockquote><p>Your grandmother&#8217;s house is 1345 miles away and you haven&#8217;t visited in months you shmuck.</p></blockquote>
<p>Now I realize its more about everything else that is said.  <em>&#8220;Where does your grandmother live?&#8221;</em> and <em>&#8220;Can you be so kind as to  slip an atlas under the door?&#8221;</em> should definitely be questions that you hear over that loudspeaker.  If you&#8217;ve separated your resposibilities properly the unit will also require a calculator that given two points on a map can tell you the distance (the specific calculator implementation should depend on whether you intend to fly or use the highway system).  The unit might even request that you hang a <em>EnRouteToGrandmas = true</em> sign on the door.  </p>
<p>The point is that you&#8217;re not so concerned with the final answer as much as you are with the unit asking the right questions.  Afterall, without that information know that it could not possibly be doing what you mean for it to do!</p>
<p>And so I define unit testing as</p>
<blockquote><p>Verifying that given an input, a piece of code makes all the external requests that you would expect where the unit is small enough that the number of these can be enumerated with ease.</p></blockquote>
<p>Note that this definition does not necessitate automated testing and this is something that I again think is basically correct.  After all, a framework should not do anything that you cannot do for yourself.</p>
<p>The beautiful part is if you&#8217;re limiting the amount of requests that you&#8217;re going to expect &#8211; let&#8217;s say no more than four &#8211; <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">single responsibility</a> emerges almost all on its own.  After all, how much can a piece of code do if its not communicating with the external world?</p>
<p>So there you go, thats my understanding of unit testing.  I look forward to being proven wrong in the future and having to refactor everything all over again.  But until that time,  Zachariah, you&#8217;ve been blogo-served!</p>
<p><strong>Disclaimer</strong>:  I do not know Zachariah personally but he seems like a smart guy that is highly involved in the ALT.Net community.  I do not purport to be more knowledgeable than him in programming issues, I just disagree with him on this one point.</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fnothingyoumissed.wordpress.com%2f2009%2f01%2f15%2fre-what-is-unit-testing%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fnothingyoumissed.wordpress.com%2f2009%2f01%2f15%2fre-what-is-unit-testing%2f" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://georgemauer.net/blog/re-what-is-unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Let&#039;s try to start this nice and simple</title>
		<link>http://georgemauer.net/blog/lets-try-to-start-this-nice-and-simple/</link>
		<comments>http://georgemauer.net/blog/lets-try-to-start-this-nice-and-simple/#comments</comments>
		<pubDate>Sat, 03 May 2008 03:25:50 +0000</pubDate>
		<dc:creator>togakangaroo</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[lists]]></category>
		<category><![CDATA[todo]]></category>

		<guid isPermaLink="false">http://nothingyoumissed.wordpress.com/?p=4</guid>
		<description><![CDATA[So since I registered this blog name I have proven empirically that I am incapable of actually writing to it so I figure I&#8217;ll start simple &#8211; with a list.  And &#8211; because this is what i&#8217;ve been reading and thinking of a lot lately &#8211; its going to be programming related.  Weeee.   So here [...]]]></description>
			<content:encoded><![CDATA[<p>So since I registered this blog name I have proven empirically that I am incapable of actually writing to it so I figure I&#8217;ll start simple &#8211; with a list.  And &#8211; because this is what i&#8217;ve been reading and thinking of a lot lately &#8211; its going to be programming related.  Weeee.   So here we go.</p>
<p><strong>Technologies that I <em>HAVE</em> to learn:</strong></p>
<ul>
<li><a href="http://www.hibernate.org/">NHibernate</a> &#8211; The alt.net list, podcasts, and .NET blogs have been a buzz about this for so long that its barely even mentioned anymore, but yes, through argument and experience I&#8217;ve been convinced, dynamically generated SQL is the way to go.  Time to get a crackin&#8217;.</li>
<li><a href="http://docs.mbunit.com/">MbUnit</a> &#8211; Apparently that&#8217;s what a lot of the pros use and I want to  be a pro right?  Well, I&#8217;ve got the basic [TestFixture] &#8211; [Test] &#8211; [RowTest] stuff down but guys like <a href="http://haacked.com/">Phil Haack</a> have to love it for more than just a few neat features and a nice GUI right?  How about reading the documentation?  Also, what the fuck is Gallilo and how come I can&#8217;t get it to run?</li>
<li><a href="http://structuremap.sourceforge.net/Default.htm">StructureMap</a> or <a href="http://www.castleproject.org/container/gettingstarted/index.html">Castle Project</a> &#8211;  Inversion of Control / Dependency injection frameworks.  This is what you use if you want an extensible application.  And I do.</li>
<li>F# &#8211; A couple months ago, I realized that I kinda like programming in Javascript.  Apparently, I&#8217;m not the only person that thinks so..  I guess it was because I was finally starting to get an understanding of what this functional programming thing is all about.  And now that that I know, I like it!</li>
<li>And in a similar vein &#8211; <a href="http://jquery.com/">JQuery</a>. &#8211; Yeah, I&#8217;ve gotten some practice with this amazing toolbox in working with <a href="http://georgemauer.net">my personal site</a> and <a href="http://www.therootsofmusic">The Roots Of Music</a> and I think there&#8217;s something there.  I want more, a lot more.</li>
<li><a href="http://git.or.cz/" target="_blank">Git</a> or <a href="http://www.selenic.com/mercurial/wiki/" target="_blank">Mercurial</a> &#8211; Distributed Version Control Systems.  These seem to be the new thing in version control, no pressing need to switch from SVN, but I should start getting familiar with them.  It seems like for the time being, Mercurial is the shiznit.  Not sure if any of them have nice <a href="http://tortoisesvn.tigris.org/" target="_blank">TortoiseSVN</a>-style support though.</li>
<li><a href="http://www.typemock.com/Learn.html" target="_blank">TypeMock</a> &#8211; Commercial mocking software.  Type mocking is really just something that I need to learn about as I&#8217;ve run into the limits of non-mocking unit tests already.  I&#8217;ve heard this product is good in a few places and they have a good learning section the web-site as well as a free download version.  Could be worth trying it out.  As an alternative, we&#8217;ve also got <a href="http://www.codeproject.com/KB/dotnet/Rhino_Mocks_Version_20.aspx">Rhino Mocks</a> which is free.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://georgemauer.net/blog/lets-try-to-start-this-nice-and-simple/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
