2

params キーワードを使用してメソッドをモレ/スタブ/モックする方法はありますか?

これは、私がモル/スタブしようとしているメソッドの例です:

Void SomeMethod(bool finalizer,params string[] parameters)...

私はそれを次のようにほくろしようとしました:

scriptServiceStub.SomeMethodBooleanStringArray=
                (bool finalizer, params string[] parameters) =>
                    {
                        agentCommCalled = true;
                    };

次のコンパイル エラーが発生します。

'; 予想される」および「予想されるタイプ」

params キーワードを強調表示します。

4

2 に答える 2

1

テストクラスファイルにメソッドを作成し、この新しいメソッドにスタブを割り当てることで、回避策を見つけました。

[TestMethod()] 
[HostType("Moles")] 
public void NotifyAgentTest() 
{ 
    ... 
    //ensure that the correct values are passed to the agentComm. 
    // have to use a real method because of the parameters param w/ the params keyword. 
    scriptServiceStub.AgentCommStringArray = AgentCommDelegate; 
    ... 
    Assert.IsTrue(agentCommCalled);

}

public bool AgentCommDelegate(bool finalizer, params string[] parameters) 
{
    agentCommCalled = true; return true; 
}
于 2011-06-23T16:40:19.563 に答える