Mocked COM objects return ObjectProxy instances instead of the object I want to return

17 views
Skip to first unread message

Rob Hammond

unread,
Feb 24, 2012, 2:07:30 PM2/24/12
to Rhino.Mocks
Hi,

Are COM objects / interfaces treated differently by Rhino Mocks when
you set up expectations? Here is a sample expectation I am setting
up, note _mockDomain is a mocked COM object:

object files = new[] { "Core", "Device", "Xact", "SettingsFull",
"Settings", "DataStore", "Sync", "Unknown" };
_mockDomain
.Stub(m => m.GetMailboxEntryIDs(Arg<string>.Is.Anything,
Arg<tAHDMailboxType>.Is.Anything, Arg<bool>.Is.Anything))
.Return(files);

When I get to the 'Act' portion of the test, Rhino Mocks returns an
instance of ObjectProxy instead of the string[] 'files' I have defined
in my test.

Thanks,

Rob Hammond

Patrick Steele

unread,
Feb 24, 2012, 8:07:12 PM2/24/12
to rhino...@googlegroups.com
There's a few things to check:

1. "files" is an object (as defined by your code). Why not use var
(to get the implicit string[])?
2. What's the signature of GetMailboxEntryIDs?
3. Is GetMailboxEntryIDs virtual?
4. Can you show the code where you create the mock?

---
Patrick Steele
http://weblogs.asp.net/psteele

> --
> You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group.
> To post to this group, send email to rhino...@googlegroups.com.
> To unsubscribe from this group, send email to rhinomocks+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
>

Rob Hammond

unread,
Feb 24, 2012, 8:14:59 PM2/24/12
to rhino...@googlegroups.com
I ended up switching to the using() style syntax and it worked as expected.


Sent via the Samsung Galaxy S™ II Skyrocket™, an AT&T 4G LTE smartphone.

Rob Hammond

unread,
Feb 24, 2012, 8:22:36 PM2/24/12
to rhino...@googlegroups.com
1) getmailboxentryids is a virtual method that returns type object. The signature is (enum,enum,string)

2) I was using AAA style to generate the mock (MockRepository.GenerateMock static method) .

I found that switching to the using() style syntax made the mock behave as expected.   Are mocks generated from the static method supposed to behave differently?

Patrick Steele

unread,
Feb 27, 2012, 8:59:12 AM2/27/12
to rhino...@googlegroups.com
I rarely use the record/replay semantics, but I don't see why the
behavior of the mock would be different. Oh well, at least you got it
working!

Reply all
Reply to author
Forward
0 new messages