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
cookies
oracle11g
react-virtualized
iterator
sd-card
filtering
analysis
graphql
frameworks
survey
podio
contact
add
session-variables
ssl-client-authentication
nano-server
resize
n-gram
orchardcms
messages
angular2-aot
one-to-many
su
pingfederate
traffic
webkitspeechrecognition
kendo-datasource
google-cloud-endpoints-v2
twilio-api
framemaker
stringtemplate
azure-sql-database
git-merge
multilingual
libvpx
abstract-class
webix-treetable
azure-ml
hp-ux
ibpy
gpx
dotcover
osx-mavericks
appcompat
strptime
jedis
dropbox-php
kbuild
magma
nodebb
windows-mobile-6.5
akka-cluster
mako
spring-cache
hittest
orthogonal
quartz-composer
abcpdf9
wdf
log4c
dstu2-fhir
measures
mongocsharpdriver
markojs
livequery
jms2
google-places
t4mvc
rake-task
typekit
xc16
rdtsc
nsbutton
id3v2
device-manager
gulp-less
mesa
typeof
bundles
oracle-warehouse-builder
jsctypes
tidy
ruby-datamapper
dbconnection
bulkloader
gwt-rpc
pushbackinputstream
unc
cisco-jtapi
armcc
tridion-worldserver
chrono
amazon-appstore
qt-jambi
gcj
genshi
krl
visitor-statistic
yslow
zend-translate
firefox4
data-driven
phonon

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