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
osgi
single-sign-on
amortized-analysis
survey
fingerprint
mvvmcross
django-imagekit
azure-storage-tables
upload
multiple-records
applepay
python-unittest
user-input
kentor-authservices
wheelnav.js
alignment
fortumo
windows-server-2012
workload-scheduler
solaris-10
flux
samoa
viewport
lldb
jtextfield
swingx
swiftlint
java-3d
restful-authentication
autosys
fish
apache-commons-io
internet-explorer-9
windows-error-reporting
file-rename
galsim
oracle-fusion-middleware
google-api-nodejs-client
catalog
bower-install
overlap
stacked
dosbox
espeak
objectlistview
unspecified
azure-ml
unoconv
ncalc
sql-server-agent
zip4j
jquery-validate
nstextview
snmptrapd
ifs
akka-cluster
dwscript
objective-c-swift-bridge
pcf
contact-list
unity-networking
pervasive-sql
ora-00900
sdhc
python-3.2
wireshark-dissector
citrus-pay
content-length
computer-algebra-systems
deis
apache-commons-fileupload
graph-api-explorer
npapi
formatjs
fscommand
typekit
xc16
nstableviewcell
codeigniter-url
gui-test-framework
socketexception
java-metro-framework
device-manager
internet-connection
p4java
poller
undefined-reference
oracle-warehouse-builder
algebraic-data-types
typo3-neos
google-cloud-save
cassini-dev
pvrtc
funscript
twrequest
windows-phone-7.1.1
doh
data-loss
deobfuscation
blackberry-playbook
dmx512
sproutcore-2
memory-size
backcolor
.net-1.0

Resources

Encrypt Message