fakeiteasy


FakeItEasy AssignsOutAndRefParameters - lazily?


I'm trying to fake a call to a method with an out parameter, with a ReturnsLazily with some basic logic in it. Ideally, I could assign a value via AssignsOutAndRefParameters based on the ReturnsLazily. However, AssignsOutAndRefParameters only accepts a value up front when the expression is compiled, is there any 'Lazily' type behavior that I'm missing?
Random r = new Random();
int[] value = new int[] { 1 };
A.CallTo(() => loader.TryLoad(A<int>.Ignored, out value))
.WithAnyArguments()
.ReturnsLazily((int key, int[] inValue) =>
{
List<int> result = new List<int>();
if (key > 0)
{
for (int i = 0; i < r.Next(100); i++)
{
result.Add(r.Next());
}
}
value = result.ToArray();
return result.Count > 0;
})
.AssignsOutAndRefParameters(value); //Assigns [1], instead of [r,a,n,d,o,m,i,n,t,s]
Update As #Crutt knows, FakeItEasy 1.22.0+ has AssignsOutAndRefParametersLazily, which supports exactly the desired behaviour:
Random r = new Random();
int[] value = new int[] { 1 };
A.CallTo(() => loader.TryLoad(A<int>.Ignored, out value))
.WithAnyArguments()
.ReturnsLazily((int key, int[] inValue) => key > 0)
.AssignsOutAndRefParametersLazily((int key, int[] inValue) =>
{
List<int> result = new List<int>();
if (key > 0)
{
for (int i = 0; i < r.Next(100); i++)
{
result.Add(r.Next());
}
}
return new object[] { result.ToArray() };
});
WAS:
No, I think you've found a hole where some functionality could be.
This appears not to be supported as of FakeItEasy 1.21.0.
I've created Issue 319 over at GitHub to track it.

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
ionic-framework
wso2-am
jdo
listview
cookies
oracle11g
kde
fft
webstorm
bookshelf.js
in-app-purchase
synchronization
communication
node-pdfkit
quickbooks
jplayer
dtrace
percona
uitypeeditor
windows-7-x64
reactcsstransitiongroup
normalizr
google-pagespeed
plunker
orleans
mps
dcevm
url-scheme
bootstrap-material-design
tooltipster
saas
yadcf
oracle-fusion-middleware
perlin-noise
azure-sql-database
atl
overlap
plsql-psp
main
lto
broadcastreceiver
ncalc
reportingservices-2005
bootstrap-dialog
cubic-spline
chain-builder
revapi
colorama
cudafy.net
imanage
grails-tomcat-plugin
azure-sdk
dstu2-fhir
impresspages
qgraphicsview
pickadate
maven-tomcat-plugin
endeca-workbench
content-length
coveralls
embedded-code
sysinternals
sortedlist
census
umbraco6
pick
coldbox
internet-connection
dml
didselectrowatindexpath
odata4j
dotnetnuke-5
bulkloader
easy-install
jplaton
dataadapter
django-nonrel
drools-planner
wsdl-2.0
path-separator
frameset
propertyeditor
pendrive
subscript
doh
data-loss
joyent
table-footer
winbugs14
telerik-scheduler
getresponsestream
compiler-specific
memory-size
simpletest
thread-local-storage
caching-application-block

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