This is a common confusion. See this on stackoverflow:

http://stackoverflow.com/questions/887245/rhino-mocks-repeat-once-not-working/887554#887554


On 12 Aug., 12:18, "Jake" <[email protected]> wrote:
> You are not repeating a call, you are repeating expectation. On strict or 
> dynamic mocks there is no implementation of the method, as such your second 
> call will fail, whereas in dynamic mock second call will go thru.
> I agree that this unnecessary feature.
> Sent from my Verizon Wireless BlackBerry
>
> -----Original Message-----
> From: Ben M <[email protected]>
>
> Date: Tue, 11 Aug 2009 16:12:40
> To: Rhino.Mocks<[email protected]>
> Subject: [RhinoMocks] Re: partial mock not correctly doing 'Repeat.Once()'
>
> yes, but doesnt this sort of defeat the purpose of using Repeat.Once
> ()?
>
> i mean if i'm using a strict or dynamic mock then i can use Repeat.Once
> () in this way, why then can i not do this w/ a partial?
>
> On Aug 11, 4:08 pm, Ayende Rahien <[email protected]> wrote:
> > Make a second call:
> >  Expect.Call(_publisher.Send(null))
>
> > >                     .IgnoreArguments()
> > >                     .Return(true)
> > >                     .Repeat.*Never()*;
> > On Wed, Aug 12, 2009 at 2:05 AM, Ben M <[email protected]> wrote:
>
> > > well, i made a discovery on this.  If you only tell it to repeat once,
> > > then the other calls will subsequently go to the actual real method as
> > > opposed to the mock version of the method.  So I've done a work around
> > > using Expect.Call().Do() and keeping my own count of the number of
> > > calls, but this is something that in my opinion I should be able to do
> > > in Rhino mocks.  Does anyone know how to do this without having to do
> > > it myself?  Ayende?
>
> > > On Aug 11, 2:48 pm, Ben M <[email protected]> wrote:
> > > > I have a partial mock on a class I'll call 'Publisher'
>
> > > > the publisher has a method called 'Publish' that in turn calls a
> > > > virtual method called Send as follows:
>
> > > > public class Publisher
> > > > {
> > > >      public bool Publish(MyList list)
> > > >      {
> > > >           string msg =_msgBuilder.BuildFrom(list);
> > > >           bool success = Send(msg);
>
> > > >           return success;
> > > >     }
>
> > > >      public virtual bool Send(string msg)
> > > >      {
> > > >             /// snip
> > > >            return true;
> > > >       }
>
> > > > }
>
> > > > my unit test then does the following:
> > > >         [SetUp]
> > > >         public void Setup()
> > > >         {
>
> > > >            _mocks = new MockRepository();
>
> > > >            _publisher =_mocks.PartialMock<Publisher>();
>
> > > >         }
>
> > > > [Test]
> > > > public void OnlyCallSendOnceForEmptyLists()
> > > > {
> > > >                 Expect.Call(_publisher.Send(null))
> > > >                     .IgnoreArguments()
> > > >                     .Return(true)
> > > >                     .Repeat.Once;
>
> > > >            _mocks.ReplayAll();
>
> > > >            _publisher.Publish(new MyList());
> > > >            _publisher.Publish(new MyList());
>
> > > >            _mocks.VerifyAll();
>
> > > > }
>
> > > > I would expect this test to fail as it should be expecting no more
> > > > than 1 call, but the test is passing, and stepping thru the debugger I
> > > > can see it IS in fact making 2 calls, yet the test still passes.  What
> > > > am I doing wrong that causes this test to give me a false positive?
>
> > > > thanks in advance
> > > > Ben
--~--~---------~--~----~------------~-------~--~----~
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