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
Firstly, I searched the forum (and google) and found this. Sadly, none of the linked posts were helpful in solving my problem.

This is my test:

    [TestFixture]
    [Isolated]
    public class GetExternalEndpointsActivityFixture
    {
        [Test]
        public void Execute_WillReturnConfiguredExternalEndpoints()
        {
            Isolate.Fake.StaticMethods(typeof(ConfigurationManager));
            var mySection = Isolate.Fake.Instance<MyConfigSection>();
            var externalEndpointsCollection = Isolate.Fake.Instance<ExternalEndpointsCollection>();
            Isolate.WhenCalled(() => mySection.ExternalEndpoints = externalEndpointsCollection);
            var sectionName = "mySection";
            Isolate.WhenCalled(() => ConfigurationManager.GetSection(sectionName)).WillReturn(mySection); // <-- This fails
        }
    }


I've removed anything that isn't related directly to the problem. On the final line, which is marked with a comment, TypeMock complains:

TypeMock.TypeMockException :
*** No method calls found in recording block. Please check:
* Are you trying to fake a field instead of a property?
* Are you are trying to fake an unsupported mscorlib type? See supported types here: https://www.typemock.com/mscorlib-types


This is a method, not a field, so I assume it isn't talking about that. Also, ConfigurationManager isn't part of the mscorlib, and I understand that what I am doing should be fully supported by TM.

The version I am using is 7.0.6.0

Thanks,
Gary
asked by gurhall (2.3k points)

3 Answers

0 votes
Hello Gary,

It seems that the cause of the problem is this line:

 Isolate.WhenCalled(() => mySection.ExternalEndpoints = externalEndpointsCollection);


What are you trying to set in this line?

I think it should look something like this:

Isolate.WhenCalled(() => mySection.ExternalEndpoints).WillReturn(externalEndpointsCollection);


Please try and let me know of it helps,
answered by NofarC (4k points)
0 votes
Hmmm... That worked, thank you. That's great, but the stack trace was pointing me to the line *after*, which is when I mock GetSection. Slightly misleading, but I realize that the prior call was nuts so that explains it.

Thanks again,
Gary
answered by gurhall (2.3k points)
0 votes
Hi Gary,

Glad to read it helped.
answered by NofarC (4k points)
...