<commit_before>---
layout: post
tags: [AutoFixture]
date: 2011-04-18 13:22:29 UTC
title: "Enumerables are dynamic - also in AutoFixture"
---
{% include JB/setup %}

<div id="post">
	<p>I just got a question about <a href="http://autofixture.codeplex.com/">AutoFixture</a>'s way of dealing with enumerables, and since I suspect this is something that might surprise a few people I found it reasonable to answer in a blog post.</p> <p>In short, this unit test <em>succeeds:</em></p> <div style="font-family: ; background: white; color: "><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> fixture = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">Fixture</font></span>();</font></pre><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> expected = fixture.CreateMany&lt;<span style="color: "><font color="#0000ff">string</font></span>&gt;();</font></pre><pre style="margin: 0px"><span style="color: "><font color="#2b91af"><font style="font-size: 10pt">Assert</font></font></span><font style="font-size: 10pt">.False(expected.SequenceEqual(expected));</font></pre></div>
<p>If this doesn't surprise you, then read the assertion again. The sequence is expected to <em>not</em> equal itself!</p>
<p><em>This behavior is by design.</em></p>
<p>(I've always wanted to write that.) The reason is that the return type of the CreateMany method is IEnumerable&lt;T&gt;, and that interface makes no guarantee that it will return the same sequence every time you iterate over it. The implementation may be a <a href="http://en.wikipedia.org/wiki/Generator_%28computer_science%29">Generator</a>.</p>
<p>According to its principle of <a href="http://blog.ploeh.dk/2009/03/05/ConstrainedNonDeterminism.aspx">Constrained Non-determinism</a>, AutoFixture goes to great lengths to ensure that since IEnumerable&lt;T&gt; <em>might be</em> non-deterministic, it will be. This can be very useful in flushing out incorrect assumptions made by the <a href="http://xunitpatterns.com/SUT.html">SUT</a>.</p>
<p align="left">This behavior is carried forward by the <a href="http://blog.ploeh.dk/2011/02/08/CreatingGeneralPopulatedListsWithAutoFixture.aspx">MultipleCustomization</a>. This unit test also succeeds:</p>
<div style="font-family: ; background: white; color: "><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> fixture = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">Fixture</font></span>()</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; .Customize(<span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">MultipleCustomization</font></span>());</font></pre><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> expected =</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; fixture.CreateAnonymous&lt;<span style="color: "><font color="#2b91af">IEnumerable</font></span>&lt;<span style="color: "><font color="#0000ff">string</font></span>&gt;&gt;();</font></pre><pre style="margin: 0px"><span style="color: "><font color="#2b91af"><font style="font-size: 10pt">Assert</font></font></span><font style="font-size: 10pt">.False(expected.SequenceEqual(expected));</font></pre></div>
<p>The behavior is the same because with the MultipleCustomization IEnumerable&lt;T&gt; acts as a <a href="http://nblumhardt.com/2010/01/the-relationship-zoo/">relationship type</a>. The class responsible for this behavior is called FiniteSequenceRelay, but AutoFixture 2.1 will also ship with an alternative StableFiniteSequenceRelay which wraps the sequence in a List&lt;T&gt;.</p>
<p>To change the default behavior you can add the StableFiniteSequenceRelay to a Fixture's customizations:</p>
<div style="font-family: ; background: white; color: "><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> fixture = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">Fixture</font></span>();</font></pre><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> stableRelay = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">StableFiniteSequenceRelay</font></span>();</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">fixture.Customizations.Add(stableRelay);</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;</font></pre><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> expected =</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; fixture.CreateMany&lt;<span style="color: "><font color="#0000ff">string</font></span>&gt;();</font></pre><pre style="margin: 0px"><span style="color: "><font color="#2b91af"><font style="font-size: 10pt">Assert</font></font></span><font style="font-size: 10pt">.True(expected.SequenceEqual(expected));</font></pre></div>
<p>The above unit test succeeds. Notice that the assertion now verifies that the sequence of strings is equal to itself.</p>
<blockquote>
<p>Just like MultipleCustomization the StableFiniteSequenceRelay class will be available in AutoFixture 2.1, but is not availale in 2.0.</p></blockquote>
<p>As always, it's best to <a href="http://blog.ploeh.dk/2011/03/18/EncapsulatingAutoFixtureCustomizations.aspx">encapsulate this behavior change into a Customization</a>:</p>
<div style="font-family: ; background: white; color: "><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">public</font></font></span><font style="font-size: 10pt"> <span style="color: "><font color="#0000ff">class</font></span> <span style="color: "><font color="#2b91af">StableFiniteSequenceCustomization</font></span> :</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font><span style="color: "><font style="font-size: 10pt" color="#2b91af">ICustomization</font></span></pre><pre style="margin: 0px"><font style="font-size: 10pt">{</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; <span style="color: "><font color="#0000ff">public</font></span> <span style="color: "><font color="#0000ff">void</font></span> Customize(<span style="color: "><font color="#2b91af">IFixture</font></span> fixture)</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; {</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: "><font color="#0000ff">var</font></span> stableRelay = </font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">StableFiniteSequenceRelay</font></span>();</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fixture.Customizations.Add(stableRelay);</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; }</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">}</font></pre></div>
<p>This makes it easier to bundle it with the MultipleCustomization if we want all the other benefits of conventions for multiples:</p>
<div style="font-family: ; background: white; color: "><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">public</font></font></span><font style="font-size: 10pt"> <span style="color: "><font color="#0000ff">class</font></span> <span style="color: "><font color="#2b91af">StableMultipeCustomization</font></span> : </font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font><span style="color: "><font style="font-size: 10pt" color="#2b91af">CompositeCustomization</font></span></pre><pre style="margin: 0px"><font style="font-size: 10pt">{</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; <span style="color: "><font color="#0000ff">public</font></span> StableMultipeCustomization()</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : <span style="color: "><font color="#0000ff">base</font></span>(</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">StableFiniteSequenceCustomization</font></span>(),</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">MultipleCustomization</font></span>())</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; {</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; }</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">}</font></pre></div>
<p>With the StableMultipleCustomization the following unit test now passes:</p>
<div style="font-family: ; background: white; color: "><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> fixture = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">Fixture</font></span>()</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; .Customize(<span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">StableMultipeCustomization</font></span>());</font></pre><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> expected =</font></pre><pre style="margin: 0px"><font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; fixture.CreateAnonymous&lt;<span style="color: "><font color="#2b91af">IEnumerable</font></span>&lt;<span style="color: "><font color="#0000ff">string</font></span>&gt;&gt;();</font></pre><pre style="margin: 0px"><span style="color: "><font color="#2b91af"><font style="font-size: 10pt">Assert</font></font></span><font style="font-size: 10pt">.True(expected.SequenceEqual(expected));</font></pre></div>
<p>I still prefer the default behavior for its potential to act as an early warning system, but as I realize that this behavior may be problematic in some scenarios, the StableFiniteSequenceRelay provides an easy way to change that behavior.</p>
<p><strong>Update (2011.8.10):</strong> StableFiniteSequenceCustomization is now part of AutoFixture and will be available in AutoFixture 2.2.</p>
</div>
	
