Thursday, May 5, 2011

NMocks2 Argument Syntax in Rhino Mocks?

In NMocks2 you can mock up the result of a method you don't know the arguments to before hand using

Stub.On(aMock)
    .Method( ... )
    .WithAnyArguments()
    .Will(Return.Value( ... );

from NMocks2 Cheatsheet. My question is, is there a similar mechanism for Rhino mocks when you don't care about the arguments? I want to make a call similar to:

    object objectIDontWantToRecreate = null; // Won't be null in actuality
    object alwaysReturned = ...;
    Expect.Call(mockObject.Method(objectIDontWantToRecreate)).Return(alwaysReturned);
From stackoverflow
  • There sure is:

    Expect.Call(mockObject.Method(null)).IgnoreArguments().Return(alwaysReturn)
    
    benjynito : Thanks. Don't know how I missed it. I guess there's a bunch of stuff to learn here :)
    womp : Rhino is a really flexible framework, but the learning curve is steep. If you're dealing with .Net 3.5, I would highly recommend Moq over Rhino.

0 comments:

Post a Comment