This is what typically I do and it works:

            int counter = 1;
            stub.Stub(o => o.SomeMethod()).Do(new Func<string>(() =>
counter++.ToString()));
            Assert.AreEqual("1", stub.SomeMethod());
            Assert.AreEqual("2", stub.SomeMethod());

But when I tried to use WhenCalled:
            stub.Stub(o => o.SomeMethod()).WhenCalled(m =>
m.ReturnValue = counter++.ToString());

I got error at the first Assert.AreEqual, this is the part that I
couldn't figure out about WhenCalled. So yes, a wiki page :)

failed: System.InvalidOperationException : Method 'IA.SomeMethod();'
requires a return value or an exception to throw.
        at 
Rhino.Mocks.Expectations.AbstractExpectation.ReturnOrThrow(IInvocation
invocation, Object[] args)
        at Rhino.Mocks.Impl.StubReplayMockState.DoMethodCall(IInvocation
invocation, MethodInfo method, Object[] args)
        at Rhino.Mocks.Impl.ReplayMockState.MethodCall(IInvocation
invocation, MethodInfo method, Object[] args)
        at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation,
Object proxy, MethodInfo method, Object[] args)
        at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation)
        at Castle.DynamicProxy.AbstractInvocation.Proceed()
        at Castle.Proxies.IAProxydb53eff9f09a47cc958b18b6606e6321.SomeMethod()

On Thu, Jul 30, 2009 at 10:42 AM, Shawn Neal<[email protected]> wrote:
> stub.Stub(o => o.SomeMethod()).Return("1");
> stub.Stub(o => o.SomeMethod()).Return("2");
> sut.SomeAction(stub);

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/RhinoMocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to