In attempting to upgrade our solution to RhinoMocks 3.6, several tests
began failing.  Two of them were because of what appears to be a bug
that was introduced in 3.6.  When setting expectations on a
DynamicMock for the same method twice using IgnoreArguments,
RhinoMocks fails to detect that the method was called the second
time.  An example should make this clear:

Class under test:

        public class Spammer
        {
                private readonly IMessageSender sender;

                public Spammer(IMessageSender sender)
                {
                        this.sender = sender;
                }

                public void SpamTwoVictims()
                {
                        sender.Send("victimA");
                        sender.Send("victimB");
                }
        }

Test (works in 3.5, breaks in 3.6):

                [Test]
                public void When_spamming_should_send_multiple_messages()
                {
                        var sender = 
MockRepository.GenerateMock<IMessageSender>();
                        var spammer = new Spammer(sender);
                        sender.Expect(s => s.Send(null)).IgnoreArguments();
                        sender.Expect(s => s.Send(null)).IgnoreArguments();

                        spammer.SpamTwoVictims();

                        sender.VerifyAllExpectations();
                }

The above test fails with the following error message:

Rhino.Mocks.Exceptions.ExpectationViolationException:
IMessageSender.Send(any); Expected #1, Actual #0.

Key observations:
- RhinoMocks did correctly expect Send to be called a second time.
However, it was not able to detect that it was in fact called.  I know
this because if I modify the Spammer class to only send a message to
one victim, then the test fails with the same error message (in this
case, the error message is correct).
- If I change the sender to be a StrictMock instead of a DynamicMock,
the test passes.  It seems that
- Using Repeat.Twice() instead works:
        sender.Expect(s => s.Send(null)).IgnoreArguments().Repeat.Twice();
- Using Arg<> instead works:
        sender.Expect(s => s.Send(Arg<string>.Is.Anything));
        sender.Expect(s => s.Send(Arg<string>.Is.Anything));

I was unable to find this issue being reported in previous discussions
in this group, I apologize if I missed this.  Is this the correct
place to report bugs?

Thanks,
--matt

--~--~---------~--~----~------------~-------~--~----~
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