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
ngrx
office365api
fme
jsp-tags
analysis
jxls
fsm
google-project-tango
disassembler
enterprise-library-5
podio
google-translate
commonmark
iron-router
vaadin7
interop
excel-vba-mac
object-detection
java-3d
arabic
windows-error-reporting
minitab
opentype
primitive
tasklet
nat
xquery-3.0
titanium-mobile
pdb
vsts-build-task
dynamics-crm-2013
ansible-playbook
splice
import-from-excel
checkboxlist
dotcover
paxos
clean-architecture
hls.js
dropbox-php
drupal-6
darcs
android-cursor
windows-mobile-6.5
pintos
jquery-filter
url-masking
trash
python-stackless
fadeout
hsv
wso2cloud
wireshark-dissector
iis-arr
deis
device-orientation
tt-news
code-access-security
eol
heisenbug
balanced-payments
geos
jmapviewer
dataservice
pushbackinputstream
comaddin
limejs
cassini-dev
free-variable
unc
bitsharp
appconkit
external-accessory
hamachi
calling-convention
gdlib
android-sdk-2.1
mysql-error-1005
sortable-tables
asp.net-profiles
ncqrs
webkit.net
nerddinner
thread-local-storage
procedural-music

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App