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
yii2
pdf
image
variables
ngrx
plot
objectgears
kalman-filter
google-project-tango
esper
medical
metatrader4
collectd
apache-metamodel
propel
database-replication
ab-testing
karma-jasmine
css-animations
chromium-embedded
devops
php-openssl
autosys
crystal-reports-2010
microsoft-sync-framework
pepper
windows-error-reporting
socialengine
galsim
airconsole
asset-pipeline
nssegmentedcontrol
bitbucket-pipelines
dynamics-crm-2013
withings
bootstrapper
dynamic-reports
botbuilder
mime
scorm
logfiles
smartcontracts
fancybox-2
qtwebview
crosswalk-runtime
pycaffe
color-picker
removechild
libpng
google-web-starter-kit
oauth2client
photobucket
cyclomatic-complexity
metaclass
jqgrid-formatter
rgeo
drawbitmap
service-accounts
umbraco6
system.reflection
jsonpickle
java.util.concurrent
file-copying
socketexception
issuu
rdl
has-many-through
elliptic-curve
cloud-connect
srs
centos5
ms-project-server-2010
ril
qt-faststart
spring-validator
limejs
mhtml
browser-detection
sublist
isnullorempty
ocx
appconkit
wse3.0
work-stealing
zpt
vdsp
mongomapper
gin
nsviewanimation
avatar
spec#
ugc
ajax-forms
document-conversion
uiq3

Resources

Encrypt Message