<div id="comments">
<hr>
<h2 id="comments-header">
	Comments
</h2>
	<div class="comment">
	<div class="comment-author">Gleb</div>
	<div class="comment-content">hello Mark, first of all thanks for a great library! I've been looking for something like AutoFixture.<br>
Can you please clarify, what do I need to do to make following scenario work:<br>
I have two classes, Stock and StockMarket, which are in many2many relationship (each has collection of other one). I want to use AutoFixture with Fluent NHibernate persistence specification for tests, but exception tells me: Ploeh.AutoFixture.ObjectCreationException: AutoFixture was unable to create an instance of type System.RuntimeType because the traversed object graph contains a circular reference</div>
	<div class="comment-date">2012-02-27 18:18 UTC</div>
</div><div class="comment">
	<div class="comment-author"><a href="http://blog.ploeh.dk/"><NAME></a></div>
	<div class="comment-content">Circular references are, IMO, a design smell, but since you are attempting to work with relational data, I guess you can't change the design.<br>
<br>
The easiest way to get around an issue like that is to customize the types to not fill in the properties in question. Something like this:<br>
<br>
fixture.Customize&lt;Stock&gt;(c =&gt; c.Without(s =&gt; s.StockMarket));<br>
<br>
fixture.Customize&lt;StockMarket&gt;(c =&gt; c.Without(sm =&gt; sm.Stock));</div>
	<div class="comment-date">2012-02-27 19:15 UTC</div>
</div><div class="comment"><commit_msg>Removed redundant (and ugly) pre tags from a post.<commit_after>---
layout: post
tags: [AutoFixture]
date: 2011-04-18 13:22:29 UTC
title: "Enumerables are dynamic - also in AutoFixture"
---
{% include JB/setup %}

