这是代码。按正常情况调用GetParentPath!
[TestMethod]
[HostType("Moles")]
public void GetParentPath_slashOnEnd_returns()
{
var sapi = new MPhotobucketApi();
sapi.GetParentPathString = s => s;
var api = new PhotobucketApi();
var parentPath = api.GetParentPath("hello/world/");
Assert.AreEqual(parentPath, "hello");
}
答案 0 :(得分:1)
编写测试的方式,重定向仅适用于sapi中嵌入的运行时实例。你需要拦截PhotobucketApi的构造函数并拦截PhotobucketApi的'future'实例:
MPhotobucketApi.Contructor = (me) => {
new MPhotobucketApi { GetParentPathString = s => s };
};
...
另一个方法是通过执行以下操作为所有实例重定向GetParentPath:
MPhotobucketApi.AllInstances.GetParentPathString = (me, s) => s;
...