Skip to content

Instantly share code, notes, and snippets.

@MikeMKH
Last active March 25, 2024 08:33
Show Gist options
  • Save MikeMKH/b16352ebcafb4f480f5b to your computer and use it in GitHub Desktop.
Save MikeMKH/b16352ebcafb4f480f5b to your computer and use it in GitHub Desktop.
How to live with a circular reference with AutoFixture
[TestInitialize]
public void BeforeEach()
{
_fixture = new Fixture();
// client has a circular reference from AutoFixture point of view
_fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
_fixture.Behaviors.Add(new OmitOnRecursionBehavior());
}
@holbizmetrics
Copy link

holbizmetrics commented Mar 25, 2024

What sometimes also might help is to use:

_fixture = new Fixture();
// client has a circular reference from AutoFixture point of view
_fixture.OmitAutoProperties = true;

P.S.: In case of some properties causing the problem, especially if they may not be needed to initialize the object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment