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
:D Congrats on the Natural Mock (TM) functionality - very nice. Have come across this though running under NUnit 2.2.0 Gui, VSNet 2003 IDE::

Production:
EventBase[] eventBases = EventFactory.Instance.GetEvents();


Test:
Mock mockEventBase = MockManager.Mock(typeof (EventBase), Constructor.Mocked);
         EventBase eventBase   = new EventBase();
         EventBase[] eventBases = new EventBase[]{eventBase};

using (RecordExpectations recordExpectations = RecorderManager.StartRecording())
{
....
    recordExpectations.ExpectAndReturn(EventFactory.Instance.GetEvents(), eventBases);            
....
}



This results in :

System.MissingMethodException : Constructor on type Rbsfm.Rates.VFramework.Events.EventBase[] not found.


Do you have any idea where I am going wrong? :?

(I tried to post this is the beta forum but it's locked)

c0d3-m0nk3y
asked by c0d3-m0nk3y (8.7k points)

4 Answers

0 votes
Nice one :oops:

This is a scenario that we missed, (returning arrays.)
We will send you a fix offline.

By the way, the code can be must simpler using the following:
using (RecordExpectations recordExpectations = RecorderManager.StartRecording())
{
....
    EventBase[] eventBases = new EventBase[]{new EventBase()};
    recordExpectations.ExpectAndReturn(
       EventFactory.Instance.GetEvents(), eventBases);            
....
}


This will work after the patch we will send
answered by scott (32k points)
0 votes
Thanks Scott - the patch fix worked with the code you suggested. 8)

However, it still generated a different error on a following line using the eventBases as an expected arg:

using (RecordExpectations recordExpectations = RecorderManager.StartRecording())
{
    recordExpectations.ExpectAndReturn(EventFactory.Instance.GetEvents(), eventBases);

    mockVFrameworkEventManager.ExpectCall("RegisterEvents").Args(eventBases);
}


The 'RegisterEvents' expectation fails as follows:

TypeMock.VerifyException : 
TypeMock Verification: Call to Rbsfm.Rates.VFramework.VFrameworkEventManager.RegisterEvents() Parameter: 1
    expected: <"Event - :" [Rbsfm.Rates.VFramework.Events.EventBase]>
     but was: [Rbsfm.Rates.VFramework.Events.EventBase[]]


I was able to fix this by changing the expectation to :

mockVFrameworkEventManager.ExpectCall("RegisterEvents").Args(new object[]{eventBases});


:idea: I know that Args uses a param argument and so I assume that each element in the array passed is treated as a separate argument to verify causing the fail - maybe this should be detailed in the guide that if passing an array as an expected arg it needs to be bounded in an object array?

Thanks again.
answered by c0d3-m0nk3y (8.7k points)
0 votes
Hi,
Your observation is correct.
I will ask to put this in our documentation.
answered by scott (32k points)
0 votes
:idea: version 3.5.1 now handles passing a single array as an expected arg automatically and there is no needs to bound the array in an object array.

Thanks for pointing this out.
answered by scott (32k points)
...