title: How to instantiate an instance of FormFile in C# without Moq?
body: <p>I want to test a function that attaches files to documents in a RavenDB database with an integration test. For this, I need an instance of <code>IFormFile</code>.</p>
  
  <p>Obviously, I can't instantiate from an interface so I tried to instantiate an instance of <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.internal.formfile?view=aspnetcore-2.1" rel="noreferrer"><code>FormFile</code></a> which inherits from the <code>IFormFile</code> interface.</p>
  
  <pre><code>using (var stream = File.OpenRead("placeholder.pdf"))
  {
      var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name))
      {
          ContentType = "application.pdf"
      };
  }
  </code></pre>
  
  <p>But this throws the following error:</p>
  
  <pre><code>System.NullReferenceException: Object reference not set to an instance of an object.
     at Microsoft.AspNetCore.Http.Internal.FormFile.set_ContentType(String value)
  </code></pre>
  
  <p>When I remove the <code>ContentType = "application.pdf"</code> from the code it allows me to instantiate a new instance but without a <code>ContentType</code>. </p>
  
  <p>How do I instantiate an instance of <code>FormFile</code> with the <code>ContentType</code> and without the <code>Moq</code> framework?</p>