title: Unit testing a file reading function
body: <p>The code I currently have is as follows:</p>
  
  <pre><code>public class SerializeFileHandler
  {
      public void WriteListToFile(MyProject myProject, string filePath)
      {
          FileStream outFile;
          BinaryFormatter bFormatter = new BinaryFormatter();
  
          outFile = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  
          bFormatter.Serialize(outFile, myProject);
  
          // Close file
          outFile.Close();
      }
  
      public MyProject ReadListFromFile(String filePath)
      {
          FileStream inFile;
          BinaryFormatter bFormatter = new BinaryFormatter(); 
          MyProject myProject = new MyProject();
  
          // Open file for input
          inFile = new FileStream(filePath, FileMode.Open, FileAccess.Read);
  
          // Obtain objects from file via serialization
          myProject = (MyProject)bFormatter.Deserialize(inFile);
  
          inFile.Close();
          return myProject;
       }
  }
  </code></pre>
  
  <p>To save the data file I use <code>public const string myProjectFile = "myproject.dat";</code> and then to save any new data to the file when the user clicks the Save button I do <code>serializeFileHandler.WriteListToFile();</code> with parameters in the parentheses of course.</p>
  
  <p>What I want to do is write a unit test or multiple tests if needed to test the functionality in terms of reading the data file into the application. Currently the data file is automatically loaded in when the program loads (Just does a <code>ReadListFromFile</code> on the <code>serializeFileHandler</code>. </p>
  
  <p>I have created the test using the test wizard within Visual Studio but I am not sure how I'd construct the test to automate the testing of the file reading functionality. Any help would be appreciated.</p>