Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

How to create and pass a lazy for unit testing?

$
0
0

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<t,tmetadata> property in the test repository. Thoughts?

public List<Lazy<IPluginContract, IDictionary<string, object>>> GetAllPlugins()
        {
            _testPluginList.Add(new Lazy<IPluginContract, IDictionary<string, object>>
                (
                    () =>
                    {
                        IPluginContract testPluginOne = new TestPluginContract();
                        return testPluginOne;
                    }
               )
            );
            _testPluginList.Add(new Lazy<IPluginContract, IDictionary<string, object>>
                (
                    () =>
                    {
                        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<string,object>' 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 =)


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>