I’m not a CS major, but I play one… everyday at work. The only real software courses they make CO majors take revolve around Java and general programming principles so it’s fair to say I don’t have any real training in software, which is now every bit of 75% of my job. I would be truly embarrassed if anyone I ever went to college with walked into my office and watched over my shoulder as I fumbled through my day-to-day. Truly, I get stuff to work, but I’m always worried I’ve gone about it in a worse than failure sort of way. But, as always, I’m endeavoring to better myself through studying and I think perhaps that going about it in a transparent fashion might be useful. I never understand something so well as when I have to explain it to someone else, so I guess I’ll go ahead and try that.
That being said, anyone out there ever use a mocking framework in .NET? Rhino? NMock? Anything? I’m starting a very large project from scratch and want to make sure my bricks are good and firm before building the house so I’m trying to learn all of these professional-looking team-based techniques despite my development team consisting of just caffeine and I.
So! I’ve been trying to use Rhino in my unit testing and I’ve got some code that passes tests… but I’m not sure if I believe it or not. It really doesn’t help that C is the language of choice for people using .NET so of course all example code is in C and I am more comfortable in VB. So I’m doing the translating myself. What was very simple in C becomes less-so in VB and the only way I’ve been able to get things working is with helper routines.
[Test]
public void Can_Dispose_UnitOfWorkImplementor()
{
using(_mocks.Record())
{
Expect.Call(() => _factory.DisposeUnitOfWork(null)).IgnoreArguments();
Expect.Call(_session.Dispose);
}
using (_mocks.Playback())
{
_uow = new UnitOfWorkImplementor(_factory, _session);
_uow.Dispose();
}
}
This works, and I have no idea how to do it any simpler.
<Test()>
Sub Can_Dispose_UnitOfWorkImplementor()
Using _mocks.Record
_session.Expect(AddressOf _session.Dispose)
_factory.Expect(AddressOf FactoryDispose_Helper).IgnoreArguments()
End Using
Using _mocks.Playback
_uowi = New UnitOfWorkImplementor(_factory, _session)
_uowi.Dispose()
End Using
End Sub
Private Sub FactoryDispose_Helper()
_factory.DisposeUnitOfWork(Nothing)
End Sub