chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
We are using TypeMock to mock business logic classes in a product which is still work-in-progress; our mocked classes provide mocked data for the UI layer until such time as our back-end is up and running.

I can work out how to use Mock and MockObject to mock classes, and property gets/sets, and even methods with return values (via AlwaysReturn and ExpectGetAlways).

However I'd like to know how to mock a method which has no return value (Sub in VB.NET, Void in C#) and when the real method is called either:

1) Always do nothing

2) Always call my own mocked implementation of the method in our own mocked assembly class

I've looked at the documentation and Mock/MockObject.ExpectAlways and also the MethodSettings object but am not clear how to go about doing what I want?

Thanks.

-Alastair
asked by alastair.cameron@kal (3.4k points)

3 Answers

0 votes
Hi
When you want the unmocked implementation to be called use
mock.ExpectUnmockedSet("Start").Args(New ParameterCheckerEx(AddressOf MockStartPropertySet)) 


What I meant is if you have code like this:
myClass.Start = otherClass.Method();


If you want to set myClass.Start to a specific value
You can do this:
 
Mock mock = MockManager.Mock("OtherClass");
DateTime returnDateTime = new DateTime(...);
mock.ExpectAndReturn("Method", returnDateTime);


Hope it helps :)
answered by ohad (35.4k points)
0 votes
yes I stumbled across .ExpectUnmockedSet which allows me to have a delegate function called to intercept the parameter value set by the propety set method while at the same time allowing unmocked calls.

Thanks for your help.
answered by alastair.cameron@kal (3.4k points)
0 votes
oops :oops:
Now I noticed.
I messed up the answers
The answer above is regarding your other post.

Just to clean the table:
If there something that's still unclear in one of the posts please tell me.
Sorry about the mess.
answered by ohad (35.4k points)
...