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
vbscript
stock
lodash
fme
bpmn
cplex
google-docs
react-redux
yarn
graphql
sharepoint-designer
webpack-2
blueprintjs
opengl-es-2.0
wamp
azure-media-services
upload
cross-validation
webrequest
kibana-4
gnupg
google-cloud-spanner
windows-server-2012
django-simple-history
angular-ui
alpine
conemu
amazonsellercentral
one-hot-encoding
sylius
autosys
crystal-reports-2010
status
facebook-access-token
internet-explorer-9
windows-error-reporting
elasticsearch-ruby
log4js-node
quote
gsoap
microsoft-chart-controls
repo
mozilla
wallpaper
http-referer
http-digest
plsql-psp
espeak
event-driven
service-discovery
android-fingerprint-api
webdriver-manager
eclipse-scout
no-www
.net-4.6.2
upstart
jedis
pnotify
csound
nodebb
dynamics-sl
orthogonal
account-kit
google-cdn
ableton-live
ios4
revolution-r
netmq
freelancer.com-api
jfugue
javax.sound.midi
cyclomatic-complexity
spidermonkey
deis
arcanist
angular-local-storage
unity5.2.3
sonarqube5.1.2
nsmutabledictionary
clicktag
nstableviewcell
codeigniter-url
network-interface
angularjs-ng-click
cdt
socketexception
ceil
aapt
contenttype
funcunit
transcoding
didselectrowatindexpath
fmod
terminal-services
dexterity
ora-00911
buster.js
rabl
plasma
ember-app-kit
browser-detection
dmoz
gdata-api
venn-diagram
automount
jspinclude
postgresql-performance
libc++
subgurim-maps
tomcat-valve
compiler-specific
substrings
eqatec
xetex

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