February 13, 2008

Incompatibility among Framework’s build versions and problems with Rhino.Mocks

Filed under: .NET, C#, TDD, Rhino Mocks

I’ve written some mocking tests for my actual project lately. These tests use library Rhino.Mocks 3.3.0.906. The project is compiled and runs under .NET 2.0. I noticed today that some tests run failed on developers machine with Vista as operation system. There has been some difference between frameworks. My developer station with Windows XP on board had .NET 2.0.50727.1433  but Vista station had 2.0.50727.312

I’ve written some tests after error analysis. I’ll try to prove an error.

   1: public interface IMyInterface
   2: {
   3:     T GetTypedValue<T>(string key);
   4: }
   5:  
   6: [Test("Test which is correct for Framework 2.0.50727.312 + RhinoMock 3.3.")]
   7: public void TestWithStringTypeAndIgnoredArguments()
   8: {
   9:     MockRepository mocks = new MockRepository();
  10:     IMyInterface service = mocks.CreateMock<IMyInterface>();
  11:  
  12:     Expect
  13:         .Call(service.GetTypedValue<string>("any2"))
  14:         .IgnoreArguments()
  15:         .Return(null);
  16:  
  17:     mocks.ReplayAll();
  18:  
  19:     service.GetTypedValue<string>("my attribute2");
  20:  
  21:     mocks.VerifyAll();
  22: }
  23: [Test("Test which is correct for Framework 2.0.50727.312 + RhinoMock 3.3.")]
  24: public void TestWithStringTypeAndSpecifiedArguments()
  25: {
  26:     MockRepository mocks = new MockRepository();
  27:     IMyInterface service = mocks.CreateMock<IMyInterface>();
  28:  
  29:     Expect
  30:         .Call(service.GetTypedValue<string>("any2"))
  31:         .Return(null);
  32:  
  33:     mocks.ReplayAll();
  34:  
  35:     service.GetTypedValue<string>("any2");
  36:  
  37:     mocks.VerifyAll();
  38: }

These tests above runs correctly for both NET framework versions, 2.0.50727.1433 and 2.0.50727.312 .

Two next tests are quite similar. The only difference is type for generic method "GetTypedValue", "bool?" instead of "string".

   1: [Test("Test proves error for Framework 2.0.50727.312 + RhinoMock 3.3.")]
   2: public void TestWithNullableTypeAndIgnoredArguments()
   3: {
   4:     MockRepository mocks = new MockRepository();
   5:     IMyInterface service = mocks.CreateMock<IMyInterface>();
   6:  
   7:     Expect
   8:         .Call(service.GetTypedValue<bool?>("any2"))
   9:         .IgnoreArguments()
  10:         .Return(null);
  11:  
  12:     mocks.ReplayAll();
  13:  
  14:     service.GetTypedValue<bool?>("my attribute");
  15:  
  16:     mocks.VerifyAll();
  17: }
  18:  
  19: [Test("Test which is correct for Framework 2.0.50727.312 + RhinoMock 3.3.")]
  20: public void TestWithNullableTypeAndSpecifiedArguments()
  21: {
  22:     MockRepository mocks = new MockRepository();
  23:     IMyInterface service = mocks.CreateMock<IMyInterface>();
  24:  
  25:     Expect
  26:         .Call(service.GetTypedValue<bool?>("any2"))
  27:         .Return(null);
  28:  
  29:     mocks.ReplayAll();
  30:  
  31:     service.GetTypedValue<bool?>("any2");
  32:  
  33:     mocks.VerifyAll();
  34: }

Second test works correctly but first one has problem with arguments for expected call. IgnoreArguments method in line (9) doesn’t make this call to ignore arguments anymore. It will start working after installing  NET 3.5 on Vista which upgrades also NET 2.0 to version 2.0.50727.1433.

As you can see, little differences in build version can mess a lot.

Get free blog up and running in minutes with Blogsome | Theme designs available here