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
try the below code:
    public class CronJobRun
    {
        public string ImageRootDirectory
        {
            get
            {
                return @"C:Documents and Settings	estMy DocumentsImage Directory";
          
            }
        }
    }


And the below test code:
        [Test, Isolated]
        public void GetFile_TooMany_Test()
        {
     
            Isolate.WhenCalled(() => Directory.GetFiles(cronJob.ImageRootDirectory))
                .WillReturn(new[] { "1", "2" });
  
        }



And this is the error I got:
TestCase 'GetFile_TooMany_Test' failed: System.ArgumentNullException : Value cannot be null.
Parameter name: path
   at System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption)
   at System.IO.Directory.GetFiles(String path, String searchPattern)
   at System.IO.Directory.GetFiles(String path)


This is confusing: can your return something like cannot mock from mscorlib error?
________
Thinkmill
asked by nsoonhui (59.1k points)

1 Answer

0 votes
Hi Soon Hui,

I agree that the error message is confusing and should be fixed. The root cause for this a known issue with Isolator which can't fake a chain nested within another chain. If you refactor the line:
Isolate.WhenCalled(() => Directory.GetFiles(cronJob.ImageRootDirectory)).WillReturn(new[] { "1", "2" });

to:
var directory = cronJob.ImageRootDirectory;
Isolate.WhenCalled(() => Directory.GetFiles(directory)).WillReturn(new[] { "1", "2" });


It should work.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
...