title: How to unit test methods that construct a string?
body: <p>I have a method which constructs a string from <code>List</code>. I want to test the method with a unit test. What's a good way to test that method?</p>
  
  <p>I need to use the database to get matchList. I don't know how to use a mock object to do that.</p>
  
  <pre><code>public class File_IO
  {
      private string _rootDirectory;
      private string _taskName;
  
      private File_IO()
      {
  
      }
  
      public File_IO(string rootDirectory, string taskName)
      {
          _rootDirectory = rootDirectory;
          _taskName = taskName;
  
      }
  
      public string RootDir
      {
          get { return _rootDirectory; }
      }
  
      public string TaskName
      {
          get { return _taskName; }
      }
  
      public string constructString()
      {
          string result = string.Empty;
          string pipe = "|";
          StringBuilder stringBuilder = new StringBuilder();
          bool isFirst = true;
  
          IList matchList = new List&lt;string&gt; { "*.Ext","*.ext" };
  
          // Iterate over the results and construct the string.
          foreach (var item in matchList)
          {
              if (!isFirst)
              {
                  stringBuilder.Append(pipe);
              }
  
              isFirst = false;
              stringBuilder.Append(item);
          }
  
          result = stringBuilder.ToString();
          return result;
      }
  
  }
  </code></pre>