Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FakeItEasy & "params" arguments

Tags:

fakeiteasy

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.

like image 845
Craig W. Avatar asked Oct 26 '25 16:10

Craig W.


1 Answers

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);
like image 105
Patrik Hägne Avatar answered Oct 28 '25 08:10

Patrik Hägne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!