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