Question: I have a a class called "ViewFactory" and this class should deliver the right view

right now it has only one method (and it will grow) which I want to write a unit test against.

the class looks like this...

```
  public class ViewFactory
{

       [ImportMany(AllowRecomposition=true)]
    IEnumerable<ExportFactory<DependencyObject, IViewMetaData>> Views { get; set; }

    public DependencyObject GetViewByName(string name)
    {
        DependencyObject view = null;

        try
        {
            view = Views.Where(v => v.Metadata.ViewName == name).FirstOrDefault().CreateExport().Value;
            return view;
        }
        catch (Exception ex)
        {

            return view;
        }
    }
}

```

what I do want is to test my method but don't know how to do it because the List of Views is composed on runtime...

I want to test if I get a view for a valid name
and 
I also want to test if I get null if I have an invalid name

What would be the right way?

Answer: 
You would provide your `ViewFactory` with a set of `ExportFactory<,>` values suitable for the particular test. Different tests might have different sets, to allow you to test different things. Basically you're faking the injected dependency.
Here's the code (for Silverlight)

```
var viewFactory = new ViewFactory();

// Satisfy the imports manually (No MEF in unit tests!)
var factories = new List<ExportFactory<DependencyObject, IViewMetaData>>();
var tuple = new Tuple<DependencyObject, Action>(new MyObject(), () => { });
var metaData = new MyViewMetaData();
var factory = new ExportFactory<DependencyObject, IViewMetaData>(() => tuple, metaData);
factories.Add(factory);
viewFactory.Views = factories;

```