patrik-hagne/FakeItEasy — Issue #3: FakeItEasy and "params" args
Author: craig-wagner
Created: 2011-10-21 17:25:42+00:00
State: open

I have a method with the following signature.

Foo GetFooById( int id, params string[] children )

This method is defined on an interface named IDal.

In my unit test I write the following:

IDal dal = A.Fake();

Foo fooToReturn = new Foo();
fooToReturn.Id = 7;

A.CallTo(()=>dal.GetFooById(7, "SomeChild")).Returns(fooToReturn);

When the test runs, the signature isn't being matched on the second argument. I tried changing it to:

A.CallTo(()=>dal.GetFooById(7, new string[]{"SomeChild"})).Returns(fooToReturn);

But that was also unsuccessful. The only way I can get this to work is to either ignore the second argument:

A.CallTo(()=>dal.GetFooById(7, A.Ignored )).Returns(fooToReturn);

Or to use IsSameSequenceAs:

A.CallTo(()=>dal.GetFooById(7, A.That.IsSameSequenceAs(new string[] { "SomeChild" }) )).Returns(fooToReturn);

The latter works, but is a little long and unwieldly.

If FakeItEasy could handle params arguments more naturally (like the framework does) it would make this type of situation more intuitive.