title: How can I fake a DbSet<T> using FakeItEasy when the classes are internal?
body: <p>I'm using Entity Framework 6 and want to unit test some of my business logic code. Following Microsoft's example on how to do this, they provide the following example using <code>MOQ</code>:</p>
  
  <pre><code>var mockSet = new Mock&lt;DbSet&lt;Blog&gt;&gt;(); 
  
  var mockContext = new Mock&lt;BloggingContext&gt;(); 
  mockContext.Setup(m =&gt; m.Blogs).Returns(mockSet.Object); 
  
  var service = new BlogService(mockContext.Object); 
  </code></pre>
  
  <p>I'm using <code>FakeItEasy</code> instead of <code>MOQ</code>, and I'd hoped it would be just as simple, however <code>FakeItEasy</code> complains that it can't create a fake of my <code>DbSet</code> using the following:  </p>
  
  <pre><code>var fakeDbSet = A.Fake&lt;DbSet&lt;InstalledProduct&gt;&gt;();
  </code></pre>
  
  <p>I get an exception as follows:</p>
  
  <blockquote>
    <p>FakeItEasy.Core.FakeCreationException:    Failed to create fake of
    type "TN.Prs.Persistence.LicenseContext".</p>
    
    <p>Below is a list of reasons for failure per attempted constructor:
        No constructor arguments failed:
          No usable default constructor was found on the type TN.Prs.Persistence.LicenseContext.
          An exception was caught during this call. Its message was:
          Access is denied: 'TN.Prs.Persistence.LicenseContext'.</p>
    
    <p>at
    FakeItEasy.Core.DefaultExceptionThrower.ThrowFailedToGenerateProxyWithResolvedConstructors(Type
    typeOfFake, String reasonForFailureOfUnspecifiedConstructor,
    IEnumerable<code>1 resolvedConstructors)    at
    FakeItEasy.Creation.FakeObjectCreator.TryCreateFakeWithDummyArgumentsForConstructor(Type
    typeOfFake, FakeOptions fakeOptions, IDummyValueCreationSession
    session, String failReasonForDefaultConstructor, Boolean
    throwOnFailure)    at
    FakeItEasy.Creation.FakeObjectCreator.CreateFake(Type typeOfFake,
    FakeOptions fakeOptions, IDummyValueCreationSession session, Boolean
    throwOnFailure)    at
    FakeItEasy.Creation.DefaultFakeAndDummyManager.CreateFake(Type
    typeOfFake, FakeOptions options)    at
    FakeItEasy.Creation.DefaultFakeCreatorFacade.CreateFake[T](Action</code>1
    options)    at FakeItEasy.A.FakeT    at
    TN.Prs.RegistrationServices.Specifications.when_activating_a_product_from_a_valid_digitally_signed_activation_key.&lt;.ctor>b__0()
    in</p>
  </blockquote>
  
  <p>My POCO classes are <code>internal</code> rather than <code>public</code>, but I've added the <code>InternalsVisibleTo</code> attributes as appropriate, for <code>DynamicProxyGenAssembly2</code>. When I make the classes public, everything works, but I really don't want to expose these classes publicly. I would appreciate any suggestions.</p>
  
  <p>Here is my context class:</p>
  
  <pre><code>internal class LicenseContext : DbContext
  {
      public LicenseContext()
      {
  
      }
      public virtual DbSet&lt;InstalledProduct&gt; ManagedProducts { get; set; }
  }
  </code></pre>