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 am seeing this error running tests on the build/test server.  This is a com interop object being mocked.

 Error: Missing method 'instance object [FwRulesNetCSharp] FwBaseLib.IFwAttribute::get_Value()' from class 'Mock0003FwAttribute'. - VB Error 0 -

locally the tests pass without any failures.

Now I found a solution but need to understand why.

my mock is such:

var fakeAttributes = Isolate.Fake.Instance<FwAttributes>(Members.ReturnNulls);
            Isolate.WhenCalled(() => fakeAttributes.Count).WillReturn(attributes.Rank);
            for (int i = 0; i < attributes.GetLength(0); i++)
            {
                var fakeAttribute = Isolate.Fake.Instance<FwAttribute>(Members.CallOriginal);
                Isolate.WhenCalled(() => fakeAttribute.Value).WillReturn(attributes[i, 0]);
                Isolate.WhenCalled(() => fakeAttribute.Name).WillReturn(attributes[i, 1]);
 
                Isolate.WhenCalled(() => fakeAttributes.get_Key(i)).WillReturn(attributes[i, 1]);
                Isolate.WhenCalled(() => fakeAttributes.get_Value(i)).WillReturn(fakeAttribute);
            }
 
This FwAttrbute object has an interface on it.
The problem is the value method.
signatures are:
 
string _Value { get; set; }
    Member of FwBaseLib.IFwAttribute

and

dynamic Value { get; set; }
    Member of FwBaseLib.IFwAttribute
 

The code is such

      string val = Attributes.Value[i].Value;

passes running test in visual studio but fails on the build server.

I change to 

      string val = Attributes.Value[i]._Value;

and it passes in both places.

What gives?  Is because it is dynamic?

 

gilstrac

 

 

 

asked by gilstrac (600 points)

1 Answer

0 votes

Hi Gilstrac,

It is hard to tell without the code, but I am guessing it has to do with the index.

when you use:

Isolate.WhenCalled(() => fakeAttributes.get_Value(i)).WillReturn(fakeAttribute);

the arguement i is ignored by default, you can either:

Isolate.WhenCalled(() => fakeAttributes.get_Value(i)).WithExactArguments().WillReturn(fakeAttribute);

or call the index directly (this defaults to following the index value)

Isolate.WhenCalled(() => fakeAttributes.Value[i]).WillReturn(fakeAttribute);

if this is not that case. can you send a simple example?

answered by eli (5.7k points)

You need to go an object down.  Not the Attributes object but the attribute object.

Isolate.WhenCalled(() => fakeAttribute.Value).WillReturn(attributes[i, 0]);

 

The error message would not point me to an index error.

Missing method 'instance object [FwRulesNetCSharp] FwBaseLib.IFwAttribute::get_Value()' from class 'Mock0003FwAttribute'. - VB Error 0 -

 

The fix to get the test to pass was to refer to the _Value method on the FWAttribute object in the code under test.  

 

 

 

...