AutoBogus icon indicating copy to clipboard operation
AutoBogus copied to clipboard

Recursive depth limit not implemented when generating constructor parameters

Open SpaceMonkeyy86 opened this issue 3 years ago • 1 comments

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
    }
}

SpaceMonkeyy86 avatar Sep 13 '22 22:09 SpaceMonkeyy86

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

soenneker avatar Apr 29 '24 20:04 soenneker