views:

25

answers:

2

I was playing around with Microsoft Entity framework 4 and at some point i want to create a fake instance of ObjectStateEntry using a proxy or FormatterServices and faced with the issues that follow:

  1. The class has internal abstract members therefore creating a proxy ends up with type having not-implemented members. Therefore, throws exception during CreateInstance.
  2. Can't use FormatterServices.GetUinitializedData as it is an abstract class.

Would love to know, if are there any other option available ?

A: 

Here I wrote down my answer as soon as I saw your question title How create an instance of an abstract class, the answer is No, you can't create an instance of an abstract class.

Danny Chen
You can create the instance of abstract class through creating a proxy (like how any proxy tool does), but if you have internal members in that abstract class then you can't if you have no options for adding `InternalVisibleTo` attribute in the target library (you need source access to do so). I was looking, if you can create the instance of abstract class by any other means in that regard. Also, Danny thanks for your answer.
Mehfuz
A: 

Have you tried any mocking framework such as Rhino Mocks

VinayC
Thanks, Vinay i did tried Rhino Mocks, i was just curious to know and the above case is true for all tools Moq, Rhino, JustMock. I searching if there is any way out.
Mehfuz
Just googling around threw this link - http://www.dimecasts.net/Casts/CastDetails/20. You need to see if it throw something useful.Typically, its advisable to test against interface rather than classes, although I can see it does not apply out here.
VinayC
Yes, it is not it. I was looking for something with the exact issue.
Mehfuz