<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Derik Whittaker : HowTo, Agile</title><link>http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/Agile/default.aspx</link><description>Tags: HowTo, Agile</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Testing that EventHandlers were wired up correctly with NUnit and Rhino Mocks</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2010/08/24/testing-that-eventhandlers-were-wired-up-correctly-with-nunit-and-rhino-mocks.aspx</link><pubDate>Tue, 24 Aug 2010 11:04:04 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:61665</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=61665</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=61665</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2010/08/24/testing-that-eventhandlers-were-wired-up-correctly-with-nunit-and-rhino-mocks.aspx#comments</comments><description>&lt;p&gt;Today I was trying to wrap some code in some tests (I got lazy and did not create the tests first… shot me).&amp;#160; What I was trying to ensure was that my event handlers I passed into a method were actually being wired up for usage.&amp;#160; Now I searched around the net for a while to see if there was a elegant solution to this problem but I could not find one.&amp;#160; Below is the solution I came up with.&amp;#160; Mind you this may not be a great solution, hell it may just down right suck but it works for me.&lt;/p&gt;  &lt;p&gt;First things first, her is the method i was trying to provide coverage for&lt;/p&gt;  &lt;pre class="c-sharp" name="code"&gt;public void GetAppointments( DateTime? from, DateTime? to, 
    EventHandler localRequestStarted,
    EventHandler remoteRequestStarted,
    EventHandler&lt;object&gt;&amp;gt; requestFinsished )
{
    var currentUser = _sessionManager.GetValue();
    var dataRequest = new AppointmentDataRequest( new AppointmentParameterContext( currentUser.ResourceIds, from.Value, to.Value ) );

    dataRequest.LocalRequestStarted += localRequestStarted;
    dataRequest.RemoteRequestStarted += remoteRequestStarted;
    dataRequest.RequestFinished += requestFinsished;

    _dataManager.Fetch( dataRequest );
}
&lt;/pre&gt;

&lt;p&gt;As you can see there are 3 lines in the above code where the passed in EventHandlers are being attached.&amp;#160; I wanted to ensure this. But what you may also see is that I have no direct access to the dataRequest object which is being created in this method.&amp;#160; That is where our handy rhino mocks library comes in.&amp;#160; With Rhino Mocks I am able to get the pointer to the various values which are passed into methods.&amp;#160; Check out the test below and you will see how this is done.&lt;/p&gt;

&lt;p&gt;My unit test&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;[Test]
public void GetAppointments_WhenCalled_EnsureWillWireupEventsCorrectly()
{
    var dataManager = MockRepository.GenerateMock&amp;lt;IDataManager&amp;gt;();
    var sessionManager = MockRepository.GenerateMock&amp;lt;ISessionManager&amp;gt;();

    var currentUser = new CurrentUser();
    sessionManager.Stub( x =&amp;gt; x.GetValue&amp;lt;CurrentUser&amp;gt;() ).Return( currentUser );

    var provider = new AppointmentProvider( dataManager, null, sessionManager, null );
    bool localWired = false, remoteWired = false, requestFinishedWired = false;

    EventHandler&amp;lt;LocalRequestStartedEventArgs&amp;gt; localRequest = ( s, arg ) =&amp;gt; { localWired = true; };
    EventHandler&amp;lt;RemoteRequestStartedEventArgs&amp;gt; remoteRequest = ( s, arg ) =&amp;gt; { remoteWired = true; };
    EventHandler&amp;lt;RequestFinishedEventArgs&amp;lt;object&amp;gt;&amp;gt; requestFinished = ( s, arg ) =&amp;gt; { requestFinishedWired = true; };

    provider.GetAppointments( DateTime.Now, DateTime.Now, localRequest, remoteRequest, requestFinished );

    IList&amp;lt;object[]&amp;gt; argumentsForCallsMadeOn = dataManager.GetArgumentsForCallsMadeOn( x =&amp;gt; x.Fetch( Arg&amp;lt;DataRequest&amp;gt;.Is.Anything ) );

    var dataRequest = (AppointmentDataRequest)argumentsForCallsMadeOn[ 0 ][ 0 ];

    dataRequest.RaiseLocalRequestStarted();
    dataRequest.RaiseRemoteRequestStarted();
    dataRequest.RaiseDataRequestFinished( DataRequestType.UserLogin, DataRequestResult.Unknown, null, null );

    Assert.That( localWired, Is.True );
    Assert.That( remoteWired, Is.True );
    Assert.That( requestFinishedWired, Is.True );

}&lt;/pre&gt;

