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 }; 
};
...

もう 1 つのアプローチは、次のようにして、すべてのインスタンスの GetParentPath をリダイレクトすることです。

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