title: AutoFixture IEnumerable<T> behavior with CreateMany()
body: <p>When looking at the post <a href="https://stackoverflow.com/questions/5398258/customizing-autofixture-builder-with-seeded-property">here</a>, it looks like I should be able to create several objects using <code>CreateMany()</code>, iterate over them using <code>foreach</code>, and then return them as an array.</p>
  
  <p>What I'm seeing is that each iteration seems to create new objects each time. Is this expected behavior?</p>
  
  <p><strong>Entity to create:</strong></p>
  
  <pre><code>public class TestEntity
  {
      public int Id { get; private set; }
      public string SomeString { get; set; }
      public void SetId(int value)
      {
          this.Id = value;
      }
  }
  </code></pre>
  
  <p><strong>Sample Program.cs:</strong></p>
  
  <pre><code>private static int id;
  
  static void Main(string[] args)
  {
      var fixture = new Fixture();
      IEnumerable&lt;TestEntity&gt; testEntities = 
        fixture.Build&lt;TestEntity&gt;().CreateMany(5);
  
      Output(testEntities);
  
      foreach (var testEntity in testEntities)
      {
          testEntity.SetId(id++);
          Console.WriteLine(
            string.Format("CHANGED IN FOREACH:: hash: {0}, id: {1}, string: {2}", 
            testEntity.GetHashCode(), testEntity.Id, testEntity.SomeString));
      }
  
      Output(testEntities);
  }
  
  private static void Output(IEnumerable&lt;TestEntity&gt; testEntities)
  {
      foreach (var testEntity in testEntities)
      {
          Console.WriteLine(
            string.Format("hash: {0}, id: {1}, string: {2}", 
            testEntity.GetHashCode(), testEntity.Id, testEntity.SomeString));
      }
  }
  </code></pre>
  
  <p>I created an issue <a href="http://autofixture.codeplex.com/workitem/4233" rel="nofollow noreferrer">here</a> (which can probably be deleted if this is expected behavior).</p>
  
  <p><strong>Edit 2011-06-02</strong></p>
  
  <p>To get the behavior I was expecting, and if I don't want to modify the AutoFixture behavior, I can use an extension method:</p>
  
  <pre><code>var fixture = new Fixture();
  TestEntity[] testEntities = fixture.Build&lt;TestEntity&gt;().CreateMany(5).ToArray();
  </code></pre>