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
ms-access
gitlab
cloud
listview
fluentd
nullpointerexception
react-virtualized
jsp-tags
sqlite-net-extensions
graphql
youtube-api-v3
fsm
umd
webpack-2
opengl-es-2.0
networkx
ios-charts
dacpac
metatrader4
spring-tool-suite
hapi
circuit
designer
jsprit
progressive-web-apps
apache-metamodel
sms-gateway
dbext
opencover
csrf-protection
p-value
react-css-modules
greendao
ping
wtx
large-file-upload
frame
iframe-resizer
preg-match-all
vsts-build-task
hybridauth
textmate
azure-sql-database
environment-modules
nssegmentedcontrol
adobe-premiere
lto
arena-simulation
mime
convertapi
angular2-meteor
jquery-nestable
powercli
tropo
spring-cache
redundancy
smart-table
gnome-shell-extensions
migradoc
xcb
spring-android
intrusion-detection
google-web-starter-kit
fuzzy-search
multiple-regression
master-slave
packagist
associative-array
cloudbees
ios8-today-widget
tmuxinator
wordml
computer-algebra-systems
muse
sankey-diagram
ami
sortedlist
e10s
lustre
website-monitoring
device-manager
eol
contenttype
yorick
jboss-weld
hyprlinkr
cdc
tidy
odata4j
quartz-graphics
mqx
ocunit
cassini-dev
mt
punbb
doh
vdsp
krl
radcombobox
getresponsestream
xsdobjectgen
preference
misv

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