fakeiteasy


How do I find the underlying Type of a Fake object returned from FakeItEasy?


I've done
fake1 = A.Fake<MyType>()
then I want to use 'reflection' on the fake to register the dependency with my dependency container as MyType. However, I'm having trouble figuring out how to get the underlying faked type. Any pointers?
Here's the code I ended up with.
var builder = new ContainerBuilder();
foreach (var obj in fakes)
{
Type fakedType = obj.GetType().BaseType;
builder.RegisterInstance(obj).As(fakedType);
}
Note that it assumes you are doing virtual method on base class faking, not interface faking, since that currently holds true for me. :)
You could easily extend it with a little more reflection to register the instance as all of its inherited interfaces too...

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
multithreading
amazon-ec2
azure-data-factory
heroku
google-api-php-client
tinymce
include
bpmn
mean-stack
filtering
twitter-bootstrap-4
alpha
ezpublish
networkx
add
metatrader4
dax
modelica
vb.net-2010
leiningen
visual-studio-2005
messages
visual-studio-cordova
iron-router
jsdoc
normalizr
firefox-webextensions
karma-jasmine
ml
sylius
zurb-foundation-6
sqlcipher
shopware
vlsi
apache-commons-io
dynamic-featured-image
selectedindexchanged
wtx
procdump
unboundid
flink-streaming
microsoft-chart-controls
typed.js
html5-fullscreen
wixsharp
stacked
streamsets
trim
jvm-languages
http-redirect
cubic-spline
qwt
scrollable
dandelion
gabor-filter
darcs
forever
composite-key
python-cryptography
pdfclown
topbeat
yt-project
word-vba-mac
color-picker
httplistener
trash
impresspages
plottable.js
lua-5.1
bluemix-app-scan
wapiti
teamcity-8.0
comobject
content-length
android-listview
php-ci
method-parameters
appfabric-cache
sankey-diagram
census
lustre
kineticjs
tween
oxwall
android-imagebutton
navigationservice
elliptic-curve
wp-query
rtmfp
transcoding
viadeo
fmod
sabredav
itmstransporter
e4x
trusted
gnu-prolog
winbugs14
blitz++
mirah
xetex
scripting-languages
defensive-programming
data-acquisition
windows-live-messenger

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