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
ionic-framework
hive
c#-4.0
layout
hp-exstream
hashmap
razor
amazon-ecs
ckeditor
baqend
directx
user-input
kentor-authservices
modx-revolution
postgres-xl
percona
openrefine
highlight.js
transformation
custom-wordpress-pages
xlsxwriter
mmap
restful-authentication
android-widget
sparse-matrix
filezilla
xacml
compatibility
quote
google-cloud-nl
gsmcomm
unboundid
ecto
language-concepts
fusionpbx
appfabric
swisscomdev
hot-module-replacement
elasticsearch-plugin
android-tabhost
glew
ibpy
avconv
rainbowtable
xml-documentation
multipeer-connectivity
ionicons
idisposable
font-size
qtwebview
watchconnectivity
word-vba-mac
xcb
heidisql
merge-conflict-resolution
nsviewcontroller
actionbardrawertoggle
packagist
design-by-contract
xpath-1.0
google-places
qdialog
ionic
ami
geonetwork
xceed-datagrid
mechanize-ruby
flexmojos
dir
listings
tws
ril
rabl
comaddin
jelly
specification-pattern
gnu-prolog
window-management
doh
calling-convention
sudzc
asp.net-mvc-areas
gamma
nsviewanimation
firefox4
nintendo-ds
swing-app-framework
temporal-database
msdev

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