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
Hi forum

I'm using typemock 6.0.8.0.

I read the docs on mocking static classes here:
http://docs.typemock.com/Isolator/##typemock.chm/Documentation/StaticAAA.html

I put together the test case below. But can't get it to work.

The test fails in the Isolate.WhenCalled line. So this is during setup of what to return when called. Why is is calling the method in this line?

Hope someone can help.

[TestMethod, Isolated]
public void TestMockStatic()
{
    Isolate.Fake.StaticMethods(typeof(Directory), Members.CallOriginal);
    Isolate.WhenCalled(() => Directory.EnumerateFiles(null)).WillReturn(new List<string> { "myconfigfile.xml" });

    Assert.IsTrue(Directory.EnumerateFiles("somenotnullvalue").GetEnumerator().MoveNext());
}

Best regards
JAXN
asked by JAXN (600 points)

1 Answer

0 votes
Hi,

The reason it fails is that Directory class belongs to mscorlib assembly and the support of this assembly is limited. We plan to support Directory class in the next version.

As a workaround you can use a wrapper class which will call Directory.EnumerateFiles and use it in production code and in tests.

Regards,
Elisha,
Typemock Support
answered by Elisha (12k points)
...