AutoBogus icon indicating copy to clipboard operation
AutoBogus copied to clipboard

[Bug] recursive constructor parameter gives `StackOverflowException`

Open 304NotModified opened this issue 2 years ago • 2 comments

given:

[Fact]
public void AutoFakerTest()
{
    // Arrange
    var faker = new AutoFaker<MyResult>().Configure(c => c
        .WithRecursiveDepth(1)
        .WithTreeDepth(1));

    // Act
    var result = faker.Generate();

    // Assert
    result.Should().NotBeNull();
}

public class MyResult
{
    public MyResult(IEnumerable<MyResult> innerResults)
    {
        InnerResults = innerResults;
    }

    public IEnumerable<MyResult> InnerResults { get; }
}
  • expected: green test
  • current: StackOverflowException!

Version:

  • AutoBugs 2.13.1
  • Bogus: 33.1.1

Unfortunately I don't get a stacktrace :'( (Also not when debugging)

304NotModified avatar Dec 02 '21 19:12 304NotModified

Hey @304NotModified

Thanks for your message and apologies for the delayed response. Working on several projects that are taking up 100% of my time at the moment.

I think you raise an interesting use case. We have checks in AutoBogus that will compares the current type to its parent and stop the recursion going past a certain depth. However, I don't think that check is performed on the generic type of a collection.

I will do some investigations and get a fix in place.

Nick.

nickdodd79 avatar Jan 19 '22 20:01 nickdodd79

@304NotModified Constructors with enumerable recursion is now tested and working in soenneker.utils.autobogus

soenneker avatar Apr 29 '24 20:04 soenneker