nickdodd79 / AutoBogus

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

[Bug] recursive constructor parameter gives `StackOverflowException` #78

Open 304NotModified opened 2 years ago

304NotModified commented 2 years ago

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

Version:

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

nickdodd79 commented 2 years ago

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.

soenneker commented 2 months ago

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