[InheritedExport(typeof(MyAbstractClass))
public abstract class MyAbstractClass
{
[Import] protected IFoo Foo { get; private set; }
}
public sealed class MyClass : MyAbstractClass
{
public void DoSomething()
{
if (Foo == null) throw new Exception();
var = Foo.GetBar();
//etc.
}
}
Basically, I use MEF to export classes out and get “common” imports. When I want to test these classes I can create mock interfaces of IFoo, but how do I actually get it in there with the private setter? MEF somehow is able to handle it, and I’m not sure how else I can test my DoSomething method.
I believe you can accomplish this with the MS Moles framework:
http://research.microsoft.com/en-us/projects/moles/