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
clips
wso2
reflection
azure-data-factory
ngrx
include
syntax
relay
rsyslog
sqlite-net-extensions
analysis
tizen-web-app
v8
retrofit
installshield
angular-ui-bootstrap
pivotal-cloud-foundry
indesign
cross-validation
slick-slider
etl
circular-dependency
dtrace
visual-studio-cordova
ghc
systemc
fatal-error
windows-7-x64
reactive-cocoa
ab-testing
lldb
dbext
kryo
object-detection
cloudhub
chromium-embedded
realex-payments-api
p-value
brunch
uninstall
fopen
applozic
vision
kendo-datasource
phonegap
winrt-xaml-toolkit
windows-dev-center
y86
mixture-model
splice
ibpy
heightmap
eclipse-gef
segment
flickr-api
termination
worksheet
typescript1.8
rdfs
gabor-filter
setter
nativeapplication
nsarray
akka-cluster
epson
gcsfuse
titanium-android
gnome-shell-extensions
migradoc
jquery-filter
android-textview
google-web-starter-kit
ctest
gstreamer-0.10
blackberry-10
hover-over
yaws
oauth2client
freelancer.com-api
prerequisites
ora-00900
simple-framework
android-listview
tableau-online
apache-commons-fileupload
createprocessasuser
generic-programming
iiviewdeckcontroller
proj4js
lustre
c++03
modalpopup
rake-task
html-helper
google-reader
mesa
expected-exception
picturefill
datagridviewcolumn
transcoding
ftps
cos
gridcontrol
rabl
django-nonrel
jquery-mobile-dialog
cassini-dev
kyotocabinet
free-variable
cisco-jtapi
word-processor
multipage
twrequest
appconkit
pendrive
subscript
transactionscope
adk
doh
data-loss
deobfuscation
heartbeat
f#-powerpack
xmemcached
javax.script
appender
self-extracting
celltable
imac
telerik-scheduler
fluent-interface
thunderbird-lightning
pascal-fc
procedural-music
private-members

Resources

Encrypt Message