fakeiteasy


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.
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);

Related Links

Converting an MOQ property setup to FakeItEasy
Howto loop OrderedAssertions in FakeItEasy 2
FakeItEasy setting property with no get accessor?
FakeItEasy mocked method won't return object, instead nullReferenceException
How to specify the class to use when faking a property?
How can I fake a Class used insite SUT using FakeItEasy
FakeItEasy expectation fail against HashSet comparisons
FakeItEasy AssignsOutAndRefParameters - lazily?
How do I find the underlying Type of a Fake object returned from FakeItEasy?
FakeItEasy ReturnsLazily with out parameter
how to verify that a method was called with an argument of a specific type
How to fake delegates with FakeItEasy
FakeItEasy & “params” arguments
Using Expression Trees as an argument constraint
How to update a property on a parameter using FakeItEasy

Categories

HOME
image
date
testng
pycharm
view
objectgears
alfresco
read-eval-print-loop
paw-app
leon
microservices
rubygems
jgroups
binary-tree
retrofit
ojdbc
django-imagekit
constraint-programming
cross-validation
google-translate
maude-system
leiningen
windows-server-2012
hapi
django-simple-history
uitypeeditor
transformation
footer
beyondcompare
openedx
firefox-webextensions
jprofiler
swiftlint
jasonette
accessor
restful-authentication
angular2-aot
uninstall
buck
kendo-datasource
r-raster
google-cloud-endpoints-v2
uisplitview
scorm2004
webtest
lxd
stacked
adobe-premiere
occlusion
particles.js
quadratic-programming
heightmap
convertapi
termination
upstart
tactic
nsarray
akka-cluster
cudafy.net
flutterwave
minimization
chord-diagram
google-cdn
spring-android
httplistener
dstu2-fhir
markojs
react-native-listview
skype4py
r-tree
cyclomatic-complexity
python-3.2
wireshark-dissector
content-length
ideamart
splash
sankey-diagram
fluid-dynamics
angularjs-ng-click
mesa
p4java
undefined-reference
aqtime
jmapviewer
web2py-modules
quartz-graphics
sharp-repository
selected
quickdialog
gdata-api
jspinclude
netdna-api
heartbeat
genshi
psi
xtype
recent-documents
celltable
gin
nsviewanimation
asp.net-profiles
vc90
ti-dsp
port-number
lzh

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App