title: Using reflection to set an interface member
body: <p>I'm having trouble setting the value of a property in a class when the property type is and interface using PropertyInfo.SetValue.
  This code is for unit testing which I'd like to use to fake out the IDbSets in my Entity.</p>
  
  <pre><code>public static void AddFakeDbSets&lt;T&gt;(this Mock&lt;T&gt; obj) where T : class
  {
      var iDbSets = typeof(T).GetProperties().Where(p =&gt; 
          p.PropertyType.IsGenericType == true &amp;&amp;
          p.PropertyType.GetGenericTypeDefinition().Name.StartsWith("IDbSet"));
  
      Type baseType = typeof(FakeDbSet&lt;&gt;);
  
      foreach (var iDbSet in iDbSets)
      {
          if (iDbSet.GetValue(obj.Object) == null)
          {
              var genericType = baseType.MakeGenericType(iDbSet.PropertyType);
              var concreteObject = Activator.CreateInstance(genericType);
              iDbSet.SetValue(obj.Object, concreteObject);
          }
      }
  }
  </code></pre>
  
  <p>Specifically it crashes at iDbSet.SetValue() with the following error:</p>
  
  <blockquote>
    <p>Object of type
    'lnEcommAPI.Tests.FakeDbSet<code>1[System.Data.Entity.IDbSet</code>1[LNWebServicesRepository.WhatsNew]]'
    cannot be converted to type
    'System.Data.Entity.IDbSet`1[LNWebServicesRepository.WhatsNew]'.</p>
  </blockquote>