<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>public abstract string[] Blog() &#187; TDD</title>
	<atom:link href="http://extractmethod.wordpress.com/category/tdd/feed/" rel="self" type="application/rss+xml" />
	<link>http://extractmethod.wordpress.com</link>
	<description>Wandering the Internet is search of better code and coding techniques</description>
	<lastBuildDate>Sat, 21 Jun 2008 14:01:14 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='extractmethod.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/aa59efbf3eef34a86e290a03a0aeb4a1?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>public abstract string[] Blog() &#187; TDD</title>
		<link>http://extractmethod.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://extractmethod.wordpress.com/osd.xml" title="public abstract string[] Blog()" />
		<item>
		<title>A Simple DataTable Constraint for RhinoMocks</title>
		<link>http://extractmethod.wordpress.com/2008/02/07/a-simple-datatable-constraint-for-rhinomocks/</link>
		<comments>http://extractmethod.wordpress.com/2008/02/07/a-simple-datatable-constraint-for-rhinomocks/#comments</comments>
		<pubDate>Thu, 07 Feb 2008 07:08:16 +0000</pubDate>
		<dc:creator>casademora</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[constrain]]></category>
		<category><![CDATA[DataTable]]></category>
		<category><![CDATA[RhinoMocks]]></category>
		<category><![CDATA[tests]]></category>
		<category><![CDATA[unit]]></category>

		<guid isPermaLink="false">http://extractmethod.wordpress.com/2008/02/07/a-simple-datatable-constraint-for-rhinomocks/</guid>
		<description><![CDATA[I&#8217;ve been a huge fan of Rhino Mocks since I heard about it on a way-back-episode of Dot Net Rocks HanselMinutes. One of the more awesome features of Rhino Mocks is that it utilizes a Record/Playback semantic so that you can set up your mocks with actual calls to the mock objects, then play them [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=extractmethod.wordpress.com&blog=2356552&post=17&subd=extractmethod&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been a huge fan of <a href="http://www.ayende.com/projects/rhino-mocks.aspx">Rhino Mocks</a> since I heard about it on a way-back-episode of <strike><a href="http://www.dotnetrocks.com">Dot Net Rocks</a></strike> <a href="http://hanselminutes.com/default.aspx?showID=43">HanselMinutes</a>. One of the more awesome features of Rhino Mocks is that it utilizes a Record/Playback semantic so that you can set up your mocks with actual calls to the mock objects, then play them back in your tests. This is great if you rely on intellisense when calling your object instances, or if you use <a href="http://www.jetbrains.com/resharper">Resharper</a> or another code refactoring tool.</p>
<p>Recently, I trying to use Rhino Mocks with DataTables like so:</p>
<blockquote>
<pre>DataTable a = <span class="kwrd">new</span> DataTable();
DataTable b = <span class="kwrd">new</span> DataTable(); 

MockObject mock = mockRepository.CreateMock&lt;MockObject&gt;();

<span class="kwrd">using</span> (mockRepository.Record())
{
   Expect.Call(mock.CreateRecord(<span class="str">"TableName"</span>, a, b).Return(1);
}
<span class="kwrd">using</span> (mockRepository.Playback())
{
  MyObject obj = <span class="kwrd">new</span> MyObject(mock);
  obj.Save();
}</pre>
</blockquote>
<p>When I ran the test, Rhino Mocks says that a the DataTable created during the obj.Save() call wasn&#8217;t the same as the one expected. This was correct as there were now two instances, and it seems that the default check Rhino Mocks performs is an Object.Equals(). Since I needed to do some more deep comparisons of the Expected and Actual DataTables, a fellow developer and I started a very simple DataTableConstraint:</p>
<div class="csharpcode">
<pre>    <span class="kwrd">class</span> DataTableConstraint : AbstractConstraint
    {
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> DataTable _expected;
        <span class="kwrd">private</span> <span class="kwrd">string</span> _errorMessage;

        <span class="kwrd">public</span> DataTableConstraint(DataTable expected)
        {
            _expected = expected;
        }

        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">bool</span> Eval(<span class="kwrd">object</span> obj)
        {
            DataTable actual = obj <span class="kwrd">as</span> DataTable;
            <span class="kwrd">if</span> (actual == <span class="kwrd">null</span>)
                <span class="kwrd">return</span> <span class="kwrd">false</span>;

            <span class="kwrd">if</span> (!CheckColumns(actual))
            {
                <span class="kwrd">return</span> <span class="kwrd">false</span>;
            }
            <span class="kwrd">if</span> (!CheckData(actual))
            {
                <span class="kwrd">return</span> <span class="kwrd">false</span>;
            }
            <span class="kwrd">return</span> <span class="kwrd">true</span>;
        }

        <span class="kwrd">private</span> <span class="kwrd">bool</span> CheckData(DataTable actual)
        {
            <span class="kwrd">if</span> (actual.Rows.Count == 0)
            {
                _errorMessage = <span class="str">"Actual table has no data to compare"</span>;
                <span class="kwrd">return</span> <span class="kwrd">false</span>;
            }
            <span class="kwrd">try</span>
            {
                <span class="kwrd">for</span> (<span class="kwrd">int</span> i=0; i &lt; _expected.Rows.Count; i++)
                {
                    <span class="kwrd">foreach</span> (DataColumn column <span class="kwrd">in</span> _expected.Columns)
                    {
                        <span class="kwrd">object</span> expectedCell = _expected.Rows[i][column];
                        <span class="kwrd">object</span> actualCell = actual.Rows[i][column];

                        <span class="kwrd">if</span> (expectedCell != actualCell)
                        {
                            _errorMessage = <span class="kwrd">string</span>.Format(<span class="str">"Expected {0} in Row ({1}), Column ({2}), but was {3}"</span>, expectedCell, i, column.ColumnName, actualCell);
                            <span class="kwrd">return</span> <span class="kwrd">false</span>;
                        }
                    }
                }
                <span class="kwrd">return</span> <span class="kwrd">true</span>;
            }
            <span class="kwrd">catch</span> (System.Exception e)
            {
                _errorMessage = e.Message;
                <span class="kwrd">return</span> <span class="kwrd">false</span>;
            }
        }

        <span class="kwrd">private</span> <span class="kwrd">bool</span> CheckColumns(DataTable actual)
        {
            <span class="kwrd">foreach</span> (DataColumn column <span class="kwrd">in</span> _expected.Columns)
            {
                <span class="kwrd">if</span> (!actual.Columns.Contains(column.ColumnName))
                {
                    _errorMessage = <span class="kwrd">string</span>.Format(<span class="str">"Could not find column {0} in {1}"</span>, column, actual);
                    <span class="kwrd">return</span> <span class="kwrd">false</span>;
                }
            }
            <span class="kwrd">return</span> <span class="kwrd">true</span>;
        }

        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> Message
        {
            get { <span class="kwrd">return</span> _errorMessage; }
        }
    }</pre>
</div>
<p>To use this using the above sample code, do</p>
<blockquote>
<pre>Expect.Call(mock.CreateRecord(<span class="kwrd">null</span>, <span class="kwrd">null</span>, <span class="kwrd">null</span>).Constraints
(
  Is.Anything(),
  <span class="kwrd">new</span> DataTableConstraint(a),
  <span class="kwrd">new</span> DataTableConstraint(b)
);</pre>
</blockquote>
<p>Now, this is just a start, and will probably evolve more as I start to get more into verifying the data in two tables. Perhaps <a href="http://www.ayende.com/default.aspx">Oren</a> will create a new Syntax Helper along the lines of Data.Equals(expectedDataTable) since using a new Constraint() call is a little awkward.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/extractmethod.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/extractmethod.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/extractmethod.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/extractmethod.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/extractmethod.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/extractmethod.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/extractmethod.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/extractmethod.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/extractmethod.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/extractmethod.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/extractmethod.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/extractmethod.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=extractmethod.wordpress.com&blog=2356552&post=17&subd=extractmethod&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://extractmethod.wordpress.com/2008/02/07/a-simple-datatable-constraint-for-rhinomocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4c5bc935da066bf73113e426f396ba60?s=96&#38;d=identicon" medium="image">
			<media:title type="html">casademora</media:title>
		</media:content>
	</item>
		<item>
		<title>Integrating ANTLR Code Generation with Visual Studio 2008</title>
		<link>http://extractmethod.wordpress.com/2008/01/02/integrating-antlr-code-generation-with-visual-studio-2008/</link>
		<comments>http://extractmethod.wordpress.com/2008/01/02/integrating-antlr-code-generation-with-visual-studio-2008/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 23:44:04 +0000</pubDate>
		<dc:creator>casademora</dc:creator>
				<category><![CDATA[ANTLR]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[DRY]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[msbuild]]></category>

		<guid isPermaLink="false">http://extractmethod.wordpress.com/2008/01/02/integrating-antlr-code-generation-with-visual-studio-2008/</guid>
		<description><![CDATA[ANTLR is a DSL tool that can generate a language parser based on a grammar (*.g) file. From there, you hook into the parser so that your code can interpret the language into constructs your application can understand. But, in order to get your grammar file correct, you make end up using a variety of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=extractmethod.wordpress.com&blog=2356552&post=6&subd=extractmethod&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://www.antlr.org/">ANTLR</a> is a DSL tool that can generate a language parser based on a grammar (*.g) file. From there, you hook into the parser so that your code can interpret the language into constructs your application can understand. But, in order to get your grammar file correct, you make end up using a variety of development methods such as TDD, and all of them will have the same step: run the <a href="http://www.antlr.org/works">ANTLR tool</a> against your grammar file to generate your parser code.The ANTLR web site has <a href="http://www.antlr.org/wiki/display/ANTLR3/Integration+with+development+environments" title="Integrating ANTLR With other development environments">an article</a> on <a href="http://www.antlr.org/wiki/display/ANTLR3/ANTLR+v3+documentation" title="ANTLR Documentation Wiki">its wiki</a> that will let you integrate the ANTLR tool into your Visual Studio Build process. Follow the steps outlined in that article <b>first</b>.  Since VS 2008 project files are basically MS Build files, the steps work almost verbatim. However, here are a few caveats I encountered:The Exec command in the <b>GenerateAntlrCode</b> target needed some <i>classpath</i> modifications. Basically, I needed to tell <a href="http://java.sun.com/">java</a> where the Antlr jar file was located. Here is what I ended up with:
<div class="csharpcode">
<pre><span class="lnum">1:  </span><span class="kwrd">&lt;</span><span class="html">Target</span> <span class="attr">Name</span><span class="kwrd">="GenerateAntlrCode"</span> <span class="attr">Inputs</span><span class="kwrd">="@(Antlr3)"</span> <span class="attr">Outputs</span><span class="kwrd">="%(Antlr3.OutputFiles)"</span><span class="kwrd">&gt;</span> <span class="lnum">   </span> <span class="lnum">2:  </span>    <span class="kwrd">&lt;</span><span class="html">Exec</span> <span class="attr">Command</span><span class="kwrd">="java -cp %22$(Antlr3ToolPath)\antlr.jar;$(Antlr3ToolPath)\antlr-3.0.1.jar;$(Antlr3ToolPath)\stringtemplate-3.1b1.jar%22 org.antlr.Tool -message-format vs2005 -lib $(AntlrGrammarPath)  @(Antlr3)"</span> <span class="attr">Outputs</span><span class="kwrd">="%(Antlr3.OutputFiles)"</span> <span class="kwrd">/&gt;</span> <span class="lnum">   </span> <span class="lnum">3:  </span>  <span class="kwrd">&lt;/</span><span class="html">Target</span><span class="kwrd">&gt;</span></pre>
</div>
<p>A couple of notes regarding this target:
<ul>
<li>%22 is the escaped form of double-quotes (&#8220;)</li>
<li>I decided to create a build variable so that any changes to a path was updated everywhere (<a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY principle</a>).</li>
<li>You need to reference several jars:
<ul>
<li>antlr.jar -&gt; The Antlr 2.7.7 tool</li>
<li>antlr-3.0.1.jar -&gt; The Antlr 3.0.1 tool</li>
<li>stringtemplate-3.1b1.jar -&gt; The String Template library</li>
</ul>
</li>
</ul>
<p>The antlr 2.7.7 jar is needed for the StreamToken class that seems to be in a different namespace than the 3.0.1 jar.The properties called Antlr3ToolPath and Antlr3GrammarPath are defined in a property group like so:
<div class="csharpcode">
<pre><span class="lnum">1:  </span>  <span class="kwrd">&lt;</span><span class="html">PropertyGroup</span><span class="kwrd">&gt;</span> <span class="lnum">   </span> <span class="lnum">2:  </span>    <span class="kwrd">&lt;</span><span class="html">Antlr3ToolPath</span><span class="kwrd">&gt;</span>$(MSBuildProjectDirectory)\..\..\Tools\ANTLR<span class="kwrd">&lt;/</span><span class="html">Antlr3ToolPath</span><span class="kwrd">&gt;</span> <span class="lnum">  </span> <span class="lnum">3:  </span>    <span class="kwrd">&lt;</span><span class="html">AntlrGrammarPath</span><span class="kwrd">&gt;</span>$(MSBuildProjectDirectory)\Model\Parsers<span class="kwrd">&lt;/</span><span class="html">AntlrGrammarPath</span><span class="kwrd">&gt;</span> <span class="lnum">   </span> <span class="lnum">4:  </span>    <span class="kwrd">&lt;</span><span class="html">BuildDependsOn</span><span class="kwrd">&gt;</span>GenerateAntlrCode;$(BuildDependsOn)<span class="kwrd">&lt;/</span><span class="html">BuildDependsOn</span><span class="kwrd">&gt;</span> <span class="lnum">   </span> <span class="lnum"><span class="lnum">5:  </span>  <span class="kwrd">&lt;/</span><span class="html">PropertyGroup</span><span class="kwrd">&gt;</span></span></pre>
</div>
<p>The reason the GrammarPath is basically pointing to the output folder of the parser. This is needed because I am using the ANTLR output option of AST, which generates an Abstract Syntax Tree that much be consumed by another ANTLR grammar. For more details on why you need two grammar files for this process, I recommend the book The Definitive ANTLR Reference, by Terrence Parr.After that, I was able to use Visual Studio to generate the code on every build of the code. When using TDD tools like <a href="http://www.jetbrains.net/resharper">resharper</a> or <a href="http://www.testdriven.net">testdriven.net</a>, this is an added bonus in that any changes made to the grammar are incorporated in my unit tests. Bonus number 2: since the changes are within the project file itself, and since my continuous integration server is based on my Visual Studio Solution file, the grammar files are also included on my build server and will cause the build to fail if the grammar fails to compile.I hope your build goes just as nicely.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/extractmethod.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/extractmethod.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/extractmethod.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/extractmethod.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/extractmethod.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/extractmethod.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/extractmethod.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/extractmethod.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/extractmethod.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/extractmethod.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/extractmethod.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/extractmethod.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=extractmethod.wordpress.com&blog=2356552&post=6&subd=extractmethod&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://extractmethod.wordpress.com/2008/01/02/integrating-antlr-code-generation-with-visual-studio-2008/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4c5bc935da066bf73113e426f396ba60?s=96&#38;d=identicon" medium="image">
			<media:title type="html">casademora</media:title>
		</media:content>
	</item>
	</channel>
</rss>