Skip to content

Instantly share code, notes, and snippets.

@phillip-haydon
Created March 27, 2015 07:50
Show Gist options
  • Save phillip-haydon/7dfa736ba70bfb34297e to your computer and use it in GitHub Desktop.
Save phillip-haydon/7dfa736ba70bfb34297e to your computer and use it in GitHub Desktop.
Autofixture Base Types and Recursion.
[TestFixture]
public class TestStuffs
{
[Test, Category(TestCategories.Unit)]
public void Fail()
{
var fixture = new Fixture().Customize(new TestCustomization());
var result = fixture.Create<TestClass>();
}
public abstract class TestClassBase
{
public IList<Node> Nodes { get; set; }
}
public class TestClass : TestClassBase
{
}
public class Node
{
public TestClassBase Parent { get; set; }
}
public class TestCustomization : ICustomization
{
public void Customize(IFixture fixture)
{
fixture.Customizations.Add(new TypeRelay(typeof(TestClassBase), typeof(TestClass)));
//How to prevent recursion???
//fixture.Customize<TestClass>(x => x.With(f => f.Nodes, fixture.Build<Node>(n => n.Without(u => u.Parent))));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment