When using DynamicMocks, it is actually not common to limit the number
of calls. When using a dynamic mock, every call is actually allowed.
You just define how it should behave and which is mandatory.

The problem is, that people are not aware that they are using a
dynamic mock.

Yes it is confusing somehow. If you know how strict mocks and dynamic
mocks work, you know why it is as it is. The question is: couldn't it
be easier that users don't have to know it all? I don't know how it
should be.


On 19 Aug., 02:44, TheMightyKumquat <[email protected]> wrote:
> I've just encountered the issue of having a test pass when a property
> on a dynamic mocked object is accessed more than once, when I have the
> LastCall.Repeat.Once() coded. That is, the method might go
>
> MyThing x = obj.MyProp;
> MyThing y = obj.MyProp;
>
> I mock
> Expect.Call(myMock.MyProp).Return(dummyObj);
> LastCall.Repeat.Once();
>
> I then expect my test to fail - I should have coded Repeat.Twice().
> But it passes. Your link explains why 
> -http://stackoverflow.com/questions/887245/rhino-mocks-repeat-once-not...
>
> This is my opinion as a beginner user. I find that confusing. The
> majority of users would want to use the Repeat method to actually
> specify the number of calls being made, and would want the test to
> fail unless they've specified the correct number. Repeat not being
> enforced with dynamic mocks and with partial mocks does not seem good
> functionality. I also don't find it the proposed solutions on the
> stackoverflow link a good workaround: why should there be any
> workaround at all? Just code the Repeat method to enforce the number
> of calls. Anything else is unnecessarily confusing to users of Rhino
> Mocks - and Stefan's mentioning that this is a common confusion
> indicates this.
>
> On Aug 17, 6:25 pm, Stefan Steinegger <[email protected]>
> wrote:
>
> > This is a common confusion. See this on stackoverflow:
>
> >http://stackoverflow.com/questions/887245/rhino-mocks-repeat-once-not...
>
> > 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- Hide quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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