title: unit test dynamic loading code
body: <p>I was reading and found this code as an aswer to a question</p>
  
  <pre><code>public List&lt;T&gt; LoadPlugin&lt;T&gt;(string directory)
  {
      Type interfaceType = typeof(T);
      List&lt;T&gt; implementations = new List&lt;T&gt;();
  
      //TODO: perform checks to ensure type is valid
  
      foreach (var file in System.IO.Directory.GetFiles(directory))
      {
          //TODO: add proper file handling here and limit files to check
          //try/catch added in place of ensure files are not .dll
          try
          {
              foreach (var type in System.Reflection.Assembly.LoadFile(file).GetTypes())
              {
                  if (interfaceType.IsAssignableFrom(type) &amp;&amp; interfaceType != type)
                  { 
                      //found class that implements interface
                      //TODO: perform additional checks to ensure any
                      //requirements not specified in interface
                      //ex: ensure type is a class, check for default constructor, etc
                      T instance = (T)Activator.CreateInstance(type);
                      implementations.Add(instance);
                  }
              }
          }
          catch { }
      }
  
      return implementations;
  }
  </code></pre>
  
  <p>and it got me wondering what the best way to unit test this code would be?</p>