<?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>Elegant Code &#187; Richard Cirerol</title>
	<atom:link href="http://elegantcode.com/author/rcirerol/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Sat, 11 Feb 2012 04:39:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>New Open Source Project: OptionStrict.oEmbed</title>
		<link>http://elegantcode.com/2011/07/15/new-open-source-project-optionstrict-oembed/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=new-open-source-project-optionstrict-oembed</link>
		<comments>http://elegantcode.com/2011/07/15/new-open-source-project-optionstrict-oembed/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 21:48:12 +0000</pubDate>
		<dc:creator>Richard Cirerol</dc:creator>
				<category><![CDATA[Esoterica]]></category>

		<guid isPermaLink="false">http://elegantcode.com/?p=4435</guid>
		<description><![CDATA[My friend, former colleague, and fellow Elegant Coder, Cory Isakson, has graciously allowed me to open source his .NET oEmbed library. Cory and I have been using this library for about two years, and a derivative of the library has been in production at an internet media company for nearly as long. The library is [...]]]></description>
			<content:encoded><![CDATA[<p>My friend, former colleague, and fellow Elegant Coder, Cory Isakson, has graciously allowed me to open source his .NET oEmbed library. Cory and I have been using this library for about two years, and a derivative of the library has been in production at an internet media company for nearly as long.</p>
<p>The library is hosted on GitHub at:</p>
<p><a href="https://github.com/codeprogression-opensource/OptionStrict.oEmbed"><strong>https://github.com/codeprogression-opensource/OptionStrict.oEmbed</strong></a></p>
<p>As far as I know, there is only one other open-source oEmbed library available for .NET. It is written in VB.NET and is hosted on CodePlex at:</p>
<p><a href="http://oembed.codeplex.com">http://oembed.codeplex.com</a></p>
<p>For the uninitiated:</p>
<blockquote><p><strong>oEmbed</strong> is a format for allowing an embedded representation of a URL on third party sites.</p>
<p>The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.</p>
<p><a href="http://oembed.com"><strong>http://oembed.com</strong></a></p></blockquote>
<p>Now, what does that mean?</p>
<p>Third-parties, such as YouTube, Flickr, Hulu, GrooveShark, CNN, etc. have resources that you want to embed on your site.</p>
<p>There are different types of resources you can embed:</p>
<ul>
<li>Photo: represents static photos</li>
<li>Video: represents playable videos</li>
<li>Link: represents generic data (i.e., a link to the author’s site or downloadable content)</li>
<li>Rich: any other type not represented above</li>
</ul>
<p>You send a web request to the API URL of the provider with the url of the resource, and the provider sends you a response with metadata about the resource as well as representations of the resource.</p>
<p>Let’s get a video of the skit SNL’s “Undercover Celebrity Boss” from Hulu.</p>
<p>To get the resource, I need the API and Resource URL’s…</p>
<p>API: <a href="http://www.hulu.com/api/oembed.{format">http://www.hulu.com/api/oembed.{format</a>}</p>
<p>Resource: <a href="http://www.hulu.com/watch/131076/saturday-night-live-undercover-celebrity-boss">http://www.hulu.com/watch/131076/saturday-night-live-undercover-celebrity-boss</a></p>
<p>Now, if I click on the resource link, I go to Hulu, but I want to embed the video in my site.</p>
<p>To do that, I make a request to Hulu’s oEmbed API, like so:</p>
<p><a title="http://www.hulu.com/api/oembed.json?url=http://www.hulu.com/watch/131076/saturday-night-live-undercover-celebrity-boss" href="http://www.hulu.com/api/oembed.json?url=http://www.hulu.com/watch/131076/saturday-night-live-undercover-celebrity-boss&amp;maxwidth=200">http://www.hulu.com/api/oembed.json?url=http://www.hulu.com/watch/131076/saturday-night-live-undercover-celebrity-boss&amp;maxwidth=200</a></p>
<p>That request returns the following (notice how I asked for a specific size):<br />
<div id="gist-1085627" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="p">{</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="s2">&quot;duration&quot;</span><span class="o">:</span> <span class="mf">102.7</span><span class="p">,</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="s2">&quot;type&quot;</span><span class="o">:</span> <span class="s2">&quot;video&quot;</span><span class="p">,</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="s2">&quot;provider_url&quot;</span><span class="o">:</span> <span class="s2">&quot;http://www.hulu.com/&quot;</span><span class="p">,</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="s2">&quot;embed_url&quot;</span><span class="o">:</span> <span class="s2">&quot;http://www.hulu.com/embed/YdmSIZmY6plQhyhHSceW2A&quot;</span><span class="p">,</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="s2">&quot;author_name&quot;</span><span class="o">:</span> <span class="s2">&quot;NBC&quot;</span><span class="p">,</span></div><div class='line' id='LC7'>&nbsp;&nbsp;<span class="s2">&quot;cache_age&quot;</span><span class="o">:</span> <span class="mi">3600</span><span class="p">,</span></div><div class='line' id='LC8'>&nbsp;&nbsp;<span class="s2">&quot;height&quot;</span><span class="o">:</span> <span class="mi">200</span><span class="p">,</span></div><div class='line' id='LC9'>&nbsp;&nbsp;<span class="s2">&quot;width&quot;</span><span class="o">:</span> <span class="mi">115</span><span class="p">,</span></div><div class='line' id='LC10'>&nbsp;&nbsp;<span class="s2">&quot;html&quot;</span><span class="o">:</span> <span class="s2">&quot;&lt;object width=&quot;</span><span class="mi">200</span><span class="s2">&quot; height=&quot;</span><span class="mi">115</span><span class="s2">&quot;&gt;&lt;param name=&quot;</span><span class="nx">movie</span><span class="s2">&quot;</span></div><div class='line' id='LC11'><span class="s2">       value=&quot;</span><span class="nx">http</span><span class="o">:</span><span class="c1">//www.hulu.com/embed/YdmSIZmY6plQhyhHSceW2A&quot;&gt;&lt;/param&gt;</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">param</span> <span class="nx">name</span><span class="o">=</span><span class="s2">&quot;flashvars&quot;</span> <span class="nx">value</span><span class="o">=</span><span class="s2">&quot;ap=1&quot;</span><span class="o">&gt;&lt;</span><span class="err">/param&gt;</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="o">&lt;</span><span class="nx">embed</span> <span class="nx">src</span><span class="o">=</span><span class="s2">&quot;http://www.hulu.com/embed/YdmSIZmY6plQhyhHSceW2A&quot;</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">type</span><span class="o">=</span><span class="s2">&quot;application/x-shockwave-flash&quot;</span> <span class="nx">width</span><span class="o">=</span><span class="s2">&quot;200&quot;</span> <span class="nx">height</span><span class="o">=</span><span class="s2">&quot;115&quot;</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nx">flashvars</span><span class="o">=</span><span class="s2">&quot;ap=1&quot;</span><span class="o">&gt;&lt;</span><span class="err">/embed&gt;&lt;/object&gt;&quot;,</span></div><div class='line' id='LC16'>&nbsp;&nbsp;<span class="s2">&quot;air_date&quot;</span><span class="o">:</span> <span class="p">{},</span></div><div class='line' id='LC17'>&nbsp;&nbsp;<span class="s2">&quot;title&quot;</span><span class="o">:</span> <span class="s2">&quot;Undercover Celebrity Boss (Saturday Night Live)&quot;</span><span class="p">,</span></div><div class='line' id='LC18'>&nbsp;&nbsp;<span class="s2">&quot;thumbnail_width&quot;</span><span class="o">:</span> <span class="mi">200</span><span class="p">,</span></div><div class='line' id='LC19'>&nbsp;&nbsp;<span class="s2">&quot;version&quot;</span><span class="o">:</span> <span class="s2">&quot;1.0&quot;</span><span class="p">,</span></div><div class='line' id='LC20'>&nbsp;&nbsp;<span class="s2">&quot;thumbnail_url&quot;</span><span class="o">:</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="s2">&quot;http://thumbnails.hulu.com/265/50037265/148745_145x80_generated.jpg&quot;</span><span class="p">,</span></div><div class='line' id='LC22'>&nbsp;&nbsp;<span class="s2">&quot;thumbnail_height&quot;</span><span class="o">:</span> <span class="mi">110</span><span class="p">,</span></div><div class='line' id='LC23'>&nbsp;&nbsp;<span class="s2">&quot;provider_name&quot;</span><span class="o">:</span> <span class="s2">&quot;Hulu&quot;</span></div><div class='line' id='LC24'><span class="p">}</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/1085627/1c07e84218dfe2297e6a81ff85ae2637000eb655/hulu-snl.js" style="float:right;">view raw</a>
            <a href="https://gist.github.com/1085627#file_hulu_snl.js" style="float:right;margin-right:10px;color:#666">hulu-snl.js</a>
            <a href="https://gist.github.com/1085627">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>
</p>
<p>To embed this in my page, I just need to add the html embed code I received to my page.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="200" height="115" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="flashvars" value="ap=1" /><param name="src" value="http://www.hulu.com/embed/YdmSIZmY6plQhyhHSceW2A" /><embed type="application/x-shockwave-flash" width="200" height="115" src="http://www.hulu.com/embed/YdmSIZmY6plQhyhHSceW2A" flashvars="ap=1"></embed></object></p>
<p>OptionStrict.oEmbed attempts to make this process a little more streamlined, giving you the ability to consume oEmbed streams, as well as provide an oEmbed API endpoint. More to come!</p>
<p><script type="text/javascript">// <![CDATA[
 var cirerolGaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + cirerolGaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
// ]]&gt;</script><script type="text/javascript">// <![CDATA[
 var cirerolPageTracker = _gat._getTracker('UA-8257866-3'); cirerolPageTracker._initData(); cirerolPageTracker._trackPageview();
// ]]&gt;</script></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/07/15/new-open-source-project-optionstrict-oembed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mimicking the AppHarbor Deployment Experience</title>
		<link>http://elegantcode.com/2011/03/20/mimicking-the-appharbor-deployment-experience/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mimicking-the-appharbor-deployment-experience</link>
		<comments>http://elegantcode.com/2011/03/20/mimicking-the-appharbor-deployment-experience/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 20:59:16 +0000</pubDate>
		<dc:creator>Richard Cirerol</dc:creator>
				<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Rake]]></category>
		<category><![CDATA[TeamCity]]></category>
		<category><![CDATA[AppHarbor]]></category>

		<guid isPermaLink="false">http://elegantcode.com/?p=4205</guid>
		<description><![CDATA[On Thursday night at NETDUG (the Boise .NET Developer User Group), I demonstrated how to get started with AppHarbor.  I also showed how to mimic the AppHarbor deployment experience. And thanks to the generosity of the AppHarbor team, we were able to raffle off a Reflector license to one of our attendees! Getting Started with [...]]]></description>
			<content:encoded><![CDATA[<p>On Thursday night at NETDUG (the Boise .NET Developer User Group), I demonstrated how to get started with AppHarbor.  I also showed how to mimic the AppHarbor deployment experience.</p>
<p>And thanks to the generosity of the AppHarbor team, we were able to raffle off a Reflector license to one of our attendees!</p>
<h4>Getting Started with AppHarbor</h4>
<p>You can find <a href="http://www.aaronstannard.com/post/2011/01/14/Getting-Started-with-AppHarbor-e28093-Heroku-for-NET.aspx" target="_blank">many</a> <a href="http://devlicio.us/blogs/rob_reynolds/archive/2011/02/16/appharbor-azure-done-right-aka-heroku-for-net.aspx" target="_blank">blog</a> <a href="http://ajondeck.net/post/2011/03/01/Configure-and-Deploy-ASPNET-MVC-3-Web-Application-Using-Git-to-AppHarbor-from-Scratch!.aspx" target="_blank">posts</a> (and videos) detailing the process of getting started with AppHarbor (see below).  But the basic scenario comes down to <a href="http://support.appharbor.com/kb/getting-started/deploying-your-first-application" target="_blank">these steps</a>*:</p>
<ol>
<li>Installing and configuring Git. (I use msysgit and Git Extensions.)</li>
<li>Initialize a repository for your application.</li>
<li>Deploy your application to AppHarbor. (If you do not have an AppHarbor account yet, feel free to use this <a href="https://appharbor.com/account/new?referrerUsername=codeprogression" target="_blank">referral link</a>.)</li>
</ol>
<p><em>* If you prefer to use Mercurial, follow </em><a href="http://support.appharbor.com/kb/getting-started/using-mercurial-on-appharbor" target="_blank"><em>these steps</em></a><em> instead.</em></p>
<p>If you develop .NET web applications and haven’t tried out AppHarbor yet, do so…Now! I did mention the service is free, right?!?</p>
<h4>Mimicking AppHarbor Deployment</h4>
<p><strong>Disclaimer: <em>The process I am about to describe is informational and not prescriptive. </em></strong><em>AppHarbor provides much more value than just deployment, and I do not want to detract from that in any way.</em></p>
<p>If you have read my previous posts, you know that I use TeamCity and Rake for my build server environment. So I thought I would try to mimic the AppHarbor experience using those tools.</p>
<p>In order to follow along you will need to:</p>
<ol>
<li>Install Git on your development workstation and build server</li>
<li>Install Ruby on your build server</li>
<li>Install TeamCity on your build server<br />
* <em>If you need to learn how to install and use TeamCity, I </em><a href="http://elegantcode.com/2009/05/04/implementing-teamcity-for-net-projects-evolving-your-build-automation-solution/" target="_blank"><em>posted a series on TeamCity 4.5</em></a><em>.</em></li>
<li>Install Web Deployment Tool 2.0 on your build server and IIS web server</li>
<li>Start the web deployment service on your IIS web server <em><br />
</em></li>
<p><em>* For the purposes of the user group presentation and this post, my development workstation, build server, and web server are all on the same machine.</em></ol>
<p>We need to manually provision much of the infrastructure that would be provided for us automatically by AppHarbor, including:</p>
<ul>
<li>Configure the web application in IIS</li>
<li>Set up a bare Git repository</li>
<li>Configure TeamCity to watch the bare repository (VCS Settings)</li>
<li>Use customize build scripts in TeamCity (Build runner/task)</li>
<li>Push your application to the TeamCity repository</li>
</ul>
<p>Other tasks I will not be considering for this sample include database provisioning and custom configuration variables.</p>
<p>Remember, with AppHarbor, the initial provisioning takes a matter of seconds. With that, let’s get our environment ready.</p>
<h5>Configure the web application in IIS</h5>
<ol>
<li>Create a folder on your web server to store the website. (e.g., <strong>c:\sites\sample</strong>)</li>
<li>In IIS, create a new virtual directory under the default site and set the path to the folder you just created. My virtual path is <strong>sample</strong>.</li>
<li>Note the IIS application path. Mine is <strong>Default Web Site\sample</strong>. My url will be http://localhost/sample.</li>
</ol>
<h5>Set up the bare Git repository</h5>
<ol>
<li>Create a folder to store your bare repository. This is the repository TeamCity will watch and use to get code to build. You can create the repository on the build server or on a remote server.  (e.g., <strong>c:\repos\sample.git\</strong>)</li>
<li>Right-click the folder and run the Git Bash from the context menu</li>
<li>In Git Bash, type <strong>git init &#8211;bare</strong></li>
</ol>
<h5>Configure the TeamCity build configuration</h5>
<ol>
<li>Create a new project (e.g., <strong>Sample</strong>)</li>
<li>Create a new build configuration (e.g., <strong>Deploy</strong>) and name it</li>
<li>Leave all other settings on the first page of the wizard at their default</li>
<li>Attach a new VCS and name it</li>
<li>Select Git as the VCS type</li>
<li>Set the Fetch URL to the bare repository you just created (e.g., <strong>c:\repos\sample.git)</strong></li>
<li>Leave all other settings at their default</li>
<li>Add a new build task</li>
<li>Select Rake as the build runner</li>
<li>Select Rakefile content and copy the following into the textbox (Update the site path and project names as appropriate)<br />
<div id="gist-878660" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nb">require</span> <span class="s1">&#39;rubygems&#39;</span></div><div class='line' id='LC2'><span class="nb">require</span> <span class="s1">&#39;erb&#39;</span></div><div class='line' id='LC3'><span class="nb">require</span> <span class="s1">&#39;fileutils&#39;</span></div><div class='line' id='LC4'><span class="nb">require</span> <span class="s1">&#39;find&#39;</span></div><div class='line' id='LC5'><span class="nb">require</span> <span class="s1">&#39;rake&#39;</span></div><div class='line' id='LC6'><span class="nb">require</span> <span class="s1">&#39;rake/tasklib&#39;</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'><span class="n">task</span> <span class="ss">:default</span> <span class="k">do</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">package_location</span><span class="o">=</span><span class="s2">&quot;sample/&quot;</span>  <span class="c1"># website folder location relative to checkout root</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">project_file</span> <span class="o">=</span>  <span class="s2">&quot;sample/sample.csproj&quot;</span> <span class="c1"># website project location relative to checkout root</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">package_name</span> <span class="o">=</span> <span class="s2">&quot;website&quot;</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">package</span> <span class="o">=</span> <span class="s2">&quot;website.deploy.cmd&quot;</span></div><div class='line' id='LC13'>&nbsp;</div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">destination_site</span> <span class="o">=</span> <span class="s1">&#39;Default Web Site/sample&#39;</span> <span class="c1"># Change to match IIS path</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">clr_version</span> <span class="o">=</span> <span class="s1">&#39;v4.0.30319&#39;</span> </div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">framework_dir</span> <span class="o">=</span> <span class="no">File</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="no">ENV</span><span class="o">[</span><span class="s1">&#39;windir&#39;</span><span class="o">].</span><span class="n">dup</span><span class="p">,</span> <span class="s1">&#39;Microsoft.NET&#39;</span><span class="p">,</span> <span class="s1">&#39;Framework&#39;</span><span class="p">,</span> <span class="n">clr_version</span><span class="p">)</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">msbuild_file</span> <span class="o">=</span> <span class="no">File</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">framework_dir</span><span class="p">,</span> <span class="s1">&#39;msbuild.exe&#39;</span><span class="p">)</span></div><div class='line' id='LC18'><br/></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="no">FileUtils</span><span class="o">.</span><span class="n">remove_file</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">package_location</span><span class="si">}#{</span><span class="n">package</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="kp">true</span><span class="p">)</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="no">FileUtils</span><span class="o">.</span><span class="n">remove_file</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">package_location</span><span class="si">}#{</span><span class="n">package_name</span><span class="si">}</span><span class="s2">.zip&quot;</span><span class="p">,</span> <span class="kp">true</span><span class="p">)</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="no">FileUtils</span><span class="o">.</span><span class="n">remove_file</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">package_location</span><span class="si">}#{</span><span class="n">package_name</span><span class="si">}</span><span class="s2">.deploy-readme.txt&quot;</span><span class="p">,</span> <span class="kp">true</span><span class="p">)</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="no">FileUtils</span><span class="o">.</span><span class="n">remove_file</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">package_location</span><span class="si">}#{</span><span class="n">package_name</span><span class="si">}</span><span class="s2">.SetParameters.xml&quot;</span><span class="p">,</span> <span class="kp">true</span><span class="p">)</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="no">FileUtils</span><span class="o">.</span><span class="n">remove_file</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">package_location</span><span class="si">}#{</span><span class="n">package_name</span><span class="si">}</span><span class="s2">.SourceManifest.xml&quot;</span><span class="p">,</span> <span class="kp">true</span><span class="p">)</span></div><div class='line' id='LC24'><br/></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1"># Package website (requires VS2010 version of msbuild)</span></div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">sh</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="n">msbuild_file</span><span class="si">}</span><span class="s2"> </span><span class="se">\&quot;</span><span class="si">#{</span><span class="n">project_file</span><span class="si">}</span><span class="se">\&quot;</span><span class="s2"> /maxcpucount /nr:true /v:m /T:Clean,Package /P:BuildInParallel=true;WarningLevel=0;Configuration=debug;DeployIisAppPath=</span><span class="se">\&quot;</span><span class="si">#{</span><span class="n">destination_site</span><span class="si">}</span><span class="se">\&quot;</span><span class="s2">;PackageLocation=</span><span class="si">#{</span><span class="n">package_name</span><span class="si">}</span><span class="s2">.zip&quot;</span></div><div class='line' id='LC27'><br/></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="c1"># Deploy website (requires Web Deployment service running on web server)</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">sh</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="n">package_location</span><span class="si">}#{</span><span class="n">package</span><span class="si">}</span><span class="s2"> /M:localhost /Y </span><span class="se">\&quot;</span><span class="s2">-skip:objectName=dirPath,skipAction=Delete,absolutePath=logs</span><span class="se">\&quot;</span><span class="s2">&quot;</span></div><div class='line' id='LC30'><br/></div><div class='line' id='LC31'><span class="k">end</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/878660/9b8fae6665452ae704aed9df7cfb006b1b111a9b/rakefile.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/878660#file_rakefile.rb" style="float:right;margin-right:10px;color:#666">rakefile.rb</a>
            <a href="https://gist.github.com/878660">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>
</li>
<li>Leave all other settings at their default</li>
<li>On the Build Triggering page, add a new VCS trigger to build on a VCS change.</li>
</ol>
<ol>Whew! Now that all the infrastructure is in place, let’s do this!</ol>
<h5>Push your application to your TeamCity repository</h5>
<ol>
<li>Assuming your local Git repository is set up and you’re application is ready to deploy…from Git Bash in your local repo, add your remote repository.  Given the settings described above, I would use the following command: <strong>git remote add teamcity /c/repos/sample.git</strong></li>
<li>Then type: <strong>git push teamcity master</strong></li>
<li>In less than a minute, TeamCity should start to package and deploy the website.</li>
</ol>
<p>Using TeamCity for deployment takes markedly longer than AppHarbor. TeamCity uses a polling interval to determine if there are changes; whereas, I assume AppHarbor is using a git post-commit-hook. As an aside, if you haven’t already, start looking into the Web Deployment Tool.</p>
<p>Auto-provisioning and super-fast deployment on an elastic infrastructure…wish I had implemented it first. <img class="wlEmoticon wlEmoticon-winkingsmile" style="border-style: none;" src="http://elegantcode.com/wp-content/uploads/2011/03/wlEmoticon-winkingsmile.png" alt="Winking smile" /></p>
<blockquote><p><strong>Update:</strong></p>
<p>A <a href="http://support.microsoft.com/kb/2537134">bug</a> was introduced in Visual Studio 2010 SP1 which causes an error when deploying with parameters. You may need to update your Microsoft.Web.Publishing.targets file referenced in the KB article (although I cannot confirm that this fixes the problem, yet).</p></blockquote>
<p><script type="text/javascript">// <![CDATA[
 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
// ]]&gt;</script> <script type="text/javascript">// <![CDATA[
 var pageTracker = _gat._getTracker("UA-3956921-1"); pageTracker._initData(); pageTracker._trackPageview();
// ]]&gt;</script></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/03/20/mimicking-the-appharbor-deployment-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Boise Code Camp 2011&#8211;Introduction to Git</title>
		<link>http://elegantcode.com/2011/02/26/boise-code-camp-2011introduction-to-git/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=boise-code-camp-2011introduction-to-git</link>
		<comments>http://elegantcode.com/2011/02/26/boise-code-camp-2011introduction-to-git/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 18:26:39 +0000</pubDate>
		<dc:creator>Richard Cirerol</dc:creator>
				<category><![CDATA[CodeCamp]]></category>
		<category><![CDATA[Source Control]]></category>
		<category><![CDATA[Git]]></category>

		<guid isPermaLink="false">http://elegantcode.com/?p=4160</guid>
		<description><![CDATA[We are having another great Boise Code Camp and once again, I am glad I presented. Git is a DVCS, or distributed version control system, that is gaining popularity in the .NET community. In this session, we will explore: How Git is different from other version control systems (Subversion, Team Foundation Server, Mercurial) Common tools [...]]]></description>
			<content:encoded><![CDATA[<p>We are having another great Boise Code Camp and once again, I am glad I presented.</p>
<blockquote><p>Git is a DVCS, or distributed version control system, that is gaining popularity in the .NET community. In this session, we will explore:</p>
<ul>
<li>How Git is different from other version control systems (Subversion, Team Foundation Server, Mercurial)</li>
<li>Common tools (emphasis on Windows users)</li>
<li>Basic commands and workflow</li>
<li>Using Git as your Subversion client</li>
<li>Various Git services, such as GitHub, and AppHarbor</li>
</ul>
</blockquote>
<p>My slides are available on <a title="Introduction to Git Slide Deck" href="https://github.com/codeprogression/Presentations/blob/master/Introduction%20to%20Git.pptx">github</a>.</p>
<p>If you attended the presentation, please leave your feedback at <a title="Introduction to Git on SpeakerRate" href="http://spkr8.com/t/5760">SpeakerRate</a> (<a title="http://spkr8.com/t/5760" href="http://spkr8.com/t/5760">http://spkr8.com/t/5760</a>).</p>
<p><script type="text/javascript">// <![CDATA[
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
// ]]&gt;</script><br />
<script type="text/javascript">// <![CDATA[
var pageTracker = _gat._getTracker("UA-3956921-1");
pageTracker._initData();
pageTracker._trackPageview();
// ]]&gt;</script></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2011/02/26/boise-code-camp-2011introduction-to-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Defining Development Experience</title>
		<link>http://elegantcode.com/2010/07/10/defining-development-experience/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=defining-development-experience</link>
		<comments>http://elegantcode.com/2010/07/10/defining-development-experience/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 07:21:32 +0000</pubDate>
		<dc:creator>Richard Cirerol</dc:creator>
				<category><![CDATA[Esoterica]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/07/10/defining-development-experience/</guid>
		<description><![CDATA[Friday morning, one of my colleagues asked, “What do you consider to be the difference between a junior, mid-level, and senior developer?” Being a .NET shop, the obvious answer would be to head over to Scott Hanselman’s blog and pull up this post: What Great .NET Developers Ought To Know (More .NET Interview Questions).&#160; Scott [...]]]></description>
			<content:encoded><![CDATA[<p>Friday morning, one of my colleagues asked, “What do you consider to be the difference between a junior, mid-level, and senior developer?” </p>
<p>Being a .NET shop, the obvious answer would be to head over to Scott Hanselman’s blog and pull up this post: <a href="http://www.hanselman.com/blog/WhatGreatNETDevelopersOughtToKnowMoreNETInterviewQuestions.aspx">What Great .NET Developers Ought To Know (More .NET Interview Questions)</a>.&#160; Scott has broken out what he considered, at the time, to be the relevant platform- and framework-related knowledge required of a .NET developer at various points in their career.</p>
<p>However, I do not believe that knowledge of a programming language and hosting platform solely defines a great developer, no matter the depth or detail of the knowledge.&#160; If a developer is unable to apply that knowledge to a problem domain, it is useless knowledge – a mere parlor trick.</p>
<p>Given a developer has an affinity towards coding and technology, that developer should be able to learn new programming languages, new platforms, and new tools.&#160; If a senior developer in a ASP.NET shop moves to a Ruby shop, what would define him or her as a Senior level? Language syntax and idiomatics should only be a small part of the equation.</p>
<h4>&#160;</h4>
<h4>A Different Perspective</h4>
<p>I believe developer levels are determined by a combination of autonomy, mastery, and trust.&#160; I have a started a list below. This list is not scientific – it just represents my current viewpoint.</p>
<p>&#160;</p>
<h4>Junior Developers</h4>
<p>Autonomy: LOW</p>
<ul>
<li>Not self-directed </li>
<li>Need tasks rather than requirements/user stories</li>
<li>Tasks are expected to be implemented as defined</li>
<li>Often under the watchful eye of a senior developer</li>
<li>May need assistance in finding/deriving appropriate solutions</li>
</ul>
<p>Mastery: LOW-&gt;MEDIUM</p>
<ul>
<li>Comfortable with the constructs of their main language/platform</li>
<li>Basic understanding of object-oriented programming</li>
<li>May have understanding of architectural design patterns and principles (MVC, Single Responsibility Principle)</li>
<li>Limited comprehension of problem domain</li>
<li>Can write basic tests/specifications</li>
</ul>
<p>Trust: LOW </p>
<p>&#160;</p>
<h4>Mid-Level Developers</h4>
<p>Autonomy: MEDIUM</p>
<ul>
<li>Self-directed</li>
<li>Can work from user stories</li>
<li>Can normally find/derive appropriate solutions</li>
</ul>
<p>Mastery: MEDIUM</p>
<ul>
<li>Comfortable with the constructs of their main language and platform</li>
<li>Basic understanding of constructs of additional languages or platforms</li>
<li>Moderate understanding of object-oriented programming</li>
<li>Basic understanding of functional programming</li>
<li>Basic understanding of messaging architectures</li>
<li>Understands several design patterns and principles</li>
<li>Can write both state and interaction tests/specifications</li>
<li>Comprehends problem domain</li>
<li>Committed to continuous learning</li>
</ul>
<p>Trust: MEDIUM</p>
<ul>
<li>Can represent the needs of the development team</li>
<li>Is respected in the community</li>
</ul>
<h4>Senior Developers</h4>
<p>Autonomy: HIGH</p>
<ul>
<li>Self-directed</li>
<li>Can develop user stories</li>
<li>Can elucidate requirements</li>
<li>Can generally find, derive, or create appropriate solutions</li>
</ul>
<p>Mastery: MEDIUM-&gt;HIGH</p>
<ul>
<li>Comfortable with two or more languages/platforms</li>
<li>Moderate to high understanding of object-oriented and functional programming</li>
<li>Moderate to high understanding of messaging</li>
<li>Can explain design patterns and principles to developers, as well as non-technical staff</li>
<li>Comprehends problem domain and common domain patterns</li>
<li>Can write state, interaction, integration tests/specifications</li>
<li>Committed to continuous learning</li>
</ul>
<p>Trust: HIGH</p>
<ul>
<li>Can represent the needs of the development team</li>
<li>Can represent the needs of the customer</li>
<li>Can represent the needs of management</li>
<li>Is respected in the community</li>
</ul>
<p>Please note that I do have emphasis on language in each level, but language is dwarfed by the need to understand and communicate the problem domain.&#160; Also, mastery of a particular platform is less important than autonomy or trust.</p>
<p>What do you think defines a junior, mid, or senior developer?</p>
<p><script type="text/javascript">// <![CDATA[
  var cirerolGaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + cirerolGaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
// ]]&gt;</script><script type="text/javascript">// <![CDATA[
  var cirerolPageTracker = _gat._getTracker('UA-8257866-3'); cirerolPageTracker._initData(); cirerolPageTracker._trackPageview();
// ]]&gt;</script></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/07/10/defining-development-experience/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Boise Code Camp 2010: Distributed Event-Driven Architecture Session Notes</title>
		<link>http://elegantcode.com/2010/03/28/boise-code-camp-2010-distributed-event-driven-architecture-session-notes/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=boise-code-camp-2010-distributed-event-driven-architecture-session-notes</link>
		<comments>http://elegantcode.com/2010/03/28/boise-code-camp-2010-distributed-event-driven-architecture-session-notes/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 17:52:09 +0000</pubDate>
		<dc:creator>Richard Cirerol</dc:creator>
				<category><![CDATA[CodeCamp]]></category>
		<category><![CDATA[Event Driven Architecture]]></category>
		<category><![CDATA[Boise Code Camp 2010]]></category>
		<category><![CDATA[Message Bus]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[Sample]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/28/boise-code-camp-2010-distributed-event-driven-architecture-session-notes/</guid>
		<description><![CDATA[I presented a session on event-driven architecture (with examples using NServiceBus) at Boise Code Camp yesterday.&#160; I had a great turnout and great feedback. Thanks so much to those who attended!&#160; If you attended and have any feedback/constructive criticism, please leave a comment! For those who missed the session – or for those who would [...]]]></description>
			<content:encoded><![CDATA[<p>I presented a session on event-driven architecture (with examples using NServiceBus) at Boise Code Camp yesterday.&#160; I had a great turnout and great feedback. Thanks so much to those who attended!&#160; </p>
<blockquote><p><strong>If you attended and have any feedback/constructive criticism, please leave a comment!</strong></p>
</blockquote>
<p>For those who missed the session – or for those who would like to see it again – you will get another opportunity. I will be presenting this session at <a href="http://www.netdug.com/" target="_blank">NETDUG</a> (in April, I believe).&#160; I am also submitting the session to <a href="http://portlandcodecamp.org" target="_blank">Portland Code Camp</a>.</p>
<h4>Session Assets</h4>
<p>As promised, I have included, in an <a href="http://code.google.com/p/codeprogression/source/browse/sample-projects/CodeProgression.BCC2010.zip" target="_blank">archive</a>:</p>
<ul>
<li>The slide deck</li>
<li>The solution as completed during the session (CodeProgression.BCC2010)</li>
</ul>
<p>I have also included:</p>
<ul>
<li>The solution with which we started (CodeProgression.BCC2010.Start)</li>
<li>A solution based on a MassTransit sample (from which I based the NServiceBus sample)</li>
</ul>
<blockquote><p><strong>Notes about the solutions:</strong></p>
<p>If you are planning on working the NServiceBus sample from scratch, don’t forget to add the NServiceBus.Host.exe as the startup program for each endpoint project.</p>
<p>For the MassTransit solution, you may need to update the <em>references\masstransit\MassTransit.RuntimeServices.exe.config</em> to point to your local database.</p>
</blockquote>
<p>&#160;</p>
<h4>Resources</h4>
<p>Here is also a list of resources I used while preparing for this session:</p>
<p><strong><u>NServiceBus       <br /></u></strong><a href="http://www.nservicebus.com">http://www.nservicebus.com</a>    <br /><a href="http://gurustop.net/blog/2008/04/20/enterprise-service-bus-messaging-using-nservicebus/">http://gurustop.net/blog/2008/04/20/enterprise-service-bus-messaging-using-nservicebus/</a>    <br /><a href="http://elegantcode.com/2009/10/09/exploring-nservicebus/">http://elegantcode.com/2009/10/09/exploring-nservicebus/</a>    <br /><a href="http://sourceforge.net/apps/mediawiki/nservicebus/index.php?title=Tutorials">http://sourceforge.net/apps/mediawiki/nservicebus/index.php?title=Tutorials</a>    <br /><a href="http://blog.zoolutions.se/post/2010/02/08/Conquering-NServiceBus-part-1-e28093-Getting-Started.aspx">http://blog.zoolutions.se/post/2010/02/08/Conquering-NServiceBus-part-1-e28093-Getting-Started.aspx</a>    <br /><a href="http://blog.zoolutions.se/post/2010/02/09/Conquering-NServiceBus-part-2-e28093-Initial-configuration.aspx">http://blog.zoolutions.se/post/2010/02/09/Conquering-NServiceBus-part-2-e28093-Initial-configuration.aspx</a></p>
<p><strong><u>MassTransit       <br /></u></strong><a href="http://masstransit.pbworks.com/A-First-Look-at-Mass-Transit">http://masstransit.pbworks.com/A-First-Look-at-Mass-Transit</a>    <br /><a href="http://blogs.dovetailsoftware.com/blogs/kmiller/archive/2009/08/26/producing-and-consuming-messages-using-masstransit-and-structuremap.aspx">http://blogs.dovetailsoftware.com/blogs/kmiller/archive/2009/08/26/producing-and-consuming-messages-using-masstransit-and-structuremap.aspx</a>    <br /><a href="http://rhysc.blogspot.com/2009/05/getting-started-with-masstransit.html">http://rhysc.blogspot.com/2009/05/getting-started-with-masstransit.html</a></p>
<p><strong><u>TopShelf       <br /></u></strong><a href="http://blogs.dovetailsoftware.com/blogs/kmiller/archive/2010/01/20/configuring-topshelf-using-a-structuremap-container.aspx">http://blogs.dovetailsoftware.com/blogs/kmiller/archive/2010/01/20/configuring-topshelf-using-a-structuremap-container.aspx</a>    <br /><a href="http://blogs.dovetailsoftware.com/blogs/kmiller/archive/2010/01/20/controlling-application-lifetime-in-topshelf.aspx">http://blogs.dovetailsoftware.com/blogs/kmiller/archive/2010/01/20/controlling-application-lifetime-in-topshelf.aspx</a></p>
<p><strong><u>Misc       <br /></u></strong><a href="http://www.enterpriseintegrationpatterns.com">http://www.enterpriseintegrationpatterns.com</a>    <br /><a href="http://www.enterpriseintegrationpatterns.com/ramblings/18_starbucks.html">http://www.enterpriseintegrationpatterns.com/ramblings/18_starbucks.html</a>    <br /><a href="http://www.amazon.com/Enterprise-Integration-Patterns-Designing-Deploying/dp/0321200683">http://www.amazon.com/Enterprise-Integration-Patterns-Designing-Deploying/dp/0321200683</a></p>
<p><script type="text/javascript">// <![CDATA[
  var cirerolGaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + cirerolGaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
// ]]&gt;</script><script type="text/javascript">// <![CDATA[
  var cirerolPageTracker = _gat._getTracker('UA-8257866-3'); cirerolPageTracker._initData(); cirerolPageTracker._trackPageview();
// ]]&gt;</script></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/28/boise-code-camp-2010-distributed-event-driven-architecture-session-notes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Is MSpec an Internal DSL?&#8230;And is that okay?</title>
		<link>http://elegantcode.com/2010/03/03/is-mspec-an-internal-dsland-is-that-okay/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=is-mspec-an-internal-dsland-is-that-okay</link>
		<comments>http://elegantcode.com/2010/03/03/is-mspec-an-internal-dsland-is-that-okay/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 20:27:07 +0000</pubDate>
		<dc:creator>Richard Cirerol</dc:creator>
				<category><![CDATA[Esoterica]]></category>
		<category><![CDATA[Internal DSL]]></category>
		<category><![CDATA[MSpec]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/03/is-mspec-an-internal-dsland-is-that-okay/</guid>
		<description><![CDATA[In my last post on MSpec, John Sonmez commented: When I see the MSpec code, I think about it being an internal DSL for doing the testing, and I start to think that perhaps it should just go ahead and be it’s own language instead of trying to live inside of C#. On the other [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://codeprogression.blogspot.com/2010/03/evolution-of-test-specification-styles.html">last post</a> on MSpec, <a href="http://elegantcode.com/2010/03/01/an-evolution-of-test-specification-styles-my-journey-to-mspec/#comment-54161">John Sonmez commented</a>:</p>
<blockquote><p>When I see the MSpec code, I think about it being an internal DSL for doing the testing, and I start to think that perhaps it should just go ahead and be it’s own language instead of trying to live inside of C#. On the other hand, I wonder about the value of using another language to unit test C# code…</p></blockquote>
<p>I think John was spot-on with his instinct – in my opinion, MSpec is an internal DSL.  I also think that is the beauty of the framework.  Domain-specific languages are meant to solve a target problem in a particular domain.  MSpec’s problem domain is testing .NET code.  By convention, it constrains you to its limited language to help you test your code in a meaningful yet powerful manner.</p>
<h4>What is an Internal DSL?</h4>
<p>According to Martin Fowler:</p>
<blockquote><p>“Internal DSLs are particular ways of using a host language to give the host language the feel of a particular language&#8230;Internal DSLs are also referred to as embedded DSLs or FluentInterfaces”  (from Bliki article: <a href="http://www.martinfowler.com/bliki/DomainSpecificLanguage.html" target="_blank">Domain Specific Language</a>)</p>
<p>“Internal DSLs use the same general purpose programming language that the wider application uses, but uses that language in a particular and limited style.”<br />
(from DSL-WIP section: <a href="http://martinfowler.com/dslwip/UsingDsls.html#DefiningDomainSpecificLanguages" target="_blank">Using Domain Specific Languages</a>)</p></blockquote>
<p><strong>But, as John wondered, <em>is there value in using another language (external DSL) to test C# code?</em> </strong></p>
<p>Perhaps.  Yet, I believe there is more value in using external DSLs to test user interfaces (e.g., <a href="http://watir.com/" target="_blank">WatiR</a>, <a href="http://watin.sourceforge.net/" target="_blank">WatiN</a>, and <a href="http://seleniumhq.org/" target="_blank">Selenium</a>), or for build scripting (e.g.,<a href="http://rake.rubyforge.org/" target="_blank">Rake</a>, <a href="http://code.google.com/p/psake/" target="_blank">psake</a>).</p>
<p><strong>Let’s look at that question a little differently:<em> Is there value in using an internal DSL (like MSpec) to test C# code?</em></strong></p>
<p>To that I give a resounding YES! MSpec’s host language is C#…which provides great value to me.  I get all the benefits of intellisense, refactoring, and (R#) navigation in my IDE.  I don’t have to worry about the impedance mismatch between my code and an external DSL.</p>
<h4>You Probably Use DSLs All the Time</h4>
<p>In fact, I use several DSLs every day when I code.</p>
<p>Consider the following table of frameworks. You may not have thought any of these in the context of a domain-specific language, but each has a specific purpose with its own limited language constructs. Some are internal, some external.</p>
<table border="1" cellspacing="0" cellpadding="2" width="541">
<tbody>
<tr>
<td width="128" valign="top"><strong>DSL</strong></td>
<td width="90" valign="top"><strong>Type</strong></td>
<td width="124" valign="top"><strong>Host Language</strong></td>
<td width="197" valign="top"><strong>Problem Domain</strong></td>
</tr>
<tr>
<td width="133" valign="top"><a href="http://structuremap.sourceforge.net/" target="_blank">StructureMap</a></td>
<td width="97" valign="top">Internal</td>
<td width="124" valign="top">C#</td>
<td width="193" valign="top">Dependency injection<br />
Inversion of control</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://www.codeplex.com/AutoMapper" target="_blank">AutoMapper</a></td>
<td width="100" valign="top">Internal</td>
<td width="123" valign="top">C#</td>
<td width="192" valign="top">Object-to-object mapping</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://www.ayende.com/projects/rhino-mocks.aspx" target="_blank">RhinoMocks</a></td>
<td width="102" valign="top">Internal</td>
<td width="123" valign="top">C#</td>
<td width="191" valign="top">Proxy object interaction and verification</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://code.google.com/p/moq/" target="_blank">Moq</a></td>
<td width="103" valign="top">Internal</td>
<td width="123" valign="top">C#</td>
<td width="191" valign="top">Proxy object interaction and verification</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://jquery.com/" target="_blank">jQuery</a></td>
<td width="103" valign="top">Internal</td>
<td width="123" valign="top">JavaScript</td>
<td width="191" valign="top">Document traversal<br />
Event handling<br />
Animation</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://www.w3.org/Style/CSS/" target="_blank">Cascading Style Sheets</a></td>
<td width="103" valign="top">External</td>
<td width="123" valign="top">English</td>
<td width="191" valign="top">Presentation semantics</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://rake.rubyforge.org/" target="_blank">Rake</a></td>
<td width="103" valign="top">External</td>
<td width="123" valign="top">Ruby</td>
<td width="191" valign="top">Build/task automation</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://code.google.com/p/psake/" target="_blank">psake</a></td>
<td width="103" valign="top">External</td>
<td width="123" valign="top">PowerShell</td>
<td width="191" valign="top">Build/task automation</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://nant.sourceforge.net/" target="_blank">nAnt</a></td>
<td width="103" valign="top">External</td>
<td width="123" valign="top">XML</td>
<td width="191" valign="top">Build/task automation</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://en.wikipedia.org/wiki/SQL" target="_blank">SQL</a></td>
<td width="103" valign="top">External</td>
<td width="123" valign="top">English</td>
<td width="191" valign="top">Data management</td>
</tr>
<tr>
<td width="135" valign="top"><a href="http://cukes.info/" target="_blank">Cucumber</a></td>
<td width="103" valign="top">External</td>
<td width="123" valign="top">Gherkin</td>
<td width="191" valign="top">Behavior-driven development</td>
</tr>
</tbody>
</table>
<p>When considering a framework within your host language: If the framework has a fluent interface with language devoted to a specific problem domain, it is probably an internal DSL.</p>
<p>So is MSpec an internal DSL? Yes.</p>
<p>And is that okay? Definitely.</p>
<h4>Further Reading</h4>
<p>Check out Martin Fowler’s articles on domain-specific languages:</p>
<p><a href="http://www.martinfowler.com/bliki/DomainSpecificLanguage.html">http://www.martinfowler.com/bliki/DomainSpecificLanguage.html</a><br />
<a href="http://martinfowler.com/dslwip/UsingDsls.html">http://martinfowler.com/dslwip/UsingDsls.html</a><br />
<a href="http://martinfowler.com/dslwip/InternalOverview.html">http://martinfowler.com/dslwip/InternalOverview.html</a></p>
<p><script type="text/javascript">// <![CDATA[
  var cirerolGaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + cirerolGaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
// ]]&gt;</script><script type="text/javascript">// <![CDATA[
  var cirerolPageTracker = _gat._getTracker('UA-8257866-3'); cirerolPageTracker._initData(); cirerolPageTracker._trackPageview();
// ]]&gt;</script></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/03/is-mspec-an-internal-dsland-is-that-okay/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>An Evolution of Test-Specification Styles &#8211; My Journey to MSpec</title>
		<link>http://elegantcode.com/2010/03/01/an-evolution-of-test-specification-styles-my-journey-to-mspec/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=an-evolution-of-test-specification-styles-my-journey-to-mspec</link>
		<comments>http://elegantcode.com/2010/03/01/an-evolution-of-test-specification-styles-my-journey-to-mspec/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 03:32:57 +0000</pubDate>
		<dc:creator>Richard Cirerol</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[MSpec]]></category>
		<category><![CDATA[NUnit]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2010/03/01/an-evolution-of-test-specification-styles-my-journey-to-mspec/</guid>
		<description><![CDATA[Over the last few years, the practice of Test-Driven Design and Behavior-Driven Design has increased in acceptance, even if its practice has not increased in equal proportion.&#160; From my perspective, specification-based design is a natural way to develop software.&#160; Each developer has a preferred framework, and a framework they loathe.&#160; In the .NET world, there [...]]]></description>
			<content:encoded><![CDATA[<p>Over the last few years, the practice of Test-Driven Design and Behavior-Driven Design has increased in acceptance, even if its practice has not increased in equal proportion.&#160; From my perspective, specification-based design is a natural way to develop software.&#160; Each developer has a preferred framework, and a framework they loathe.&#160; In the .NET world, there are a plethora of unit testing frameworks &#8211; NUnit has been nearly ubiquitous; mbUnit was evolutionary; xUnit was revolutionary; MSTest is…er, getting an update.&#160; For BDD, you can find frameworks like SpecUnit.NET, NBehave, and MSpec.&#160; My current framework of choice is MSpec, especially when <a href="http://elegantcode.com/2009/11/30/wrapping-up-the-structuremap-automocking-container/" target="_blank">coupled with StructureMap’s automocking container and a couple helper classes</a>. </p>
<p>From my unscientific observation, developers either love or hate MSpec.&#160; For those that hate MSpec, I wonder if it is the grammatical syntax or the lambda-expression style creating the aversion.&#160; Some even expound MSpec as cryptic and cumbersome.&#160; This seems to be a common complaint – one I hope to address in this post.</p>
<p>I find that those drawn to MSpec have experienced an evolution of testing/specification styles, influenced partially by the community and partially by frameworks they have used.&#160; At the very least, this has been my experience as I have transitioned from xUnit frameworks. </p>
<h4>Conventions of MSpec</h4>
<p>I particularly like the conventions MSpec encourages using its four delegate types:</p>
<p><strong>Establish</strong>: </p>
<ul>
<li>Provides setup (context) for the specification </li>
<li>One per class (but not required) </li>
<li>“Unlimited” per specification or inheritance chain </li>
<li>Runs down the inheritance chain prior to the <strong>Because</strong> delegate </li>
</ul>
<p><strong>Because</strong>:</p>
<ul>
<li>The action/event being tested </li>
<li>One per specification </li>
</ul>
<p><strong>It</strong>: </p>
<ul>
<li>An assertion (usually extension methods/fluent interfaces based on NUnit/xUnit Assert classes) </li>
<li>“Unlimited” per specification/class </li>
<li>Can be “hosted” in a <strong>Behavior</strong> class </li>
<li>Runs after the <strong>Because</strong> </li>
<li>Can be reused when placed in a <strong>Behavior</strong> class </li>
<li>If body of delegate is missing, will mark as “Ignored” or “Not Implemented” in a test runner </li>
</ul>
<p><strong>Cleanup</strong>:</p>
<ul>
<li>Provides teardown for the specification </li>
<li>One per class (but not required) </li>
<li>“Unlimited” per specification or inheritance chain </li>
<li>Runs up the inheritance chain after the <strong>It</strong> delegates are completed </li>
</ul>
<p>MSpec also has one other delegate type (<code>Behaves_like&lt;T&gt;</code>) and several optional attributes available (<code>Subject, Tag, Ignore, Behavior</code>).&#160; <code>[Subject]</code> provides additional information about the specification. <code>[Tag]</code> is similar to the <code>[Category]</code> attribute in NUnit.&#160; <code>[Ignore]</code> is self-explanatory. <code>[Behavior]</code> marks a class made up entirely of assertions (<code>It</code> delegates).&#160; <code>Behaves_like&lt;T&gt;</code> is a delegate type that can be included in a specification block taking the place of a set of assertions (<code>It</code> delegates).</p>
<p>&#160;</p>
<h4>NUnit – TestFixture-Per-Class </h4>
<p>I have gone from using a TestFixture-Per-Class style to a behavior-driven/context-specification style.&#160; I would like to use the standard HomeController, created in an ASP.NET MVC 1.0 project, as an example class to explore this evolution.&#160; </p>
<p>In my TestFixture-Per-Class days, I may have tested the <code>Index</code> action as follows:</p>
<pre class="brush: csharp;">[TestFixture]
public class HomeControllerTests
{
    [Test]
    public void IndexActionTest()
    {
        var controller = new HomeController();
        var result = (ViewResult) controller.Index();
        Assert.AreEqual(&quot;Welcome to ASP.NET MVC!&quot;, result.ViewData[&quot;Message&quot;]);
    }
}</pre>
<p>I do like the simplicity of the code.&#160; One line to set up the test, one to execute, and one to assert.&#160; There is a little ceremony involved with marking the class and methods with the NUnit attributes.&#160; With this simple test, it is easy to distinguish the setup code from the assertion; yet, a more complex test would make scanning the test more difficult.&#160; Comments can help, but tend to just add noise.</p>
<p>&#160;</p>
<h4>NUnit – Arrange/Act/Assert</h4>
<p>With the advent of BDD, I started naming my classes and expectations as inspired by BDD syntax.&#160; I might have used the <code>[SetUp]</code> attribute or a base class to organize my test code in a style similar to the following:</p>
<pre class="brush: csharp;">[TestFixture]
public class when_I_go_to_the_home_page: AAA
{
    private HomeController _controller;
    private ViewResult _result;

    protected override void Arrange()
    {
        _controller = new HomeController();
    }
    protected override void Act()
    {
        _result = (ViewResult)_controller.Index();
    }

    [Test]
    public void then_the_welcome_message_should_be_displayed()
    {
        _result.ViewData[&quot;Message&quot;].ShouldEqual(&quot;Welcome to ASP.NET MVC!&quot;);
    }
}</pre>
<p>This actively separates out the different responsibilities of the test.&#160; You can see where the setup code is, as well as the action being tested.&#160; The assertion is the only line of code in the test method.&#160; There is still ceremony involved with the attributes.&#160; Plus, we have added a little more ceremony and noise with the <code>Arrange()</code> and <code>Act()</code> overrides.&#160; This simple test does not necessarily need the parts split in this manner, but it would help with more complex scenarios.&#160; Additionally, the assertion is using extension methods based on the NUnit Assert classes which provides a little more clarity to the assertion.</p>
<p>&#160;</p>
<h4>MSpec</h4>
<p>Once started down the path of a behavior-driven (or context/specification) style, I started looking at frameworks devoted to that style.&#160; MSpec is one of those frameworks.&#160; Here is the Index action specification in MSpec:</p>
<pre class="brush: csharp;">public class when_I_go_to_the_home_page
{
    Establish context = () =&gt;  _controller = new HomeController();
    Because of = () =&gt; _result = (ViewResult)_controller.Index();
    It should_display_the_welcome_message = () =&gt; _result.ViewData[&quot;Message&quot;].ShouldEqual(&quot;Welcome to ASP.NET MVC!&quot;); 

    static HomeController _controller;
    static ViewResult _result;
}</pre>
<p>If you look closely, this specification is very similar to the first NUnit test.&#160; However, there are no attributes to specify and the specification has a distinct functional separation.&#160; The Establish/Because/It syntax is analogous to the Given/When/Then language used in user stories or Arrange/Act/Assert syntaxes used in the previous example.&#160; In my opinion, this has less noise than the test using NUnit with an AAA base class – even while using the lambda delegate syntax.</p>
<p>&#160;</p>
<h4>MSpec &#8211; SpecificationFor&lt;ClassUnderTest&gt;</h4>
<p>I often use a base class to handle some of my setup code. Using StructureMap and RhinoMocks, it generates and injects proxied dependencies for the given class.&#160; In this example, I have no dependencies to wire up, but I think you can still see the benefits.</p>
<pre class="brush: csharp;">public class when_I_go_to_the_home_page : SpecificationFor&lt;HomeController&gt;
{
    Because of = () =&gt; _result = (ViewResult)ClassUnderTest.Index();
    It should_display_the_welcome_message = () =&gt; _result.ViewData[&quot;Message&quot;].ShouldEqual(&quot;Welcome to ASP.NET MVC!&quot;); 

    static ViewResult _result;
}</pre>
<p>The Establish delegate is not needed in this specification, because I have wired up the class via the base class.&#160; I feel this version is most clear and concise of all the examples, and neither cryptic nor cumbersome&#160; If you are interested in the <code>SpecificationFor&lt;T&gt;</code> base class and the supporting components, check out my previous <a href="http://elegantcode.com/2009/11/30/wrapping-up-the-structuremap-automocking-container/" target="_blank">post</a>.&#160; </p>
<p>&#160;</p>
<h4>Looking to the Future</h4>
<p>I hope that this post has shown that MSpec does not have to be cryptic, nor cumbersome.&#160; If you considered it as such before, please take another critical look.</p>
<p>Given the evolving state of the craft, I am sure that my test/specification style will continue to gradually change.&#160; I am sure that my framework of choice will eventually change as well, especially as each framework is extended and challenged by others.&#160; Hopefully, you can be open to evolving your style as well.</p>
<p><script type="text/javascript">// <![CDATA[
 var cirerolGaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + cirerolGaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
// ]]&gt;</script><script type="text/javascript">// <![CDATA[
 var cirerolPageTracker = _gat._getTracker('UA-8257866-3'); cirerolPageTracker._initData(); cirerolPageTracker._trackPageview();
// ]]&gt;</script></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2010/03/01/an-evolution-of-test-specification-styles-my-journey-to-mspec/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Wrapping up the StructureMap Automocking Container</title>
		<link>http://elegantcode.com/2009/11/30/wrapping-up-the-structuremap-automocking-container/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wrapping-up-the-structuremap-automocking-container</link>
		<comments>http://elegantcode.com/2009/11/30/wrapping-up-the-structuremap-automocking-container/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 07:21:43 +0000</pubDate>
		<dc:creator>Richard Cirerol</dc:creator>
				<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[StructureMap; Automocking; MSpec;]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/11/30/wrapping-up-the-structuremap-automocking-container/</guid>
		<description><![CDATA[<p><font color="#804040"><strong>UPDATE</strong>: I apologize…the original wrapper did not allow injected dependencies.&#160; I have fixed this bug and updated the sample.</font></p> I have been using StructureMap.AutoMocking with MSpec (Machine.Specifications) and Rhino.Mocks for a few months now.  Although I am very comfortable with the patterns that emerge from using the frameworks together, introducing StructureMap.Automocking to other developers is sometimes challenging. I decided to wrap the details of the container to make the intention clearer and explanation easier.  I have started using this wrapper in my projects, and have found it makes building up specifications more efficient in my daily coding.]]></description>
			<content:encoded><![CDATA[<p><span style="color: #804040;"><strong>UPDATE</strong>: I apologize…the original wrapper did not allow injected dependencies.  I have fixed this bug and updated the sample.</span></p>
<p>I have been using StructureMap.AutoMocking with MSpec (Machine.Specifications) and Rhino.Mocks for a few months now.  Although I am very comfortable with the patterns that emerge from using the frameworks together, introducing StructureMap.Automocking to other developers is sometimes challenging.</p>
<p>When viewing a specification or test set up with the Rhino.Mocks or Moq automocking container, what is being tested is not readily apparent.  Once the concept is explained and demonstrated, these same developers seem to have no issue with maintaining the specifications/tests.</p>
<p>I decided to wrap the details of the container to make the intention clearer and explanation easier.  I have started using this wrapper in my projects, and have found it makes building up specifications more efficient in my daily coding.</p>
<p>Let me know whether this is useful to you, or how it could be made more useful.</p>
<h4>The Examples</h4>
<p>Let’s contrive an example.  We’ll say we have a coffee machine that grinds its own beans before brewing. However, the hopper has to have beans before starting the grind.  Here is the basic specification:</p>
<table border="1" cellspacing="0" cellpadding="2" width="533">
<tbody>
<tr>
<td width="117" valign="top">Action/Behavior</td>
<td width="414" valign="top">Prepare coffee grounds for 12 cups of coffee</td>
</tr>
<tr>
<td rowspan="2" width="117" valign="top">Expectations</td>
<td width="414" valign="top">Should check that hopper has beans (mock returns true)</td>
</tr>
<tr>
<td width="414" valign="top">Because hopper has beans, should ask grinder to grind enough beans for 12 cups of coffee</td>
</tr>
</tbody>
</table>
<p>We could start without a container, using Rhino.Mocks to build up the CoffeeMachine dependencies manually:</p>
<pre class="brush: csharp;">[Subject(typeof(CoffeeMachine),"using vanilla Rhino.Mocks")]
public class Example01_when_preparing_coffee_grounds
{
    Establish context = () =&gt;
        {
            Grinder = MockRepository.GenerateMock&lt;IGrinder&gt;();
            Hopper = MockRepository.GenerateMock&lt;IHopper&gt;();
            Hopper.Expect(x =&gt; x.HasBeans()).Return(true);
            CoffeeMachine = new CoffeeMachine(Grinder, Hopper);
        };

    Because of = () =&gt; _coffeeMachine.PrepareCoffeeGrounds(12);

    It should_check_if_hopper_has_beans = () =&gt; Hopper.VerifyAllExpectations();
    It should_grind_coffee = () =&gt; Grinder.AssertWasCalled(x =&gt; x.Grind(12));

    static IGrinder Grinder;
    static IHopper Hopper;
    static CoffeeMachine CoffeeMachine;
}</pre>
<p>For those of you not familiar with the MSpec style, please refer to the following posts:</p>
<ul>
<li><a href="http://blog.wekeroad.com/blog/make-bdd-your-bff-2/" target="_blank">Make BDD Your BFF</a></li>
<li><a href="http://www.lostechies.com/blogs/seanbiefeld/archive/2009/08/25/step-by-step-to-using-machine-specifications-with-resharper.aspx" target="_blank">Step by Step to Using MSpec (Machine.Specifications) with ReSharper</a></li>
<li><a href="http://elegantcode.com/2009/07/05/mspec-take-2/" target="_blank">MSpec &#8211; Take 2</a></li>
<li><a href="http://marcinobel.com/index.php/mspec-bdd-installer/" target="_blank">MSpec BDD framework installer</a></li>
<li><strong>Updated! </strong>From the <a href="http://blog.cwa.me.uk/2009/11/30/the-morning-brew-487/" target="_blank">Morning Brew #487</a>: BDD with MSpec and Rhino Auto Mocks, parts  <a href="http://telldontask.wordpress.com/2009/11/10/bdd-with-mspec-and-rhino-auto-mocks/" target="_blank">1</a>, <a href="http://telldontask.wordpress.com/2009/11/19/bdd-with-mspec-and-rhino-auto-mocks-part-2/" target="_blank">2</a>, and <a href="http://telldontask.wordpress.com/2009/11/29/bdd-with-mspec-and-rhino-auto-mocks-part-3/" target="_blank">3</a><br />
Here is the same specification using the RhinoAutoMocker&lt;T&gt; class provided by StructureMap.AutoMocking:</li>
</ul>
<pre class="brush: csharp;">[Subject(typeof(CoffeeMachine),"using RhinoAutoMocker&lt;CoffeeMachine&gt;")]
public class Example02_when_preparing_coffee_grounds
{
    Establish context = () =&gt;
        {
            CoffeeMachine = new RhinoAutoMocker&lt;CoffeeMachine&gt;();
            Grinder = CoffeeMachine.Get&lt;IGrinder&gt;();
            Hopper = CoffeeMachine.Get&lt;IHopper&gt;();
            Hopper.Expect(x =&gt; x.HasBeans()).Return(true);
        };

    Because of = () =&gt; v.ClassUnderTest.PrepareCoffeeGrounds(12);

    It should_check_if_hopper_has_beans = () =&gt; Hopper.VerifyAllExpectations();
    It should_grind_coffee = () =&gt; Grinder.AssertWasCalled(x =&gt; x.Grind(12));

    static IGrinder Grinder;
    static IHopper Hopper;
    static RhinoAutoMocker&lt;CoffeeMachine&gt; CoffeeMachine;
}</pre>
<p>Although I think this looks cleaner, the initialization of CoffeeMachine causes some confusion. Unfortunately, a common question would be, “Is RhinoAutoMocker&lt;CoffeeMachine&gt; creating a mocked version of CoffeeMachine?” Well, not exactly.</p>
<p>RhinoAutoMocker is an implementation of the AutoMocker base class which uses StructureMap to fill dependencies.  The RhinoAutoMocker implementation of the container uses Rhino.Mocks to generate all of dependencies of the target class, whereas the MoqAutoMocker implementation uses Moq.  (Optionally, the target class can be partially mocked in order to further isolate behavior.)  We then retrieve the class under test (in this case, CoffeeMachine) and its dependencies (IGrinder and IHopper) from the container for use.</p>
<p>If you do not need to setup any expectations in the specification, there is no need to retrieve the dependency from the container.  However, in this specification, we need both dependencies.</p>
<p><em>(Incidentally, I do not like the ClassUnderTest name.  I may end up changing this to Instance, ClassInstance, TargetClass, or something similar.  Suggestions?)</em></p>
<p>By moving the initialization of the RhinoAutoMocker to a base class, some of the chattiness of the context can be hidden.</p>
<ul>
<pre class="brush: csharp;">[Subject(typeof(CoffeeMachine),"using RhinoAutoMocker base")]
public class Example03_when_preparing_coffee_grounds : with_rhinoautomocker
{
    Establish context = () =&gt; Hopper.Expect(x =&gt; x.HasBeans()).Return(true);

    Because of = () =&gt; CoffeeMachine.ClassUnderTest.PrepareCoffeeGrounds(12);

    It should_check_if_hopper_has_beans = () =&gt; Hopper.VerifyAllExpectations();
    It should_grind_coffee = () =&gt; Grinder.AssertWasCalled(x =&gt; x.Grind(12));

}

[Subject("using RhinoAutoMocker&lt;T&gt;")]
public class with_rhinoautomocker
{
    protected static IGrinder Grinder;
    protected static IHopper Hopper;
    protected static RhinoAutoMocker&lt;CoffeeMachine&gt; CoffeeMachine;

    Establish context = () =&gt;
    {
        CoffeeMachine = new RhinoAutoMocker&lt;CoffeeMachine&gt;();
        Grinder = CoffeeMachine.Get&lt;IGrinder&gt;();
        Hopper = CoffeeMachine.Get&lt;IHopper&gt;();
    };
}</pre>
<p>However, we are still initializing and accessing the class in a less than optimal manner.To make the usage of the container a little more seamless, I decided to create a wrapper and factory for the AutoMocker.  Setup of the dependencies and expectations are done through an AutoMocker wrapper object.  The instance of the class under test is accessed through a ClassUnderTest object.</p>
<h4>The Result</h4>
<p>The specification (and base class) now look like this:</p>
<pre class="brush: csharp;">[Subject(typeof(CoffeeMachine),"using coffee machine base")]
public class Example05_when_preparing_coffee_grounds : with_coffee_machine
{
    Establish context = () =&gt; Hopper.Expect(x =&gt; x.HasBeans()).Return(true);

    Because of = () =&gt; ClassUnderTest.PrepareCoffeeGrounds(12);

    It should_check_if_hopper_has_beans = () =&gt; Hopper.VerifyAllExpectations();
    It should_grind_coffee = () =&gt; Grinder.AssertWasCalled(x =&gt; x.Grind(12));
}

[Subject("using SpecificationFor&lt;CoffeeMachine&gt;")]
public class with_coffee_machine : SpecificationFor&lt;CoffeeMachine&gt;
{
    protected static IGrinder Grinder;
    protected static IHopper Hopper;

    public with_coffee_machine
    {
        Grinder = AutoMocker.Get&lt;IGrinder&gt;();
        Hopper = AutoMocker.Get&lt;IHopper&gt;();
    }
}</pre>
<p>As you can see, the base class inherits from SpecificationFor&lt;T&gt;.  The default constructor uses Rhino.Mocks(MockMode.AAA) to generate the dependencies.  It then exposes a AutoMocker object, which is just the wrapper around the AutoMocker base class.  It also exposes a ClassUnderTest object.  If I didn’t need to use the dependencies, I could make the <em>Example05_when_preparing_coffee_grounds</em> class inherit from <em>SpecificationFor&lt;CoffeeMachine&gt; </em>instead of inheriting from the base class<em>.</em></p>
<h4>The Code</h4>
<p>I have included the code for the wrapper below for your review.  The code and six examples are available on my <a href="http://codeprogression.googlecode.com/svn/trunk/CodeProgression.Framework.Testing" target="_blank">Google code repository</a>. The repository also includes an example using the MoqAutoMocker.  All the examples have the same assertions, but are built up using the different techniques.</p>
<pre class="brush: csharp;">namespace CodeProgression.Framework.Testing
{
    public abstract class SpecificationFor&lt;T&gt; where T: class
    {
        protected static ClassUnderTest&lt;T&gt; Factory;

        // UPDATE 2009-12-21:
        //   Moved initialization here
        protected static T ClassUnderTest {get {return AutoMocker.Instance;} }

        protected SpecificationFor()
        {
            AutoMocker = AutoMockFactory.CreateTarget&lt;T&gt;();

            // UPDATE 2009-12-21:
            //    Initializing here prevented injected dependencies!
            // AutoMocker.PartialMockTheClassUnderTest();
            // ClassUnderTest = AutoMocker.Instance;
        }

        protected SpecificationFor(AutoMockType type)
        {
            AutoMocker = AutoMockFactory.CreateTarget&lt;T&gt;(type);

            // UPDATE 2009-12-21:
            // Initializing here prevented injected dependencies!
            // AutoMocker.PartialMockTheClassUnderTest();
            // ClassUnderTest = AutoMocker.Instance;
        }
    }

    public static class AutoMockFactory
    {
        public static ClassUnderTest&lt;TARGETCLASS&gt; CreateTarget&lt;TARGETCLASS&gt;() where TARGETCLASS : class
        {
            return CreateTarget&lt;TARGETCLASS&gt;(AutoMockType.RhinoMocksAAA);
        }

        public static ClassUnderTest&lt;TARGETCLASS&gt; CreateTarget&lt;TARGETCLASS&gt;(AutoMockType framework) where TARGETCLASS : class
        {
            AutoMocker&lt;TARGETCLASS&gt; mocker;
            ServiceLocator serviceLocator;
            switch (framework)
            {
                case AutoMockType.RhinoMocksAAA:
                    mocker = new RhinoAutoMocker&lt;TARGETCLASS&gt;(MockMode.AAA);
                    serviceLocator = new RhinoMocksAAAServiceLocator();
                    break;
                case AutoMockType.RhinoMocksClassic:
                    mocker = new RhinoAutoMocker&lt;TARGETCLASS&gt;(MockMode.RecordAndReplay);
                    serviceLocator = new RhinoMocksClassicServiceLocator();
                    break;
                case AutoMockType.Moq:
                    mocker = new MoqAutoMocker&lt;TARGETCLASS&gt;();
                    serviceLocator = new MoqServiceLocator();
                    break;
                default:
                    throw new ArgumentOutOfRangeException("framework");
            }
            return new ClassUnderTest&lt;TARGETCLASS&gt;(mocker, serviceLocator);
        }
    }

    public enum AutoMockType
    {
        Moq,
        RhinoMocksAAA,
        RhinoMocksClassic
    }

    public class ClassUnderTest&lt;TARGETCLASS&gt; where TARGETCLASS : class
    {
        readonly IAutoMocker&lt;TARGETCLASS&gt; _mocker;
        readonly ServiceLocator _serviceLocator;

        public ClassUnderTest(IAutoMocker&lt;TARGETCLASS&gt; mocker, ServiceLocator serviceLocator)
        {
            _mocker = mocker;
            _serviceLocator = serviceLocator;
        }

        public AutoMockedContainer Container
        {
            get { return _mocker.Container; }
        }

        public TARGETCLASS Instance
        {
            get { return _mocker.ClassUnderTest; }
        }

        public void MockObjectFactory()
        {
            _mocker.MockObjectFactory();
        }

        public void PartialMockTheClassUnderTest()
        {
            _mocker.PartialMockTheClassUnderTest();
        }

        public T Get&lt;T&gt;() where T : class
        {
            return _mocker.Get&lt;T&gt;();
        }

        public void Inject(Type pluginType, object stub)
        {
            _mocker.Inject(pluginType, stub);
        }

        public void Inject&lt;T&gt;(T target)
        {
            _mocker.Inject(target);
        }

        public T AddAdditionalMockFor&lt;T&gt;() where T : class
        {
            return _mocker.AddAdditionalMockFor&lt;T&gt;();
        }

        public void UseConcreteClassFor&lt;T&gt;()
        {
            _mocker.UseConcreteClassFor&lt;T&gt;();
        }

        public T[] CreateMockArrayFor&lt;T&gt;(int count) where T : class
        {
            return _mocker.CreateMockArrayFor&lt;T&gt;(count);
        }

        public void InjectArray&lt;T&gt;(T[] stubs)
        {
            _mocker.InjectArray(stubs);
        }

        public T Mock&lt;T&gt;() where T : class
        {
            return _serviceLocator.Service&lt;T&gt;();
        }
        public object Mock(Type serviceType)
        {
            return _serviceLocator.Service(serviceType);
        }
        public T PartialMock&lt;T&gt;() where T : class
        {
            return _serviceLocator.PartialMock&lt;T&gt;();
        }
    }
}</pre>
</ul>
<p><script type="text/javascript">// <![CDATA[
 var cirerolGaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + cirerolGaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
// ]]&gt;</script></p>
<p><script type="text/javascript">// <![CDATA[
 var cirerolPageTracker = _gat._getTracker('UA-8257866-3'); cirerolPageTracker._initData(); cirerolPageTracker._trackPageview();
// ]]&gt;</script></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/11/30/wrapping-up-the-structuremap-automocking-container/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>State Pattern, Enumeration Class and Fluent NHibernate (Oh my!)</title>
		<link>http://elegantcode.com/2009/11/01/state-pattern-enumeration-class-and-fluent-nhibernate-oh-my/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=state-pattern-enumeration-class-and-fluent-nhibernate-oh-my</link>
		<comments>http://elegantcode.com/2009/11/01/state-pattern-enumeration-class-and-fluent-nhibernate-oh-my/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 04:20:10 +0000</pubDate>
		<dc:creator>Richard Cirerol</dc:creator>
				<category><![CDATA[.Net 3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Fluent NHibernate;State Pattern;Enumeration]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/11/01/state-pattern-enumeration-class-and-fluent-nhibernate-oh-my/</guid>
		<description><![CDATA[Recently, I needed to change a basic enumeration into a full-fledged state pattern. After getting all my domain classes updated, I began reviewing the persistence layer. And I hit a wall.  I wasn’t sure how I wanted to update my Fluent NHibernate convention to persist the current state.]]></description>
			<content:encoded><![CDATA[<p>Recently, I needed to change a basic enumeration into a full-fledged state pattern. After getting all my domain classes updated, I began reviewing the persistence layer. And I hit a wall.  I wasn’t sure how I wanted to update my Fluent NHibernate convention to persist the current state.</p>
<p>My original classes were similar to this:</p>
<pre class="brush: csharp;">public class MyProgress{
   public virtual Guid Id { get; set; }
   ...
   ...
   public virtual MyStatus Status { get; private set; }
}

public enum MyStatus{
   New,
   InProgress,
   Completed,
   Canceled,
   Failed
}
</pre>
<p>My new state pattern was similar to this:</p>
<pre class="brush: csharp;">
public abstract class MyStatus
{
    public static readonly MyStatus New = new NewStatus();
    public static readonly MyStatus InProgress = new InProgressStatus();
    ...
}

public class NewStatus: MyStatus
{
    public override void Start(MyProgress progress)
    {
        progress.SetStatus(InProgress);
    }
    public override void Cancel(MyProgress progress)
    {
        progress.SetStatus(Cancelled);
    }
    public override void Fail(MyProgress progress)
    {
            progress.SetStatus(Failed);
    }
}
...
</pre>
<p>Here is the problem… My enumeration was persisted as an integer field on the record. Now that I had a state pattern, how should I save my state? I googled the problem and found <a href="http://www.lostechies.com/blogs/derickbailey/archive/2008/11/26/mapping-a-state-pattern-with-nhibernate.aspx" target="_blank">Derick Bailey’s article</a> on the state pattern and Fluent NHibernate. Derick’s pattern works well, but I felt that creating a lookup table in my database just so I can persist a value in another table was not the path I wanted to traverse – I wasn’t persisting an entity, I was persisting a state value on an entity. Not finding any more love from Google, I asked around and was advised to contact fellow Elegant Coder and <a href="http://guild3.com" target="_blank">Guild3</a> member, <a href="http://elegantcode.com/author/jgrundy/" target="_blank">Jason Grundy</a>. Here is Jason’s advice:</p>
<blockquote><p>&#8220;I&#8217;ve recently changed from using Enums to an approach outlined by Jimmy Bogard <a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/08/12/enumeration-classes.aspx">here</a>.  In the Entity I would do something like this:</p>
<pre class="brush: csharp;">
protected int _orderStatusId;
public virtual OrderStatus OrderStatus
{
    get { return Enumeration.FromValue&lt;OrderStatus&gt;(_orderStatusId); }
    set { _orderStatusId = value.Value; }
}
</pre>
<p>Then in Fluent NH you can simply map to the protected member.&#8221;</p></blockquote>
<p>I decided to pursue Jason’s advice.  The result is my database tables did not need to change at all. Here is some snippets of the updated classes:</p>
<pre class="brush: csharp;">
public class MyProgress
{
     public virtual Guid Id {get;set;}
     ...
     protected int _status;
     public virtual MyStatus
     {
         get{ return Enumeration.FromValue&lt;MyStatus&gt;(_status); }
         set{ _status = value.Value; }
     }
     ...
}

public class MyStatus : Enumeration
{
     public static MyStatus New = new NewStatus();
     ...

     private class NewStatus : MyStatus
    {
         public NewStatus() : base (0,"New"){}

         public override void Start(MyProgress progress)
         {
             progress.SetStatus(InProgress);
         }
    }
     ...
</pre>
<p>Notice that the MyStatus class is no longer abstract.  However, the subclasses are all private nested classes, each with a value and a display name.  I set each subclass value to match the enumeration value it replaced.  I did not need to convert my existing data to a new schema.</p>
<p>And here is the Fluent NHibernate override:</p>
<pre class="brush: csharp;">
public class MyProgressOverride : IAutoMappingOverride&lt;MyProgress&gt;
{
    public void Override(AutoMapping&lt;MyProgress&gt; mapping)
    {
        mapping.Map(x =&gt; x.Status)
            .CustomType(typeof(int))
            .Access.CamelCaseField(Prefix.Underscore);
    }
}
</pre>
<p>As you can see, we use convention-based automapping with overrides, but this same map could be used in a standard class map.</p>
<p>Thanks to Jimmy, Derick, and Jason for the inspiration and assistance!</p>
<p><script type="text/javascript"> 
var cirerolGaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + cirerolGaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script><br />
<script type="text/javascript"> 
var cirerolPageTracker = _gat._getTracker('UA-8257866-3');
cirerolPageTracker._initData();
cirerolPageTracker._trackPageview();
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/11/01/state-pattern-enumeration-class-and-fluent-nhibernate-oh-my/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>AutoMapper Introduction and Samples from NETDUG</title>
		<link>http://elegantcode.com/2009/10/06/automapper-introduction-and-samples-from-netdug/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automapper-introduction-and-samples-from-netdug</link>
		<comments>http://elegantcode.com/2009/10/06/automapper-introduction-and-samples-from-netdug/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 05:08:11 +0000</pubDate>
		<dc:creator>Richard Cirerol</dc:creator>
				<category><![CDATA[Esoterica]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/10/06/automapper-introduction-and-samples-from-netdug/</guid>
		<description><![CDATA[In September, Cory Isakson and I presented AutoMapper to the Boise .NET Developer User Group (NETDUG).&#160; As promised, I have included the sample code here.&#160; AutoMapper 1.0 RC1 is available on the CodePlex site. At my company, we have embraced convention-over-configuration throughout our applications, from our data access framework (Fluent NHibernate) to our IoC container [...]]]></description>
			<content:encoded><![CDATA[<p><em>In September, Cory Isakson and I presented AutoMapper to the Boise .NET Developer User Group (NETDUG).&#160; As promised, I have included the sample code </em><a href="http://code.google.com/p/codeprogression/source/browse/sample-projects" target="_blank"><em><strong>here</strong></em></a><em>.&#160; AutoMapper 1.0 RC1 is available on the <a href="automapper.codeplex.com" target="_blank">CodePlex</a> site. </em></p>
<p>At my company, we have embraced convention-over-configuration throughout our applications, from our data access framework (Fluent NHibernate) to our IoC container (StructureMap) to our build scripts to our…well, you get the picture.&#160; However, we had been hitting a pain point in our application when trying to serialize our domain objects for transport across the WCF service layer.&#160; We were also seeing some issues with using domain objects directly in our MVC views. The old way would have been to write that boring left-hand/right-hand code.&#160; We all know that left-hand/right-hand code is ugly and pollutes the methods that should be doing real work with ceremonious busy work.&#160; </p>
<p>Well, just as we were really getting stung by these pain points, Cory and I started talking about AutoMapper.&#160; Now, for those who have no idea what AutoMapper is, check out the <a href="http://automapper.codeplex.com/Wiki/View.aspx?title=Getting%20Started" target="_blank">Getting Started</a> page on <a href="http://automapper.codeplex.com/" target="_blank">CodePlex</a>.&#160; If you want to check out the source, go to the <a href="http://code.google.com/p/automapperhome/" target="_blank">Google code</a> site.&#160; Jimmy Bogard, the AutoMapper author, describes the AutoMapper as a convention-based object-to-object mapper.</p>
<p>&#160;</p>
<h2>Different Means to an End</h2>
<p>&#160;</p>
<p>Here is the basic idea… In the past, I would write this classic chunk of code:</p>
<pre class="brush: csharp;">var meeting = _repository.GetMeetingById(meetingId);
var dto = new MeetingDto();
dto.Begins = meeting.Begins;
dto.End = meeting.End;
dto.Attendees = meeting.Attendees;
dto.AttendeesCount = meeting.Attendees.Count;
//do something meaningful</pre>
<p>With AutoMapper, I can write this instead:</p>
<pre class="brush: csharp;">var meeting = _repository.GetMeetingById(meetingId);
var dto = Mapper.Map&lt;Meeting, MeetingDto&gt;(meeting);
//do something meaningful</pre>
<p>&#160;</p>
<p>Herein lies the beauty of AutoMapper.&#160; When your classes align themselves <em>conventionally</em>, your mapping configuration can be as simple as: </p>
<pre class="brush: csharp;">CreateMap&lt;Meeting,MeetingDto&gt;();</pre>
<p>This is a trivial example, but where AutoMapper shines is in the ability to map lists and nested properties by convention. Or constructing an object based on another object’s properties.&#160; All without littering a method with ceremonial code.</p>
<p>Using an object-to-object mapper does have its drawbacks:</p>
<ol>
<li>The classic left-hand/right-hand code performs faster than mapped code, although Jimmy has made great strides in increasing performance. </li>
<li>When defining unconventional mappings, you will still have left-hand/right-hand code </li>
<li>There will be a learning curve for you (and/or your team) if you have not had experience with convention-based frameworks or some of the .NET 3.5 features. </li>
</ol>
<p><em><strong>However, we have found these drawbacks to be <u>trivial</u> when compared to the benefits.</strong></em></p>
<p>&#160;</p>
<h2>Mapping Toolset</h2>
<p>In addition to providing the convention mappings, Jimmy has provided a toolset for enhancing the mappings. Listed here are several tools we either use or find compelling. </p>
<p><strong>Custom Converters</strong>: Code to convert from source type to destination type. Defined once and implicitly used for all mappings.&#160; </p>
<p><strong>Custom Resolvers</strong>: Code to convert from source value to destination value.&#160; Defined once for use by any mapping, but must be explicitly used by a mapping. </p>
<p><strong>Custom Formatters</strong>: Code to reformat a type for presentation.&#160; Like resolvers, formatters are defined once and explicitly used. </p>
<p><strong>Before/After Map Functions</strong>: Provides the ability to run custom code before or after the mappings are performed. </p>
<p><strong>Validation Assertion</strong>: Provides a method to short-circuit at runtime (or in tests) with an explanatory exception when a mapping may cause failures.&#160; </p>
<p><strong>Mapping Profiles</strong>: Profile is a base class that helps you organize your code.&#160; If you are familiar with StructureMap’s Registry class, you will feel right at home with the Profile class.</p>
<p>&#160;</p>
<h2>Where We Use AutoMapper</h2>
<p>&#160;</p>
<p>We use AutoMapper to transform our object model to our presentation model.&#160; This happens in two places – in our MVC controllers and at our WCF service layer.</p>
<p>In the controllers, we will map from a domain model or DTO into the view model.&#160; We will also map from our view model into a message object for use by the service or domain.</p>
<p>At the service layer, we flatten our domain model into a DTO or map a message object to run a command against the domain.</p>
<p>&#160;</p>
<h2>Code Samples</h2>
<p>&#160;</p>
<p>I am including the sample code used at the NETDUG meeting.&#160; The <a href="http://code.google.com/p/codeprogression/source/browse/sample-projects/NETDUGSample1.zip" target="_blank">first sample</a> shows different ways to setup mappings (inline vs. profiles).&#160; The <a href="http://code.google.com/p/codeprogression/source/browse/sample-projects/NETDUGSample2.zip" target="_blank">second sample</a> shows some usages of custom resolvers, formatters, and before-maps.</p>
<p>Download the AutoMapper source.&#160; Jimmy has provided many sample classes and unit tests showing off the usage of different conventions.&#160; </p>
<p>Matt Hinze also <a href="http://mhinze.com/automapper-in-nerddinner/" target="_blank">posted</a> a sample solution using AutoMapper with NerdDinner (of which I borrowed some custom formatter code – Thanks Matt!). </p>
<p>Download the <a href="http://code.google.com/p/codecampserver/" target="_blank">CodeCampServer source</a>.&#160; It is full of examples and conventions, including using an IoC/DI implementation of the AutoMapper engine.</p>
<p><script type="text/javascript"> 
var cirerolGaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + cirerolGaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script><br />
<script type="text/javascript"> 
var cirerolPageTracker = _gat._getTracker('UA-8257866-3');
cirerolPageTracker._initData();
cirerolPageTracker._trackPageview();
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/10/06/automapper-introduction-and-samples-from-netdug/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

