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

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.

Answers


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

Need Your Help

ifstream fails without any reason?

c++ ifstream

I have a list of 3d spheres, when I save the list, I loop through:

How to use library of other languages in Action Script 3?

actionscript-3 flash air

Is there any way to use the library of other language in Action Script 3 ?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.