fakeiteasy


Howto loop OrderedAssertions in FakeItEasy 2


As I understand, ordered assertions in FakeItEasy 2 are done like this (from the docs):
// Assert
A.CallTo(() => unitOfWorkFactory.BeginWork()).MustHaveHappened()
.Then(A.CallTo(() => usefulCollaborator.JustDoIt()).MustHaveHappened())
.Then(A.CallTo(() => unitOfWork.Dispose()).MustHaveHappened());
Now, suppose I have a collection and for each item in this collection I want to assert that a call was made to a faked object. What is the best approach to assert the calls were made in the correct order?
I came up with this, but don't really like it:
IOrderableCallAssertion ioca = null;
foreach (var item in items.OrderBy(i => i.Id)
{
var itemUnderTest = item;
if (ioca == null)
{
ioca = A.CallTo(() => fakeObject.Handle(itemUnderTest, otherArgument)).MustHaveHappened(Repeated.Exactly.Once);
}
else
{
ioca = ioca.Then(A.CallTo(() => fakeObject.Handle(itemUnderTest, otherArgument)).MustHaveHappened(Repeated.Exactly.Once));
}
}
That looks about right to me. Of course, you could inline itemUnderTest and pull MustHaveHappened outside of the two if branches.
And you could always hide this in a convenience method.
An alternative: use Invokes to capture the fakes as the calls come in and later compare them against a list.

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
gerrit
reserved
onedrive
android-4.4-kitkat
tizen-web-app
twitter-bootstrap-4
c#-2.0
jpeg
installshield
angular-ui-bootstrap
here-api
remote-access
static-libraries
messages
ibm-odm
foselasticabundle
highlight.js
flux
normalizr
samoa
textfield
swingx
grails3
intentfilter
cloudhub
graphicsmagick
tibco-mdm
smb
fish
underflow
elasticsearch-ruby
google-cloud-nl
bluestacks
tinymce-4
javascriptcore
exuberant-ctags
karaf
google-sites-2016
google-qpx-express-api
avcapturesession
overriding
theano.scan
elasticsearch-plugin
jvm-languages
outlook-api
acoustics
auto-update
jsch
dds
prolog-setof
tropo
aurelia-validation
sybase-asa
titanium-android
django-scheduler
objective-c-swift-bridge
medium.com
libpng
trash
gstreamer-0.10
multiple-regression
skype4py
suffix-tree
design-by-contract
wapiti
system.management
pyke
kendonumerictextbox
wordml
fouc
pundit
quicklisp
dukescript
microbenchmark
ideamart
twirl
myo
system32
device-orientation
client-side-templating
android-2.2-froyo
transcoding
cos
eclipse-memory-analyzer
anonymous-methods
isnullorempty
labwindows
viewswitcher
assembly-loading
cufon
libc++
spyware
heartbeat
appender
disclosure
gallio
webkit.net
spec#
defensive-programming
django-notification

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