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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I found a bug when mocking method calls on a struct and the order in which the recording statements are issued.

Here is an example where ParentalControlSettings is a Struct.

IBaseMediaTitle title = RecorderManager.CreateMockedObject<IBaseMediaTitle>();
Account account = RecorderManager.CreateMockedObject<Account>();
ParentalControlSettings settings = new ParentalControlSettings();

using (RecordExpectations recorder = RecorderManager.StartRecording()) {
      recorder.ExpectAndReturn(account.ParentalControlSettings, settings);
      recorder.ExpectAndReturn(settings.IsTitlePermitted(title), true);
}
         
Assert.IsTrue(account.ParentalControlSettings.IsTitlePermitted(title));


If I execute the above code, then I get this error:
Can not mock chained statements with 'struct' objects. Account.get_ParentalControlSettings() returns GameFly.Retail.Domain.Customer.ParentalControlSettings


however, if I change the recording block to this
using (RecordExpectations recorder = RecorderManager.StartRecording()) {  
   recorder.ExpectAndReturn(settings.IsTitlePermitted(title), true);
   recorder.ExpectAndReturn(account.ParentalControlSettings, settings);
}



the test succeeds correctly. All I did was change the order of the expectations. Pretty weird bug if you ask me, and also a bad exception message since there isnt a chained statement.

Please let me know if you need more info.

Thanks,
Jesse
asked by juice_johnson (9.8k points)

2 Answers

0 votes
Hi,
Indeed this looks like a wierd defect.
we will investigate this and let you know
answered by lior (13.2k points)
0 votes
Hi,

We've introduced the fix in the 4.2 version which now out!

The fix for the bug was part of the treatment we gave method chains. While Typemock Isolator does not support chains with structs, the identification of chains was re-defined and remove the order dependency depicted in the post.
answered by gilz (14.5k points)
...