単体テストは依存関係から分離する必要があることを知っています。Typemock を使用してアプリケーションの単体テストを作成しようとしています。問題は、クラス内のメソッドの 1 つで、いくつかの Xml ファイルパス パラメータを受け取り、メソッド内のどこかで使用される XMLDocument オブジェクトをメソッド内に作成することです。
public bool ValidateXml(String aFilePath, String ruleXmlPath)
{
XmlDocument myValidatedXml = new XmlDocument();
try
{
myValidatedXml.Load(aFilePath);
}
catch
{
return false;
}
XmlDocument myRuleXml = new XmlDocument();
try
{
myRuleXml.Load(ruleXmlPath);
}
catch
{
return false;
}
MyClass myObject = new MyClass(myValidatedXml);
//Do something more with myObject.
XmlNodeList rules = myRuleXml.SelectNodes("//rule");
//Do something more with rules object.
return true;
}
物理的な場所を指定せずに単体テストを作成するにはどうすればよいですか? 注: 残念ながらコードを変更することはできません。