4

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.

Craig W.
  • 17,838
  • 6
  • 49
  • 82

1 Answers1

6

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);
Blair Conrad
  • 233,004
  • 25
  • 132
  • 111
Patrik Hägne
  • 16,751
  • 5
  • 52
  • 60
  • 1
    Outstanding. At first it still wasn't working, but when I changed it to A.That.IsSameSequenceAs(new string[] { "SomeChild" }) it worked like a charm. – Craig W. Oct 21 '11 at 17:21
  • I also added an issue on github as requested. – Craig W. Oct 21 '11 at 17:26
  • Great, I'll try to come up with a fix of the issue. – Patrik Hägne Oct 22 '11 at 19:06
  • Is the Workaround with IsSameSequenceAs still the way to go? The other variations from the original questions and also A.That.IsEqualTo() don't work with FakeItEasy 6.0 – Anton R Nov 24 '21 at 11:08
  • @AntonR, there should be no need for workaround. On FIE 7.3.1, ` A.CallTo(() => dal.GetFooById(7, "SomeChild"))` is working for me. If you continue to have a problem, perhaps submit a new question or [github issue](https://github.com/FakeItEasy/FakeItEasy/issues/new). – Blair Conrad Oct 12 '22 at 01:59