【发布时间】:2013-07-01 13:27:51
【问题描述】:
我有以下方法。
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;
}
我尝试在我的测试用例中使用以下内容。
[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);
}
它抛出了以下 typemock 异常。
TypeMock.TypeMockException : * 在录制块中没有找到方法调用。请检查: * 您是否试图伪造字段而不是属性? * 您是否在尝试伪造不受支持的 mscorlib 类型?
有没有办法解决这个问题?
【问题讨论】:
-
但他们没有提到如何使用 Typemock 实现这一目标
-
你能分享你整个单元测试的代码吗?
-
请始终在问题本身而不是在 cmets 中为您的问题添加附加信息或说明。这将有助于未来的用户/观众理解问题。
-
@RyanGates:根据您的评论编辑
标签: c# nunit typemock typemock-isolator nunit-2.5.9