Craig W.
Craig W.

Reputation: 18155

FakeItEasy & "params" arguments

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<IDal>();

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 use:

A.CallTo(()=>dal.GetFooById(7, A<string[]>.Ignored )).Returns(fooToReturn);

I'd prefer to be able to specify the value of the second argument so the unit test will break if someone changes it.

Upvotes: 4

Views: 3156

Answers (1)

Patrik H&#228;gne
Patrik H&#228;gne

Reputation: 17141

Update: I'm not sure when, but the issue has long since been resolved. FakeItEasy 2.0.0 supports the desired behaviour out of the box.

It might be possible to special case param-arrays in the parsing of the call-specification. Please submit an issue at: https://github.com/patrik-hagne/FakeItEasy/issues?sort=created&direction=desc&state=open

Until then, the best workaround is this:

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

Upvotes: 6

Related Questions