nickdodd79 / AutoBogus

A C# library complementing the Bogus generator by adding auto creation and population capabilities.
MIT License
423 stars 49 forks source link

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

Open nour-s opened 1 year ago

nour-s commented 1 year ago

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.

soenneker commented 5 months ago

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

soenneker commented 4 months ago

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