Hi Sudhir,
This is an interesting question. The case is an external dependency in the ILocalisation dictionary, which is provided by MEF, rather than by a standard function call or constructor. When testing the factory method we would of course like to isolate this dependency in MEF. I would try to fake the getter of the LocalisationMainService property to return a dictionary with test data, instead of trusting MEF to return it. Something like:
// create test data according to what you would like to test
var localisation1 = ...
var localisation2 = ...
// create the object under test. Because we are testing an instance method on a factory class, you can inject the object under test using Swap.NextInstance:
var factoryUnderTest = new LocalisationProviderFactory();
Isolate.Swap.NextInstance<LocalisationProviderFactory>().With(factoryUnderTest);
// return the test data instead of the MEF import
Isolate.WhenCalled(() => factoryUnderTest.LocalisationMainService).WillReturn(new[] {localisation1, localisation2});
// call the method under test
LocalisationProviderFactory.GetLocalisationService("MyType");
// assert results according to test data/requirements
Hope this helps!
Doron
Typemock Support