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
hook
webpack
amazon-ec2
cookies
android-4.4-kitkat
q
cakephp-2.5
fingerprint
enterprise-library-5
echarts
awesome-wm
mapserver
nstableview
remote-access
beyondcompare
object-detection
clickonce
react-css-modules
rst2pdf
linkerd
fifo
nameservers
webtest
openoffice.org
form-data
mozilla
nssegmentedcontrol
dosbox
ssjs
ws-security
pdf-reactor
spring-security-kerberos
fakeiteasy
flashair
s
scrollable
python-c-api
hendrix
domain-model
return-value
elgg
r-forge
knpmenubundle
capacity
pagerank
lemon
icu4j
cannon.js
tmuxinator
security-testing
emailrelay
map-projections
appfabric-cache
cisco-ios
graph-api-explorer
lustre
qpainter
android-nested-fragment
googlemock
yorick
bundles
resty-gwt
farseer
sitemesh
dataservice
easy-install
sabredav
factory-method
free-variable
dmoz
path-separator
sublist
frameset
venn-diagram
armcc
reddot
infobox
gdlib
w3wp.exe
h.323
gamma
filtered-index
exchange-server-2003
xetex
port-number
ugc

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