Rhino Mocks Arg<T> Error

Software

In hindsight, this one was easy to predict.  Running a test with the following lines in record mode:

rd.LogMessage(Arg<MessageImportance>.Is.Anything, Arg<string>.Is.Anything);
LastCall.IgnoreArguments().Repeat.Any();

I got the error:

Failed    Execute_1    Cornbread.MSBuild.Tasks.Test    Test method Cornbread.MSBuild.Tasks.Test.RestoreDatabaseTest.Execute_1 threw exception:  System.InvalidOperationException: Use Arg<T> ONLY within a mock method call while recording. 2 arguments expected, 4 have been defined..

The obvious problem: I’m using Arg<T> when I should be using NULL to indicate “don’t care” parameters to the expected call:

rd.LogMessage(MessageImportance.Normal, null);
LastCall.IgnoreArguments().Repeat.Any();

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Furl
  • Ma.gnolia
  • Reddit
  • TwitThis
1 Comment

1 Comment

  1. RArmstrong  •  Aug 4, 2009 @2:23 am

    Question – how is ‘null’ better than Arg.Is.Anything? The intention of this is to specify that it can be any value of a given type which is actually better than ‘null’. Surely you are not solving the problem you had rather just avoiding it – I have had the same issue and it appears to be a bug?

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">