title: How to mock fake file size in bytes array in unit testing
body: <p>Here I have code which copies the document to specific loacation for that I have code which creates fake file as below.</p>
  
  <pre><code>private static Mock&lt;IFormFile&gt; GetMockFormFile()
  {
        var fileMock = new Mock&lt;IFormFile&gt;();
        var fileStreamProviderMock = new Mock&lt;IFileStreamProvider&gt;();
        var contentTypes = "text/plain";
        var content = "Fake File";
        var fileName = "Test.txt";
        var disk = new MemoryStream();
        var writers = new StreamWriter(disk);
        writers.Write(content);
        writers.Flush();
        disk.Position = 0;
        fileMock.Setup(_ =&gt; _.OpenReadStream()).Returns(disk);
        fileMock.Setup(_ =&gt; _.FileName).Returns(fileName);
        fileMock.Setup(_ =&gt; _.Length).Returns(disk.Length);
        fileMock.Setup(_ =&gt; _.ContentType).Returns(contentTypes);
        fileMock.Setup(_ =&gt; _.ContentDisposition).Returns($"form-data;name='file';filename ='{fileName}'");
        fileStreamProviderMock.Setup(_ =&gt; _.Create(It.IsAny&lt;string&gt;())).Returns(disk);
        fileStreamProviderMock.Setup(_ =&gt; _.Open(It.IsAny&lt;string&gt;())).Returns(disk);
        fileMock.Setup(_ =&gt; _.CopyToAsync(disk, It.IsAny&lt;CancellationToken&gt;())).Returns(Task.CompletedTask);
        fileMock.Verify();
        return fileMock;
  }
  </code></pre>
  
  <p>I am passing this fake file to controller like</p>
  
  <pre><code>[Fact]
  public async sample()
  {
      var formFile = GetMockFormFile();
      var file = formFile.Object;
      var SavedFile = new AttachmentMetadata
      {
          Id = 4231,
          DocumentName = file.FileName,
          DocumentType = file.ContentType,
          CreatedDateTime = dateTime,
          ModifiedDateTime = dateTime
      };
      var viewModel = new AttachmentViewModel()
      {
          File = new List&lt;IFormFile&gt; { file }
      };
  
      await controller.AddAttachment(viewModel);
      fileStreamProviderMock.Verify(_ =&gt; _.Create(@"C:\TestFolder\Test.txt"));
      formFile.Verify(_ =&gt; _.CopyToAsync(It.IsAny&lt;Stream&gt;(), It.IsAny&lt;CancellationToken&gt;()));
  }
  </code></pre>
  
  <p>and inside my controller i have some code as like</p>
  
  <pre><code>foreach (var file in model.File)
    {
      using (var ms = new MemoryStream())
         {
              file.CopyTo(ms);
              fileBytes = ms.ToArray();
         } 
    ----
    ----
  }
  </code></pre>
  
  <p>which should return the fileBytes something except 0, currently I am getting fileBytes as 0 which cause issues in further code execution.
  So is there any other way where I can mock this fake bytes size?</p>