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
I'm experimenting with the new Natural TypeMocks, and I cannot get them to work. I'm new to TypeMock in general, so it's possible I'm making a novice mistake.

I create a simple example of a class that has a method called foo that creates a standard List, and Adds something to it. I then create a seperate Test project that tests this class, and then try to mock out the call to Add. The TypeMock related code of my test looks like this:

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                aList.Add(null);
            }


I've tried many permutations of this code and I always get the following error: The name 'aList' does not exist in the current context

How is this supposed to work?

Thanks!

-Scot

[/code]
________
Nash-Kelvinator
asked by scotb (1.2k points)

3 Answers

0 votes
I would recommend you read the Understanding Instances Chapter in the User Guide.
See: Mocking Live Instance
Mocking Interfaces and Abstract classes
Mocking Future Objects

In your case you are creating a future object so you should create the object in the using block.

:idea: REMEMBER mocking objects from mscorlib (for example ArrayList) in not supported yet.
answered by scott (32k points)
0 votes
It was a Future object problem. Thanks!

Note that in my actual test case I had already created the object under test. What was Future was an object that got created by my object under test, and then called.

In the Natural TypeMock tutorial, section "The First Natural TypeMock", there's no mention of needing to create the object you're going to Mock calls on. Evidently that's because it was static. May I suggest you add a mock of a call on a non-static object in that section of the tutorial?

Thanks again for your help and your quick response.

-Scot
________
Buy silversurfer vaporizer
answered by scotb (1.2k points)
0 votes
:idea: Great tip, I think that we will use your suggestions.
answered by scott (32k points)
...