Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
DynamicMock and Repeat
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rob  
View profile  
 More options May 16 2008, 5:55 pm
From: Rob <rten...@gmail.com>
Date: Fri, 16 May 2008 14:55:47 -0700 (PDT)
Local: Fri, May 16 2008 5:55 pm
Subject: DynamicMock and Repeat
I found this post which appears to answer my quandary of the day:
http://groups.google.com/group/RhinoMocks/browse_thread/thread/ac6391...

To pull a quote from the post:
"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."

What I'm wondering is whether or not that is still true. I understand
the desire to have a DynamicMock and to not want to set up each and
every call on it. It seems though that once an expectation is stated,
the "dynamic" component of that call would be lost.

This code demonstates the issue I'm talking about. I would expect the
test to fail, but it passes. If I change the DynamicMock to
CreateMock, the test fails as one would expect.

public interface IMyTestInterface
{
   void MyTestMethod();

}

[TestFixture]
public class RepeatTests
{
   [Test]
   public void Test()
   {
      var mockery = new MockRepository();
      var myMock = mockery.DynamicMock<IMyTestInterface>();

      using (mockery.Record())
      {
         myMock.MyTestMethod();
         LastCall.Repeat.Once();
      }
      using (mockery.Playback())
      {
         myMock.MyTestMethod();
         myMock.MyTestMethod();
      }
   }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ayende Rahien  
View profile  
 More options May 17 2008, 3:08 am
From: "Ayende Rahien" <aye...@ayende.com>
Date: Sat, 17 May 2008 10:08:14 +0300
Local: Sat, May 17 2008 3:08 am
Subject: Re: [RhinoMocks] DynamicMock and Repeat

The key difference between dynamic and strict mocks is how they treat
unexpected method calls.In your test, the second method call is not
expected, and is ignored.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob  
View profile  
 More options May 18 2008, 3:51 pm
From: Rob <rten...@gmail.com>
Date: Sun, 18 May 2008 12:51:08 -0700 (PDT)
Local: Sun, May 18 2008 3:51 pm
Subject: Re: DynamicMock and Repeat
I wouldn't argue with the default behavior of a dynamic mock at all.
That's why we like it so much. The interesting part to me I guess is
the fact that my stating "LastCall.Repeat.Once()" doesn't undo the
dynamic behavior of that particular method call on the dynamic mock.
If that can't happen, I think I would rather get an exception that
tells me that I can't specify "Once" on a dynamic mock, than just have
the test pass as if everything is working as expected.

Not a huge deal by any means. The production code has been updated and
is working like a champ now.

On May 17, 2:08 am, "Ayende Rahien" <aye...@ayende.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ayende Rahien  
View profile  
 More options May 21 2008, 2:49 pm
From: "Ayende Rahien" <aye...@ayende.com>
Date: Wed, 21 May 2008 21:49:03 +0300
Local: Wed, May 21 2008 2:49 pm
Subject: Re: [RhinoMocks] Re: DynamicMock and Repeat

The problem here is that we have different models on what is going on.

Repeat.One() is actually the default behavior.

The way it works is:

  [Test]
  public void Test()
  {
     var mockery = new MockRepository();
     var myMock = mockery.DynamicMock<IMyTestInterface>();

     using (mockery.Record())
     {
// create an expectation that this method would be call once
        myMock.MyTestMethod();

// doesn't really do anything
        LastCall.Repeat.Once();
     }
     using (mockery.Playback())
     {
// match to the first expectation and satisfy it.
        myMock.MyTestMethod();
// back to usual behavior
        myMock.MyTestMethod();
     }

What you seem to want is something like this


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ayende Rahien  
View profile  
 More options May 21 2008, 2:49 pm
From: "Ayende Rahien" <aye...@ayende.com>
Date: Wed, 21 May 2008 21:49:11 +0300
Local: Wed, May 21 2008 2:49 pm
Subject: Re: [RhinoMocks] Re: DynamicMock and Repeat

Like this:

MockRepository mocks = new MockRepository();
IDemo demo = mocks.DynamicMock<IDemo>();
demo.VoidNoArgs();
LastCall.Repeat.Once();// doesn't realy matter
demo.VoidNoArgs();
LastCall.Repeat.Never();

mocks.ReplayAll();

demo.VoidNoArgs();//should work

demo.VoidNoArgs();// will fail


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob  
View profile  
 More options May 22 2008, 2:37 pm
From: Rob <rten...@gmail.com>
Date: Thu, 22 May 2008 11:37:49 -0700 (PDT)
Local: Thurs, May 22 2008 2:37 pm
Subject: Re: DynamicMock and Repeat
I just wanted to say that I really appreciate the feedback.  I know
all of our time is valuable.

I'm just arguing for the sake of argument at this point. I know how to
use your framework as intended now and still think it's completely
excellent to use. So, with that said, one more go at it...

I think I would still assert that the definition of Once is "Once and
only once".  This is especially so with the presence of another method
called "AtLeastOnce".

Now, given that assertion, if someone creates a dynamic mock that
ignores unexpected calls, and then turns around and says "Once" on one
of the methods of that mock, we're left with a contradiction I think.
For that one method, did the user mean dynamic or did he/she mean
once? I personally would guess that the user meant "dynamic for
everything on the mock except the one where I was specific."

Have an excellent day and thanks again.
Rob

On May 21, 1:49 pm, "Ayende Rahien" <aye...@ayende.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ayende Rahien  
View profile  
 More options May 22 2008, 7:09 pm
From: "Ayende Rahien" <aye...@ayende.com>
Date: Fri, 23 May 2008 02:09:45 +0300
Local: Thurs, May 22 2008 7:09 pm
Subject: Re: [RhinoMocks] Re: DynamicMock and Repeat

The problem is with the interpretation of Once.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »