How to create and pass a lazy<T,Tmetadata> for unit testing?-Collection of common programming errors
Hello all,
So i decided to create a repository for my MEF project, this would allow me to swap out the source for my given situation (runtime, testing, etc…) However, I’ve noticed and I understand that most use lazy loading for the MEF importmany plugin property/field. My issue is attempting to build a repository that returns test plugin classes, but of course i’m having problems instantiating the lazy property in the test repository. Thoughts?
public List GetAllPlugins()
{
_testPluginList.Add(new Lazy
(
() =>
{
IPluginContract testPluginOne = new TestPluginContract();
return testPluginOne;
}
)
);
_testPluginList.Add(new Lazy
(
() =>
{
IPluginContract testPluginTwo = new TestPluginContract();
return testPluginTwo;
}
)
);
return _testPluginList;
}
Thoughts anyone?
I get the following error when attempting to build:
“Cannot convert anonymous method to type ‘System.Collections.Generic.IDictionary’ because it is not a delegate type” ; that is on both list.Add methods.
May the Force be with you young Jedi…
Console.WriteLine("-Warren");
Please Help your Helper(s) =)
If you find someone’s post helpful please click the green “up arrow” to the left and vote!
Did someone’s post Answer your question? Mark it as the Answer!
It’s Greatly Appreciated =)