<div id="post">
	<p>I just got a question about <a href="http://autofixture.codeplex.com/">AutoFixture</a>'s way of dealing with enumerables, and since I suspect this is something that might surprise a few people I found it reasonable to answer in a blog post.</p> <p>In short, this unit test <em>succeeds:</em></p> <div style="font-family: ; background: white; color: "><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> fixture = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">Fixture</font></span>();</font>
<span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> expected = fixture.CreateMany&lt;<span style="color: "><font color="#0000ff">string</font></span>&gt;();</font>
<span style="color: "><font color="#2b91af"><font style="font-size: 10pt">Assert</font></font></span><font style="font-size: 10pt">.False(expected.SequenceEqual(expected));</font></pre></div>
<p>If this doesn't surprise you, then read the assertion again. The sequence is expected to <em>not</em> equal itself!</p>
<p><em>This behavior is by design.</em></p>
<p>(I've always wanted to write that.) The reason is that the return type of the CreateMany method is IEnumerable&lt;T&gt;, and that interface makes no guarantee that it will return the same sequence every time you iterate over it. The implementation may be a <a href="http://en.wikipedia.org/wiki/Generator_%28computer_science%29">Generator</a>.</p>
<p>According to its principle of <a href="http://blog.ploeh.dk/2009/03/05/ConstrainedNonDeterminism.aspx">Constrained Non-determinism</a>, AutoFixture goes to great lengths to ensure that since IEnumerable&lt;T&gt; <em>might be</em> non-deterministic, it will be. This can be very useful in flushing out incorrect assumptions made by the <a href="http://xunitpatterns.com/SUT.html">SUT</a>.</p>
<p align="left">This behavior is carried forward by the <a href="http://blog.ploeh.dk/2011/02/08/CreatingGeneralPopulatedListsWithAutoFixture.aspx">MultipleCustomization</a>. This unit test also succeeds:</p>
<div style="font-family: ; background: white; color: "><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> fixture = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">Fixture</font></span>()</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; .Customize(<span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">MultipleCustomization</font></span>());</font>
<span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> expected =</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; fixture.CreateAnonymous&lt;<span style="color: "><font color="#2b91af">IEnumerable</font></span>&lt;<span style="color: "><font color="#0000ff">string</font></span>&gt;&gt;();</font>
<span style="color: "><font color="#2b91af"><font style="font-size: 10pt">Assert</font></font></span><font style="font-size: 10pt">.False(expected.SequenceEqual(expected));</font></pre></div>
<p>The behavior is the same because with the MultipleCustomization IEnumerable&lt;T&gt; acts as a <a href="http://nblumhardt.com/2010/01/the-relationship-zoo/">relationship type</a>. The class responsible for this behavior is called FiniteSequenceRelay, but AutoFixture 2.1 will also ship with an alternative StableFiniteSequenceRelay which wraps the sequence in a List&lt;T&gt;.</p>
<p>To change the default behavior you can add the StableFiniteSequenceRelay to a Fixture's customizations:</p>
<div style="font-family: ; background: white; color: "><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> fixture = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">Fixture</font></span>();</font>
<span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> stableRelay = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">StableFiniteSequenceRelay</font></span>();</font>
<font style="font-size: 10pt">fixture.Customizations.Add(stableRelay);</font>
<font style="font-size: 10pt">&nbsp;</font>
<span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> expected =</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; fixture.CreateMany&lt;<span style="color: "><font color="#0000ff">string</font></span>&gt;();</font>
<span style="color: "><font color="#2b91af"><font style="font-size: 10pt">Assert</font></font></span><font style="font-size: 10pt">.True(expected.SequenceEqual(expected));</font></pre></div>
<p>The above unit test succeeds. Notice that the assertion now verifies that the sequence of strings is equal to itself.</p>
<blockquote>
<p>Just like MultipleCustomization the StableFiniteSequenceRelay class will be available in AutoFixture 2.1, but is not availale in 2.0.</p></blockquote>
<p>As always, it's best to <a href="http://blog.ploeh.dk/2011/03/18/EncapsulatingAutoFixtureCustomizations.aspx">encapsulate this behavior change into a Customization</a>:</p>
<div style="font-family: ; background: white; color: "><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">public</font></font></span><font style="font-size: 10pt"> <span style="color: "><font color="#0000ff">class</font></span> <span style="color: "><font color="#2b91af">StableFiniteSequenceCustomization</font></span> :</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font><span style="color: "><font style="font-size: 10pt" color="#2b91af">ICustomization</font></span>
<font style="font-size: 10pt">{</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; <span style="color: "><font color="#0000ff">public</font></span> <span style="color: "><font color="#0000ff">void</font></span> Customize(<span style="color: "><font color="#2b91af">IFixture</font></span> fixture)</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; {</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: "><font color="#0000ff">var</font></span> stableRelay = </font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">StableFiniteSequenceRelay</font></span>();</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fixture.Customizations.Add(stableRelay);</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; }</font>
<font style="font-size: 10pt">}</font></pre></div>
<p>This makes it easier to bundle it with the MultipleCustomization if we want all the other benefits of conventions for multiples:</p>
<div style="font-family: ; background: white; color: "><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">public</font></font></span><font style="font-size: 10pt"> <span style="color: "><font color="#0000ff">class</font></span> <span style="color: "><font color="#2b91af">StableMultipeCustomization</font></span> : </font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; </font><span style="color: "><font style="font-size: 10pt" color="#2b91af">CompositeCustomization</font></span>
<font style="font-size: 10pt">{</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; <span style="color: "><font color="#0000ff">public</font></span> StableMultipeCustomization()</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : <span style="color: "><font color="#0000ff">base</font></span>(</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">StableFiniteSequenceCustomization</font></span>(),</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">MultipleCustomization</font></span>())</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; {</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; }</font>
<font style="font-size: 10pt">}</font></pre></div>
<p>With the StableMultipleCustomization the following unit test now passes:</p>
<div style="font-family: ; background: white; color: "><pre style="margin: 0px"><span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> fixture = <span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">Fixture</font></span>()</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; .Customize(<span style="color: "><font color="#0000ff">new</font></span> <span style="color: "><font color="#2b91af">StableMultipeCustomization</font></span>());</font>
<span style="color: "><font color="#0000ff"><font style="font-size: 10pt">var</font></font></span><font style="font-size: 10pt"> expected =</font>
<font style="font-size: 10pt">&nbsp;&nbsp;&nbsp; fixture.CreateAnonymous&lt;<span style="color: "><font color="#2b91af">IEnumerable</font></span>&lt;<span style="color: "><font color="#0000ff">string</font></span>&gt;&gt;();</font>
<span style="color: "><font color="#2b91af"><font style="font-size: 10pt">Assert</font></font></span><font style="font-size: 10pt">.True(expected.SequenceEqual(expected));</font></pre></div>
<p>I still prefer the default behavior for its potential to act as an early warning system, but as I realize that this behavior may be problematic in some scenarios, the StableFiniteSequenceRelay provides an easy way to change that behavior.</p>
<p><strong>Update (2011.8.10):</strong> StableFiniteSequenceCustomization is now part of AutoFixture and will be available in AutoFixture 2.2.</p>
</div>
	
<div id="comments">
<hr>
<h2 id="comments-header">
	Comments
</h2>
	<div class="comment">
	<div class="comment-author">Gleb</div>
	<div class="comment-content">hello Mark, first of all thanks for a great library! I've been looking for something like AutoFixture.<br>
Can you please clarify, what do I need to do to make following scenario work:<br>
I have two classes, Stock and StockMarket, which are in many2many relationship (each has collection of other one). I want to use AutoFixture with Fluent NHibernate persistence specification for tests, but exception tells me: Ploeh.AutoFixture.ObjectCreationException: AutoFixture was unable to create an instance of type System.RuntimeType because the traversed object graph contains a circular reference</div>
	<div class="comment-date">2012-02-27 18:18 UTC</div>
</div><div class="comment">
	<div class="comment-author"><a href="http://blog.ploeh.dk/"><NAME></a></div>
	<div class="comment-content">Circular references are, IMO, a design smell, but since you are attempting to work with relational data, I guess you can't change the design.<br>
<br>
The easiest way to get around an issue like that is to customize the types to not fill in the properties in question. Something like this:<br>
<br>
fixture.Customize&lt;Stock&gt;(c =&gt; c.Without(s =&gt; s.StockMarket));<br>
<br>
fixture.Customize&lt;StockMarket&gt;(c =&gt; c.Without(sm =&gt; sm.Stock));</div>
	<div class="comment-date">2012-02-27 19:15 UTC</div>
</div><div class="comment">
{'fraction_non_alphanumeric': 0.2100787152406946, 'fraction_numerical': 0.03306831217119576, 'mean_word_length': 7.7420470262793915, 'pattern_counts': {'":': 0, '<': 947, '<?xml version=': 0, '>': 947, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3107457', 'n_tokens_mistral': 8645, 'n_tokens_neox': 7888, 'n_words': 1977}