AutoBogus icon indicating copy to clipboard operation
AutoBogus copied to clipboard

Record with nested children of the same type as the parent causes StackOverflow

Open nour-s opened this issue 1 year ago • 2 comments

It seems that the recursive depth safe mechanism doesn't work on records. Generating an instance of this record as follows

public record FakeChild (string Name, List<FakeChild>? C);

var child = new AutoFaker<FakeChild>().Configure(x => x.WithTreeDepth(1).WithRecursiveDepth(1)).Generate();

will cause a StackOverflow exception.

The only way around this is to move the Children property to the Record body as follows:

public record FakeChild (string Name)
{
    List<FakeChild> Children { get; set; }
}

While that works, it defies the purpose of using a Record instead of a Class.

nour-s avatar Aug 16 '22 14:08 nour-s

I'm sure you have moved past this, but I will fix this in soenneker.utils.autobogus shortly

soenneker avatar Feb 20 '24 04:02 soenneker

soenneker.utils.autobogus now supports classes and records with parameters of the same declaring type.

soenneker avatar Feb 23 '24 15:02 soenneker