title: How to verify if a stream has been copied on a fileSystem
body: <p>I want to write a unit test that check a stream has been copied on the disk :</p>
  
  <p>The problem is CopyTo method is not virtual so I can't use </p>
  
  <pre><code>inputMemoryStreamMock.Verify(c =&gt; c.CopyTo(outputMemoryStreamMock.Object));
  </code></pre>
  
  <p>and I don't know how to mock a stream :-/</p>
  
  <p>here is my test method :</p>
  
  <pre><code>    [TestMethod]
      public void Save_Stream_On_DestinationPath()
      {
          // Arrange
          string fileName = "filename.pdf";
          DateTime date = new DateTime(2013, 9, 27);
  
          var serverConfigMock = new Mock&lt;IServerConfigurationManager&gt;();
          serverConfigMock.Setup(config =&gt; config.ReportingBasePath).Returns(@"c:\reportsFolder");
  
          var factoryReportFileResultMock = new Mock&lt;IReportFileResultFactory&gt;();
  
          var timeManagementMock = new Mock&lt;ITimeManagement&gt;();
          timeManagementMock.Setup(c =&gt; c.GetServerDate()).Returns(date);
  
          var fileSystemMock = new Mock&lt;IFileSystem&gt;();
          var fileInfoFactory = new Mock&lt;IFileInfoFactory&gt;();
          var directoryInfoBaseMock = new Mock&lt;DirectoryInfoBase&gt;();
          var inputMemoryStreamMock = new Mock&lt;Stream&gt;();
          var outputMemoryStreamMock = new Mock&lt;Stream&gt;();
  
          var reportFileHelper = new ReportFileHelper(serverConfigMock.Object, factoryReportFileResultMock.Object, fileSystemMock.Object);
  
  
          inputMemoryStreamMock.Setup(c =&gt; c.CanRead).Returns(true);
          outputMemoryStreamMock.Setup(c =&gt; c.CanWrite).Returns(true);
          outputMemoryStreamMock.Setup(c =&gt; c.CanWrite).Returns(true);
  
          fileSystemMock.Setup(c =&gt; c.FileInfo).Returns(fileInfoFactory.Object);
          fileSystemMock.Setup(c =&gt; c.File.Create(It.IsAny&lt;string&gt;())).Returns(outputMemoryStreamMock.Object);
          fileSystemMock.Setup(c =&gt; c.Directory.CreateDirectory(It.IsAny&lt;string&gt;())).Returns(directoryInfoBaseMock.Object);
          // Act  
          reportFileHelper.Save(inputMemoryStreamMock.Object, fileName, timeManagementMock.Object);
  
          // Assert
          inputMemoryStreamMock.Verify(c =&gt; c.CopyTo(outputMemoryStreamMock.Object));
  
      }
  </code></pre>
  
  <p>And here is the method to test :</p>
  
  <pre><code>    public void Save(Stream portfolioReportFileInfoBase,  string destinationName, ITimeManagement timeManagement)
      {
          string destinationPath = GetDestinationPath(timeManagement);
          string destinationFileUri = Path.Combine(destinationPath, destinationName);
  
          FileSystem.Directory.CreateDirectory(destinationPath);
  
          using (var fileStream = FileSystem.File.Create(destinationFileUri))
          {
              portfolioReportFileInfoBase.CopyTo(fileStream);
          }
      }
  </code></pre>
  
  <p>Thank you </p>