title: How can I unit test the modification of an XML file which recursively points to other XML files?
body: <p>I am attempting to unit test the modification of an XML structure like:</p>
  
  <pre><code>&lt;element1&gt;
      &lt;open file="otherfile.xml"&gt;
  &lt;/element1&gt;
  </code></pre>
  
  <p>Suppose that <code>otherfile.xml</code> contains:</p>
  
  <pre><code>&lt;element2&gt;
      &lt;open file="anotherfile.xml"&gt;
      &lt;happytag/&gt;
  &lt;/element2&gt;
  </code></pre>
  
  <p>And that <code>anotherfile.xml</code> looks like:</p>
  
  <pre><code>&lt;element3&gt;
      &lt;sadtag/&gt;
  &lt;/element3&gt;
  </code></pre>
  
  <p>The correct modification copies and pastes code from the file to be opened into the code that called the <code>open</code> tag.  Therefore, I am expecting a structure like:</p>
  
  <pre><code>&lt;element1&gt;
      &lt;element2&gt;
          &lt;element3&gt;
              &lt;sadtag/&gt;
          &lt;/element3&gt;
          &lt;happytag/&gt;
      &lt;/element2&gt;
  &lt;/element1&gt;
  </code></pre>
  
  <p>The problem I am having is that I am unsure how to go about unit testing the creation of this structure.  Ideally, and what I have tried to far (unsuccessfully), is to create this unit test so that I do not need to make any calls to the file system in order to create the structure.  To do that, I create a mock object which pretends to be an input stream which opens a file, but is really just returning a stream created from the text of</p>
  
  <pre><code>&lt;element1&gt;
      &lt;open file="otherfile.xml"&gt;
  &lt;/element1&gt; 
  </code></pre>
  
  <p>The problem I have in this approach is that I cannot figure out a way to inject the text of <code>otherfile.xml</code> so that a mock object will return the text of:</p>
  
  <pre><code>&lt;element2&gt;
      &lt;open file="anotherfile.xml"&gt;
      &lt;happytag/&gt;
  &lt;/element2&gt;
  </code></pre>
  
  <p>Another thing I've tried is to put the text of <code>anotherfile.xml</code> into <code>open file=""</code>, like <code>open file="&amp;lt;element3&amp;gt;...&amp;lt;/element3&amp;gt;"&gt;</code>.  This doesn't work because the XML parser complains that it isn't valid XML.</p>
  
  <p>I could also create these xml files from strings before I run the test and then delete them after the test.</p>