nickdodd79 / AutoBogus

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

Recursive depth limit not implemented when generating constructor parameters #91

Open SpaceMonkeyy86 opened 1 year ago

SpaceMonkeyy86 commented 1 year ago

No checks are in place for skipping the generation of reference types for a constructor. This will lead to a StackOverflowException if a reference type's constructor has itself as one of the parameters, even if that parameter is optional:

public class Node
{
    public string Data { get; set; }
    public Node Parent { get; set; }

    public Node(string data, Node parent = null)
    {
        Data = data;
        Parent = parent;
    }

    public static void Test()
    {
        var foo = AutoFaker.Generate<Node>(); // This will result in a StackOverflowException
    }
}
soenneker commented 2 months ago

@SpaceMonkeyy86 Recursive constructors are working and follow depth limits in soenneker.utils.autobogus