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
jdo
cloud
asp.net-core
fluentd
mockito
iot
malloc
rubygems
serverspec
append
midi
rascal
pugjs
contextmenu
scichart
plunker
grails3
kryo
ml
mps
accessor
realex-payments-api
format-specifiers
bootstrap-material-design
social-media
typo3-6.2.x
gsmcomm
instant-messaging
preg-match-all
.net-4.0
exuberant-ctags
winrt-xaml-toolkit
android-kernel
mapdb
revolution-slider
file-format
awt
janrain
spring-security-kerberos
nxlog
outlook-2013
atomicity
theming
ifs
zendesk-app
titanium-android
android-fonts
nxt
passport-google-oauth
ado.net-entity-data-model
ipconfig
teamcity-8.0
citrus-pay
cakephp-3.1
oberon
unity5.2.3
jsapi
geonetwork
flask-cors
yorick
valuechangelistener
kgdb
picturefill
typo3-neos
oam
xsockets.net
apc
dbconnection
opcache
ocunit
factory-method
mhtml
sublist
getmessage
parametric-equations
uiviewanimation-curve
punbb
subscript
gcj
android-sdk-2.1
jmock
visitor-statistic
sproutcore-2
ncqrs
substrings
sef
simpletest
port-number
w3wp
multiple-languages

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