0

这是代码。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");
    }
4

1 回答 1

1

您编写测试的方式,您的重定向仅适用于嵌入在 sapi 中的运行时实例。您需要拦截 PhotobucketApi 的构造函数并在其中拦截 PhotobucketApi 的“未来”实例:

MPhotobucketApi.Contructor = (me) => {
    new MPhotobucketApi { GetParentPathString = s => s }; 
};
...

另一种方法是通过执行以下操作为所有实例重定向 GetParentPath:

MPhotobucketApi.AllInstances.GetParentPathString = (me, s) => s;
...
于 2010-07-14T14:36:31.750 回答