Thursday 26 November 2009

My Podcasting List

This is a list of the current podcasts I listen to.  I usually listen to these at work, though occasionally on the way to/from work.

Development Technical Podcasts

.Net Rocks iTunes link This show covers a great range of .NET topics and is really well presented.  I’m not sure how the guys who brought you Mondays are also able to bring you such a great technical podcast, but I’d recommend it to any .NET developer.
Hanselminutes iTunes Link Scott Hanselman talking about anything technical.  Most of the stuff is .NET and development related and Scott is a great presenter.
Stack Overflow Link Everyone’s favorite site now produces a podcast, it’s not quite as entertaining as the other podcasts, but it’s very informative and well presented.

Other Tech Podcasts

PING Link Channel 9’s ping is just good fun, I can’t find a good podcast location for downloading it to my iPhone through iTunes, but I watch it online anyway.
TWiT Link Leo La-port is a great podcaster and TWiT covers some great topics each week.  This seems to be one of those shows that some people just REALLY hate, but I’m not sure why.  Take it with a grain of salt, but it’s good fun, entertaining and informative (even if some times opinionated).
Aussie Geek Link I’m an Aussie, I’m a geek.  This is just pitched at me.  It’s not bad, not as good as TWiT but similar, focused more on Aussie news as well which is great.

Entertainment

Answer Me This Link These guys are so great, very funny and well presented podcast.  If you’re looking for a humorous podcast, this is worth a listen.  My favorite podcast!
Carpool Link - Awesome site! Robert Lewellyn is a very interesting entertainer who has created one of the most fantastic and informative podcasts with an innovative and brilliant format.  You’ll like this podcast more if you like cars and alternative energy, or even if you’re a fan of Red Dwarf.
Hardcore History Link Ever wanted to know more about the plague?  Or the Ancient Mogols?  Perhaps you want to know about the rise and fall of the Asirians?  This is a great place to learn about it.  Well presented and great tempo, this is a good fun podcast that I listen to between audio books.
College Humor iTunes Link Just funny, really really funny.

Monday 9 November 2009

Testing function parameters with Rhino Mocks

When I’m developing, often I need to test the parameters that were passed to a function.  This is most often the case when dealing with the repository pattern.

For example, if I’m writing a processor that goes through a list of objects and inserts them into the database using a repository I would wish to know that my repository is called 10 times.  I might also with to ensure that it is called 10 times in the correct order and that each time the correct object is passed into the method.

There are a few ways to do this, one way is to keep the objects in memory in my test class and assert that the correct object was passed in:

   1: IRepository repo = mocks.DynamicMock<IRepository>();
   2: mocks.ReplayAll();
   3:  
   4: // testing code
   5:  
   6: repo.AssertWasCalled(repo.Insert(objects[0]));
   7: repo.AssertWasCalled(repo.Insert(objects[1]));
   8: repo.AssertWasCalled(repo.Insert(objects[2]));
   9: repo.AssertWasCalled(repo.Insert(objects[3]));
  10: repo.AssertWasCalled(repo.Insert(objects[4]));
  11: repo.AssertWasCalled(repo.Insert(objects[5]));
  12: repo.AssertWasCalled(repo.Insert(objects[6]));
  13: repo.AssertWasCalled(repo.Insert(objects[7]));
  14: repo.AssertWasCalled(repo.Insert(objects[8]));
  15: repo.AssertWasCalled(repo.Insert(objects[9]));

But this isn’t going to test the order they were called in.  Also, often I find that I don’t have a reference to the object that is being passed into the method even though I might know it’s contents.

One way to get around this is to expect that when the method is called to use a delegate and add the parameters to a list we can test later.

   1: IRepository repository = mocks.DynamicMock<IRepository>();
   2: List<MyObject> args = new List<MyObject>();
   3:  
   4: using (mocks.Record())
   5: {
   6:     Expect
   7:         .Call(delegate { repository.Insert(null) })
   8:         .IgnoreArguments().WhenCalled(o => args.Add(o.Arguments.First() as MyObject))
   9:         .Repeat.AtLeastOnce();
  10: }

Note the delegate, used because repository.Insert is a void method.

This way, every time the function is called the parameter is added to the list.  I can now check the order the function was called in and the contents of each parameter used each time it was called.