Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Expect and overloaded methods
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
  6 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
 
Al  
View profile  
 More options Jul 6, 9:29 pm
From: Al <ali.bl...@gmail.com>
Date: Mon, 6 Jul 2009 18:29:46 -0700 (PDT)
Local: Mon, Jul 6 2009 9:29 pm
Subject: Expect and overloaded methods
Hi,

I have a question you might help me with.
We need to verify that a method A calls any of the overloaded forms of
method B.

e.g. I have
void B(int)
void B(int, int)
void B(int, int, int)

and I don't care which one of those is called from my method A (at
least one must be called).
Is it possible with Rhino Mocks to define "alternative
expectations" ?  Like a set of expectation from which at least one
must be met (or something like .VerifyAnyExpectation instead
of .VerifyAllExpectations) ?

If this is not possible, what would you suggest for this scenario?

What I did now is grouped the 3 methods in the most complex one.
The call B(x) will now be B(x, null, null), but I don't like this work-
around and I'm looking for better alternatives.

Thanks,
Al


    Reply to author    Forward  
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.
Tim Barcz  
View profile  
 More options Jul 7, 12:52 pm
From: Tim Barcz <timba...@gmail.com>
Date: Tue, 7 Jul 2009 11:52:18 -0500
Local: Tues, Jul 7 2009 12:52 pm
Subject: Re: [RhinoMocks] Expect and overloaded methods

What is the usage of this....?

The code isn't random as runtime is it?  There is logic in place to
determine what actual method should be called.  If that is the case you can
assert the different scenarios.

Tim

--
Tim Barcz
ASPInsider
http://timbarcz.devlicio.us
http://www.twitter.com/timbarcz

    Reply to author    Forward  
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.
Kenneth Xu  
View profile  
 More options Jul 7, 2:10 pm
From: Kenneth Xu <kenne...@gmail.com>
Date: Tue, 7 Jul 2009 14:10:16 -0400
Local: Tues, Jul 7 2009 2:10 pm
Subject: Re: [RhinoMocks] Re: Expect and overloaded methods
I guess this is some sort of state v.s. interactive test. I had the
same need for this.

Yes, there is a logic to determine which is called but this is
implementation detail. If my email service as overloaded sendmail
methods. All I care is one of them is called. Which one is called is
the implementation detail and I don't want my test case to fail if the
implementation changes in future.

There is no direct support from RhinoMocks for this but you can do
below to archive the same result:

try {
  mock.AssertWasCalled(x=>x.B(i));

} catch (FogotNameButYouCanFindOutEasilyException)

{
  try {
    mock.AssertWasCalled(x=>x.B(i,j));
  } catch (...) {
    mock.AssertWasCalled(x=>x.B(i,j,k));
  }


    Reply to author    Forward  
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.
Al  
View profile  
 More options Jul 8, 12:36 am
From: Al <ali.bl...@gmail.com>
Date: Tue, 7 Jul 2009 21:36:37 -0700 (PDT)
Local: Wed, Jul 8 2009 12:36 am
Subject: Re: Expect and overloaded methods
Thanks Kenneth,

What you described is exactly what I have. Sorry I didn't explain
better myself.

I just wanted to check with you that Rhino Mocks doesn't provide
support for that, before trying something else.

I'll do something similar with what you proposed and make sure my
condition (that exactly one of the function is called) is met.

Cheers,
Al

On Jul 8, 4:10 am, Kenneth Xu <kenne...@gmail.com> wrote:


    Reply to author    Forward  
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.
Kenneth Xu  
View profile  
 More options Jul 8, 10:48 pm
From: Kenneth Xu <kenne...@gmail.com>
Date: Wed, 8 Jul 2009 22:48:08 -0400
Local: Wed, Jul 8 2009 10:48 pm
Subject: Re: [RhinoMocks] Re: Expect and overloaded methods
Al,

You are welcome. I understood your pain of writing the test as I have
experienced the same. Your request confirmed that I'm not the only one
needed this feature so I went ahead and tried something myself.

How does this look to you?

(
  mock.ActivityOf(m=>m.B(1)) |
  mock.ActivityOf(m=>m.B(1,2)) |
  mock.ActivityOf(m=>m.B(1,2,3))
).AssertOccured;

If you want exactly once, you can do:

    Activities.OneOf(
        foo.ActivityOf(f=>f.Foo(1), m=>m.Repeat.Once()),
        foo.ActivityOf(f=>f.Foo(1,2), m=>m.Repeat.Once()),
        foo.ActivityOf(f=>f.Foo(1,2,3), m=>m.Repeat.Once())
    ).AssertOccured;

If you are interested and want to give it a try. See
http://kennethxu.blogspot.com/2009/07/introduce-powerful-aaa-syntax-f...
for detail.

Cheers,
Kenneth


    Reply to author    Forward  
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.
Al  
View profile  
 More options Jul 9, 1:38 am
From: Al <ali.bl...@gmail.com>
Date: Wed, 8 Jul 2009 22:38:32 -0700 (PDT)
Local: Thurs, Jul 9 2009 1:38 am
Subject: Re: Expect and overloaded methods
Hey Kenneth,

That's awsome.
I'm reading on your blog to see exactly what you did there.
But this is the functionality I want.

Thanks and keep doing the good work :)

Al


    Reply to author    Forward  
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 »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google