title: Dealing with HttpResponse in unit tests
body: <p>I have a simple website that has one page. The function I am unit testing is</p>
  
  <pre><code>public void WriteFileToClient(string fileContent, string fileName)
          {
              StringWriter stringWriter = new StringWriter();
              stringWriter.Write(fileContent);
              Response.ContentType = "text/plain";
              Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.txt", fileName));
              Response.Clear();
  
              using (StreamWriter writer = new StreamWriter(Response.OutputStream, Encoding.UTF8))
              {
                  writer.Write(stringWriter.ToString());
              }
              Response.End();
          }
  </code></pre>
  
  <p>When I run my test it says that <code>Response</code> is not available <img src="https://i.stack.imgur.com/a7egL.png" alt="enter image description here"></p>
  
  <p>Here is my Unit test</p>
  
  <pre><code>[TestMethod]
          [TestCategory("Unit")]
          public void WriteFileToClient_ShouldSucceedForCorrectInput()
          {
              //Arrange
              Migrate migrate = new Migrate();
              Guid g = Guid.Parse("fffe49c1-a838-46bc-b5c6-4e0bbd3e4c32");
  
              string fileContent = migrate.GenerateFlatFileText(g);
              string fileName = string.Format("flat file - {0}.txt", g);
  
              //Ask
              migrate.WriteFileToClient(fileContent, fileName);
  
              //Assert
              migrate.Response.OutputStream.Should().NotBeNull();
              migrate.Response.ContentType.Should().Be("text/plain");
              migrate.Response.Headers.Should().HaveCount(1);
          }
  </code></pre>
  
  <p>Any suggestions on how to mock the response? honestly I don't understand why the <code>Response</code> object is not available, my <code>Migrate</code> class inherits <code>Page</code> and to my understanding should has the <code>Response</code> included</p>