void SomeMethod(object c)
{
if (c.GetType() == typeof(SqlConnection))
{
// ..some code that wan't invoke but should
}
}
I need the code inside brackets to invoke, but it won't. Unless I mock
the GetType method, while the code of SomeMethod can not be modified.
Is it possible?
Patrick Steele
unread,
Mar 12, 2008, 5:22:35 PM3/12/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Rhino...@googlegroups.com
I think you'd rather do:
if(c is IDbConnection) { ...
alamandra007
unread,
Mar 12, 2008, 5:50:34 PM3/12/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Rhino.Mocks
I said that I can not modify SomeMethod method.
Patrick Steele
unread,
Mar 12, 2008, 5:52:39 PM3/12/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Rhino...@googlegroups.com
Oops. Sorry, missed that.
alamandra007
unread,
Mar 12, 2008, 6:06:22 PM3/12/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Rhino.Mocks
That's ok:) Nobody's perfect!
alamandra007
unread,
Mar 13, 2008, 1:21:58 PM3/13/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Rhino.Mocks
I get the InvalidOperationException with message "Can set only a
single return value or exception to throw or delegate to execute on
the same method call", when i try to mock the method at line
where this.Target is a mocked SqlConnection instance.
Ayende Rahien
unread,
Mar 13, 2008, 4:03:55 PM3/13/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Rhino...@googlegroups.com
That is because GetType() cannot be mocked using normal mocks. You can use remoting mocks, but I _STRONGLY ADVICE_ you to avoid this.
The code that you have at the moment should be changed, and the tests are showing you this.
Owen Evans
unread,
Mar 13, 2008, 4:10:52 PM3/13/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Rhino...@googlegroups.com
I would agree on Ayende's point really do advise avoid. Ask why you are testing a class you cannot modify (you stated you can't modify the call to gettype) and instead try and abstract away the code that is fixed and use an adapter or factory facade so that you can just remove the test reliance on untestable code
my 2 cents
O
alamandra007
unread,
Mar 13, 2008, 4:49:59 PM3/13/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Rhino.Mocks
While I'm still not convinced, why remoting mocks are such a bad idea,
could you please briefly describe the reasons for not using them?
Ayende Rahien
unread,
Mar 13, 2008, 4:51:49 PM3/13/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message