rhino_
This week I had the privilege of leading a custom workshop for a team of developers in Fort Worth, TX. One of the topics that we covered was Writing Testable Code; specifically, we looked at the Model-View-Presenter (MVP) patterns, dependency injection and using RhinoMocks to pull it all together. The one catch was… this group of developers used Visual Basic.

I’ve never shied away from VB. In fact, VB6 with classic ASP is where I cut my programming teeth, and VB.NET was my first move to a true OO language. That being said, I work day in and day out with C#… I’m much more fluent there, and I realized that there were a ton of new features in VB that I wanted to cover that I wasn’t up to par with, fortunately I was able to call on my network of super smart friends and recruit/hire a fellow MVP’er to help me out for the day (thanks Cory for doing that 2 days after your wedding!)

One of the things that tripped me up was using Lambdas in VB. Lambdas are especially important if you are going to use a Mocking framework like RhinoMocks (which I do). Doing Lambdas in VB – especially when I was trying to raise an event from a mock – sort of tripped me up…

First – if you are working with Rhino Mocks, you should go have a look at the excellent Wiki. http://ayende.com/Wiki/Rhino+Mocks+3.5.ashx I find that a lot of people (read: I had) skip the “documentation” since RhinoMocks is so fluent and straight forward, but it’s definitely worth the read!

Second, if you’ve never raised an event in mock from your test in C# here’s the code:

viewMock.Raise(x => x.CalcShippingRequest += null, this, EventArgs.Empty);

and in VB:

Read the rest of this entry »



Search

Subscribe

Enter your email address:

Categories