&lt;p&gt;As you can see this test has a lot going on, but let me explain some of this for you.&lt;/p&gt;

&lt;p&gt;1) First thing we need to do is create a few local variables which will hold the state of the event firing&lt;/p&gt;

&lt;p&gt;2) Next we want to create local copies of our event delegates in order to push them into our method&lt;/p&gt;

&lt;p&gt;3) Next is time for the Rhino Mock magic.&amp;#160; Notice how I am calling the GetargumentsForCallsMadeOn() method.&amp;#160; This is a method in Rhino Mocks which allows me to reach into the call stack and pull out the values which were pushed into a method when it was called.&amp;#160; I then cast the argument i want to its native type.&lt;/p&gt;

&lt;p&gt;4) In order to ensure the events were wired up I need to call the various ‘raise’ methods in order to trigger them.&amp;#160; Doing this should cause my local state holders for the events to be changed and this is what we actually want to ensure&lt;/p&gt;

&lt;p&gt;5) Ensure the event state variables were set to true.&lt;/p&gt;

&lt;p&gt;There you have it, a simple (well kinda) way to ensure that your events have been registered correctly in your code.&lt;/p&gt;

&lt;p&gt;Till next time,&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;/object&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=61665" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Agile/default.aspx">Agile</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/.Net/default.aspx">.Net</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/TDD/default.aspx">TDD</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Rhino+Mocks/default.aspx">Rhino Mocks</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category></item><item><title>Teaching someone to test using an Isolation Framework</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2008/12/30/teaching-someone-to-test-using-an-isolation-framework.aspx</link><pubDate>Tue, 30 Dec 2008 17:21:12 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:43560</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>14</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=43560</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=43560</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2008/12/30/teaching-someone-to-test-using-an-isolation-framework.aspx#comments</comments><description>&lt;p&gt;Part of my job at work is to teach and mentor other developers on our team.&amp;nbsp; Right now I am in the process of teaching two of our developers how to create unit tests (notice I did NOT say integration tests because most anyone can do those).&amp;nbsp; We are also learning how to create our tests by utilizing an Isolation Framework (aka mocking framework).&lt;/p&gt; &lt;p&gt;I am really excited for this opportunity because I firmly believe that you create better software when you do it by creating tests to prove your code works.&amp;nbsp; I am also excited because both of the developer buy into the idea of testing and are extremely eager to learn how to to better test their code.&lt;/p&gt; &lt;p&gt;Because we had a few days of downtime because of the Christmas holiday before our 1st sprint on our project we thought it would be a good time to do some pairing (guess it would be better called tri-pairing).&amp;nbsp; Our plan of attack was to start to flush out some of the features in our system but do it in a total TDD manor.&amp;nbsp; We were also going to be utilizing the Rhino Mock Isolation framework in our tests.&lt;/p&gt; &lt;p&gt;So over the next 2 days we spent about 12 hours or so working building out our code.&amp;nbsp; Over this time we actually were able to create an complete end to end &amp;#39;version&amp;#39; (I say version because we did not fill in all the functionality of the code but were able to get all the major pieces stubbed out) which allowed us to flush out many, many more business requirement and build a simple, yet flexible code base.&lt;/p&gt; &lt;p&gt;I hope both of my co-workers learned a ton from this exercise, I know I did.&amp;nbsp; This was the first time where I had actually spent any significant amount of time teaching someone who was new to testing how to do so.&amp;nbsp; Sure I had spent an hour here or an hour there, but nothing like this.&amp;nbsp; &lt;/p&gt; &lt;p&gt;What I really wanted to share with everyone is what I learned form this experience.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Slowdown, slowdown, slowdown&lt;br /&gt;&lt;/strong&gt;The first thing you should do when teaching something how to do anything is SLOWDOWN.&amp;nbsp; You have to remember that if you are talking/teaching to someone who is new to this they have to not only try to process the information so they can understand it, they also have to try to remember it.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Make NO assumptions, teach as if they know nothing&lt;br /&gt;&lt;/strong&gt;This one was the most important thing I learned.&amp;nbsp; You cannot make assumptions on anything.&amp;nbsp; Anytime you say anything make sure you fully explain it.&amp;nbsp; If you use an acronym EXPLAIN IT.&amp;nbsp; Any time you mention a buzz word EXPLAIN IT.&amp;nbsp; Plan and simple EXPLAIN EVERYTHING&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Have them drive&lt;br /&gt;&lt;/strong&gt;During the teaching part it is critical that you have then code, have them tell you what to do.&amp;nbsp; It is ok for you to &amp;#39;lead&amp;#39; them in the right direction, but you must not always drive.&amp;nbsp; This will really help to drive home the concepts.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Provide examples both with and without the Isolation framework&lt;br /&gt;&lt;/strong&gt;In our case because I was trying to teach them testing using an Isolation framework it really helped when I would create a test (aka integration) with no mocks and then re-create it with mocks.&amp;nbsp; Doing this really helped to explain to them how using the Isolation framework removed dependencies.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Don&amp;#39;t let them skate by&lt;br /&gt;&lt;/strong&gt;Don&amp;#39;t let them simply nod their head as if they understand.&amp;nbsp; Make sure you keep asking them if there is anything you can clear up or explain better.&amp;nbsp; At first they are going to simply say no, they are good.&amp;nbsp; But as you keep asking and start having them drive they WILL start to ask more questions, I promise.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Turn off any coding tools such as ReSharper (or the likes) and do NOT use shortcuts&lt;br /&gt;&lt;/strong&gt;This may have been the biggest issue for us at first.&amp;nbsp; I am pretty good with ReSharper (if I can toot my own horn here) and I was coding with it as I would do if I were by myself.&amp;nbsp; On more than one occasion the would look at me cross-eyed and ask &amp;#39;what the hell just happened&amp;#39;.&amp;nbsp; Finally I simply stopped using it for the first day.&amp;nbsp; On the second day I went back to using R#, but I turned on &lt;a href="http://weblogs.asp.net/rosherove/archive/2007/06/03/train-to-be-a-keyboard-master-with-keyboard-jedi.aspx"&gt;Keyboard Jedi&lt;/a&gt; so they could see what was going on.&amp;nbsp; Even though I turned on Keyboard Jedi, I tried my best to make sure to explain what just happened when used R#.&lt;/p&gt; &lt;p&gt;Anyway, I have rambled on long enough and I think I have pretty much gotten my thoughts out there.&amp;nbsp; I really enjoyed working with these guys and I am looking forward to doing so again when we get back from break.&lt;/p&gt; &lt;p&gt;Hope this helps, &lt;/p&gt; &lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=43560" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Agile/default.aspx">Agile</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/TDD/default.aspx">TDD</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Rhino+Mocks/default.aspx">Rhino Mocks</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Opinion/default.aspx">Opinion</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category></item><item><title>Nasty MSBuild Error - MSB4126 "Debug|HPD" issue</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2008/02/29/nasty-msbuild-error-msb4126-quot-debug-hpd-quot-issue.aspx</link><pubDate>Fri, 29 Feb 2008 19:55:04 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:39536</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>14</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=39536</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=39536</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2008/02/29/nasty-msbuild-error-msb4126-quot-debug-hpd-quot-issue.aspx#comments</comments><description>&lt;p&gt;Today I was trying to put together a simple NAnt build script for a &amp;#39;play&amp;#39; project of mine.&amp;nbsp; This build script is real simple, it only calls MSBuild right now.&amp;nbsp; However, when I was running the script I kept getting the message &amp;#39;error MSB4126: The specified solution configuration &amp;quot;Debug|HPD&amp;quot; is invalid.&amp;#39;&lt;/p&gt; &lt;p&gt;For the life of me I could not figure out what this was.&amp;nbsp; I spent time on Google, and could not find anything useful.&amp;nbsp; What made this more strange was that I could compile via the solution file.&lt;/p&gt; &lt;p&gt;Finally it dawned on me to check my Environment&lt;a href="http://devlicio.us/blogs/derik_whittaker/WindowsLiveWriter/NastyMSBuildErrorMSB4126DebugHPDissue_BF83/image_4.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="252" alt="image" src="http://devlicio.us/blogs/derik_whittaker/WindowsLiveWriter/NastyMSBuildErrorMSB4126DebugHPDissue_BF83/image_thumb_1.png" width="229" align="right" border="0" /&gt;&lt;/a&gt; Variables on my&amp;nbsp; machine.&amp;nbsp; About half way down was a variable &amp;#39;Platform&amp;#39; with a value of &amp;#39;HPD&amp;#39;.&amp;nbsp; I removed that variable, and rebooted, now all is right with the world again (ok, all is right with the build).&lt;/p&gt; &lt;p&gt;Hope this helps someone else out, cause I know it was pissing me of.&lt;/p&gt; &lt;p&gt; Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=39536" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Development+Tools/default.aspx">Development Tools</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Agile/default.aspx">Agile</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category></item><item><title>StructureMap 101 Error Gotcha</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2008/02/02/structuremap-101-error-gotcha.aspx</link><pubDate>Sat, 02 Feb 2008 20:48:03 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:39354</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=39354</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=39354</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2008/02/02/structuremap-101-error-gotcha.aspx#comments</comments><description>&lt;p&gt;Today I was putting together a test app for a few presentations I am doing in the coming weeks (announcements on these coming soon).&amp;#160; While doing this I kept getting a 101 exception when trying to build an object via StructureMap&amp;#39;s ObjectFactory (error information &lt;a href="http://structuremap.sourceforge.net/Troubleshooting.htm" target="_blank"&gt;here&lt;/a&gt;).&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Error message&lt;/strong&gt;    &lt;br /&gt;Assembly {AssemblyNamehere} referenced by an &amp;lt;Assembly&amp;gt; node in StructureMap.config cannot be loaded into the current AppDomain&lt;/p&gt;  &lt;p&gt;What did not make sense is that the test project had reference to the assembly that it was complaining about.&amp;#160; It turns out that I was not actually using the assembly so it did NOT copy the assembly to the bin directory during compile time.&amp;#160; Which I guess makes sense.&lt;/p&gt;  &lt;p&gt;So, after pondering what to do, I simply created a &amp;#39;hack&amp;#39; class that created an instance of an object out of the missing assembly.&amp;#160; Now it copied the .dll to the bin directly like I thought it would.&amp;#160; I can here you now, why create the &amp;#39;hack&amp;#39; class.&amp;#160; Well, simple, I was not using the assembly directly, but using it via IoC with StructureMap.&amp;#160; &lt;/p&gt;  &lt;p&gt;So, if you ever get the 101 exception from StructureMap, make sure the assembly is actually being copied to your output (bin) folder like you thought.&lt;/p&gt;  &lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=39354" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Development+Tools/default.aspx">Development Tools</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Agile/default.aspx">Agile</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/StructureMap/default.aspx">StructureMap</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category></item><item><title>NHibernate and Automatic Properties gotcha</title><link>http://devlicio.us/blogs/derik_whittaker/archive/2008/01/31/nhibernate-and-automatic-properties-gotcha.aspx</link><pubDate>Thu, 31 Jan 2008 14:25:52 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:39346</guid><dc:creator>Derik Whittaker</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/rsscomments.aspx?PostID=39346</wfw:commentRss><wfw:comment xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/derik_whittaker/commentapi.aspx?PostID=39346</wfw:comment><comments>http://devlicio.us/blogs/derik_whittaker/archive/2008/01/31/nhibernate-and-automatic-properties-gotcha.aspx#comments</comments><description>&lt;p&gt;Just an FYI.&amp;nbsp; &lt;/p&gt; &lt;p&gt;If you are using NHibernate and have objects that are using the new Automatic Properties feature of .Net 3.5 make sure that your NHibernate .hbm file does not have &amp;#39;default-access=&amp;quot;field.camelcase-underscore&amp;quot;&amp;#39; in the hibernate-mapping node.&lt;/p&gt; &lt;p&gt;If you have this attribute set you will get a run-time error while using NHibernate.&amp;nbsp; The error is NHibernate.PropertyNotFoundException: Could not find field &amp;#39;_fieldNameHere&amp;#39; in class &amp;#39;ClassNameHere&amp;#39;&lt;/p&gt; &lt;p&gt;Hope this helps someone else. I know I spent about 10 minutes trying to figure out what I did wrong.&lt;/p&gt; &lt;p&gt;Till next time,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=39346" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/Agile/default.aspx">Agile</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/NHibernate/default.aspx">NHibernate</category><category domain="http://devlicio.us/blogs/derik_whittaker/archive/tags/HowTo/default.aspx">HowTo</category></item></channel></rss>