fakeiteasy


how to verify that a method was called with an argument of a specific type


I need to verify that a method was called with an object of a specific type
this is the interface with the method that I want to test that it was called:
interface IPlayer
{
void Send(object message);
}
the test:
var player1 = A.Fake<IPlayer>();
room.AddPlayer(player1);
room.DoSomething();
A.CallTo(() => player1.Send(A<Type1>.Ignored)).MustHaveHappened();
since there are multiple calls to player1.Send with many different objects I get InvalidCastException
anybody knows how to do this properly ?
This is by design, what you're trying to do is actually:
A.CallTo(() => player1.Send(A<object>.That.IsInstanceOf(typeof(MessageType)))).MustHaveHappened();
The type specified in A<?> should always be the exact parameter type the method takes. I actually did consider changing it so that you could constrain the type the way you propose and if I remember correctly the main reason (but I think there were other reasons too) was that it would be more fragile in cases where you introduce overloads.
For example, consider that you introduced the following overload on your IPlayer interface:
interface IPlayer
{
void Send(object message);
void Send(Type1 message);
}
Once you introduce this overload your test changes meaning.

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
twitter
vbscript
debugging
magnific-popup
stock
iot
gis
paw-app
icloud
autotools
usergrid
windows-phone-7
fallback
quartz-scheduler
systemc
after-effects
beyondcompare
lldb
dbext
emulator
wkwebview
spark-jobserver
chromebook
tooltipster
typo3-6.2.x
karaf
commit
android-nestedscrollview
suricata
adobe-premiere
code-search-engine
sqlite2
webdriver-manager
optix
eigenvalue
unixodbc
node-sass
cubic-spline
jquery-nestable
hendrix
csound
jspdf-autotable
lync-client-sdk
vtigercrm
quartz-composer
eventkit
url-pattern
spring-android
angular-cache
bonobo
google-places
eclipse-clp
kcachegrind
method-parameters
vstest.console.exe
angular-local-storage
sonarqube5.1.2
jsonpickle
android-nested-fragment
castle
contenttype
seaside
kgdb
multiprocessor
mysqltuner
page-layout
oam
jsctypes
dexterity
gridcontrol
comaddin
jelly
cassini-dev
dice
first-responder
chrono
xmlspy
xmemcached
bespin
database-management
boost-smart-ptr
ugc
caching-application-block
document-conversion

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