I have the following method.
public string CreateFile(string path, string fileName)
{
string fullPath = path + "ExportedFiles\\";
if (Directory.Exists(fullPath))
{
DirectoryInfo dir = new DirectoryInfo(fullPath);
foreach (FileInfo fi in dir.GetFiles())
{
fi.Delete();
}
}
else
{
Directory.CreateDirectory(fullPath);
}
string filePath = fullPath + fileName;
return filePath;
}
I attempted to used the following in my test case.
[Test, Isolated]
public void TestCreateFileIfPathExists()
{
Isolate.WhenCalled(() => System.IO.Directory.Exists("gsgs")).WillReturn(true);
Isolate.WhenCalled(() => testMyClass.CreateFile(@"D:\testFolder\","TestFile")).CallOriginal();
string result = testMyClass.CreateFile(@"D:\testFolder\", "TestFile");
Assert.AreEqual("D:\\testFolder\\ExportedFiles\\TestFile", result);
}
It's throwing the following typemock exception.
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?
Is there any way to solve this?
If you look at the last question of the exception that you are getting,
there is actually a web address after that in the exception, which reads
When you go there, you will notice:
Notably absent from this list is the
System.IO.Directory
class, which appears to not be supported TypeMock as of this writing. This is the line that is causing your error.