开发者

Is there a way in Moles to mole/mock a method with the params keyword?

开发者 https://www.devze.com 2023-03-14 15:24 出处:网络
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:

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

精彩评论

暂无评论...
验证码 换一张
取 消