Showing posts with label mock. Show all posts
Showing posts with label mock. Show all posts

Sunday, June 13, 2010

Rhino Mocks moving to the AAA syntax

Having looked at how I should write my unit tests, I've started to move to the AAA syntax (Arrange, Act, Assert). I found it quite hard (me being stupid) to find a before and after example - so here's my before and after...

// Art of unit testing (7.3.1 naming unit tests)
  //  name of method being tested _ scenario being tested _ the expected behaviour
  //  MethodUnderTest_Scenario_Behaviour
  [TestMethod]
  public void CreateParser_WellKnownDataset_PostsNodesToReciever()
  {
   MockRepository mocks = new MockRepository();
   IParsedReceiver receiver = mocks.StrictMock<IParsedReceiver>();

   using (mocks.Record())
   {
    receiver.AcceptNode(null);
    LastCall.IgnoreArguments().Repeat.Times(14);
   }

   Parser parser = Manager.CreateParser(receiver, @"..\..\ParseData\OsmTestData.xml");

   mocks.VerifyAll();
  }

and using the 3.5 Arrange, Act, Assert approach:

// Art of unit testing (7.3.1 naming unit tests)
  //  name of method being tested _ scenario being tested _ the expected behaviour
  //  MethodUnderTest_Scenario_Behaviour
  [TestMethod]
  public void CreateParser_WellKnownDataset_PostsNodesToReciever_AsStub()
  {
   // arrange
   IParsedReceiver receiver = MockRepository.GenerateStub<IParsedReceiver>();

   // act
   Parser parser = Manager.CreateParser(receiver, @"..\..\ParseData\OsmTestData.xml");
   
   // assert
   receiver.AssertWasCalled(c => c.AcceptNode(null), options => options.Repeat.Times(14).IgnoreArguments());
  }

which has the nice side effect of being less code as well!

Tuesday, June 8, 2010

Maps revisited

Last year I created a prototype map renderer in Silverlight using the OSM dataset. Since then I've been thinking about some of the issues with the design - especially:
  • the UI load time and
  • some specific issues with the Quad Store approach
  • Dataset size
  • Automated updates to the dataset, including taking differences
  • No Geograhic AI system
  • No animation engine in the renderer

I've decided that I will restart the renderer again, but with a new design, storage mechanism and using more mature agile approaches (i.e. TDD, Mocking, IoC etc). Also during this time silverlight has moved form version 2.0 to 4.0 which also offers some interesting capabilities, and .Net 4.0 now has support for memory mapped files. I also want to follow a more product management approach, with a proper backlog etc.


TDD Unit test for Strontium using Rhino Mocks
I've started writing new code, especially for the import routine using the full dataset rather than just London. As part of this I'm using PowerShell and the Pscx extensions - there seems to be some issues with handling large files, so hopefully when this gets fixed I can have a constantly updating system.

The prototype code was using the Project Cobalt name, this new effort will go under Project Strontium