Is there a way to mole/stub/mock a method with the params keyword?
Here is an example of the Method I am trying to mole/stub:
Void SomeMethod(bool finalizer,params string[] parameters)...
I have tried to mole it like so:
scriptServiceStub.SomeMethodBooleanStringArray=
开发者_开发问答 (bool finalizer, params string[] parameters) =>
{
agentCommCalled = true;
};
I am getting the following compile error:
'; expected' and 'Type Expected'
that highlights the params keyword.
I found a work around by creating method in the test class file and assigning the stub to this new method.
[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;
}
Just remove the params keyword from the delegate signature in your example and it will work just fine.
scriptServiceStub.SomeMethodBooleanStringArray=
(bool finalizer, string[] parameters) =>
{
agentCommCalled = true;
};
精彩评论