LastCall.Repeat doesn't seem to function properly.

7 views
Skip to first unread message

EmmanuelGoldstein

unread,
Sep 24, 2007, 1:38:50 PM9/24/07
to Rhino.Mocks
IInsertRuleView testView = _mocks.DynamicMock<IInsertRuleView>();
testView.AddErrorMessage("Ignore");
LastCall.Repeat.Once();
LastCall.IgnoreArguments();
_mocks.ReplayAll();

_presenter.InsertRule();
_mocks.VerifyAll();

With the above code, if AddErrorMessage isn't called at all, the test
fails as expected, but as long as it is called at least once, the test
passes. Am I missing something? I'm expecting that Repeat.Once means
"once and only once".

I'm using Rhino.Mocks version 3.2.0.781

Thanks,
Matt

EmmanuelGoldstein

unread,
Sep 24, 2007, 1:55:19 PM9/24/07
to Rhino.Mocks
I should also mention that removing the LastCall.Repeat.Once doesn't
seem to do anything either. I must be doing something wrong.

EmmanuelGoldstein

unread,
Sep 24, 2007, 2:14:15 PM9/24/07
to Rhino.Mocks
Sorry to keep replying to myself, but something seems to be seriously
wrong here. This code passes, but it doesn't seem like it should:

[Test]
public void TestRepeatOnce()
{
MockRepository mockery = new MockRepository();
IInsertRuleView mockView =
mockery.DynamicMock<IInsertRuleView>();

Expect.Call(mockView.AddErrorMessage("test")).Return(true).Repeat.Once();

mockery.ReplayAll();
mockView.AddErrorMessage("test");
mockView.AddErrorMessage("test");
mockery.VerifyAll();
}


On Sep 24, 10:38 am, EmmanuelGoldstein <matt.horn...@gmail.com> wrote:

EmmanuelGoldstein

unread,
Sep 24, 2007, 3:09:01 PM9/24/07
to Rhino.Mocks
OK, last one for now. It seems like if I use CreateMock instead of
DynamicMock, everything works properly. I'd prefer not to have to use
CreateMock just to get Repeat to work properly, but it's at least a
workaround for now.

> > Matt- Hide quoted text -
>
> - Show quoted text -

EmmanuelGoldstein

unread,
Sep 27, 2007, 11:04:50 AM9/27/07
to Rhino.Mocks
Can anyone verify this behavior?

On Sep 24, 10:38 am, EmmanuelGoldstein <matt.horn...@gmail.com> wrote:

Ayende Rahien

unread,
Sep 28, 2007, 11:33:57 AM9/28/07
to Rhino...@googlegroups.com
This is the expected behavior.
Dynamic Mock will ignore any unknown calls that your make to it.
Therefor, setting up any Repeat means that you are setting a minimum, not a hard limit.

Derick Bailey

unread,
Sep 28, 2007, 5:08:26 PM9/28/07
to Rhino.Mocks
this thread just saved me an hour of freaking out. :)

On Sep 28, 10:33 am, "Ayende Rahien" <aye...@ayende.com> wrote:
> This is the expected behavior.
> Dynamic Mock will ignore any unknown calls that your make to it.
> Therefor, setting up any Repeat means that you are setting a minimum, not a
> hard limit.
>

EmmanuelGoldstein

unread,
Sep 29, 2007, 10:34:10 AM9/29/07
to Rhino.Mocks
Thanks Ayende!

Derick: I'm glad my hours of freaking out saved you some time ;)

Reply all
Reply to author
Forward
0 new messages