title: C# SystemWrapper mock File.ReadAllLines
body: <p>In a method I would usually do something like this:</p>
  
  <pre><code>string[] lines = File.ReadAllLines(filename);
  </code></pre>
  
  <p>To test, I'd like to be able to mock out the file system, and I have heard positive comments about <a href="https://systemwrapper.codeplex.com/" rel="nofollow">SystemWrapper</a>, so I'd like to use this library.</p>
  
  <p>As I understand, using SystemWrapper requires that I do interface based calling. That's fine. So my above line of code becomes:</p>
  
  <pre><code>string[] lines = new FileWrap().ReadAllLines(filename);
  </code></pre>
  
  <p>Now, my test method looks like this: (I am using  Microsoft.VisualStudio.TestTools.UnitTesting in conjunction with Rhino Mock)</p>
  
  <pre><code>[TestMethod()]
  public void Test_this_method()
  {
      IFileWrap fileWrapRepository = MockRepository.GenerateMock&lt;IFileWrap&gt;();
      fileWrapRepository.expect(x =&gt; x.ReadAllLines("abc.txt").Return(new string[] {"Line 1", "Line 2", "Line 3"});
  
      MethodThatReadsLines();
  }
  </code></pre>
  
  <p>This example is adapted from an example on SystemWrapper's <em>Getting Started</em> page.</p>
  
  <p>However, when I do this, the method is not calling my mocked method, it is calling <code>File.ReadAllLines</code>, which is not what I am expecting.</p>
  
  <p>What is the correct way to mock <code>File.ReadAllLines</code>?</p>