How can I find out why AutoFixture throws a Kernel.OmitSpecimen exception

I am working on a pretty nested model that has some circular links. It also uses the Entity Framework, therefore all listings ICollection<T>. To do this, I configure AutoFixture as follows:

_fixture = new Fixture().Customize(new MultipleCustomization());
_fixture.Behaviors.Remove(new ThrowingRecursionBehavior());
_fixture.Behaviors.Add(new OmitOnRecursionBehavior());

When I try to create a type

_fixture.CreateAnonymous<Session>();

AutoFixture has a problem and throws the following error:

System.InvalidCastException: cannot throw an object of type "Ploeh.AutoFixture.Kernel.OmitSpecimen" to enter "The.Model.Language"

If I exclude a collection in a Sessiontype Language, AutoFixture throws the same exception for another type in the graph.

Is there a way to extract additional information from AutoFixture, such as the property that caused the error?

AutoFixture OmitSpecimen , ?

.

Update

.

public class Session
{
    public Language Language { get; set; }
}

public class Language
{
    public ICollection<Session> Sessions { get; set; }
}

_fixture.CreateAnonymous<Session>(); .

+5
1

AutoFixture (, 3.31.3).

:

public class Session
{
    public Language Language { get; set; }
}

public class Language
{
    public ICollection<Session> Sessions { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        var fixture = new Fixture();
        fixture.Behaviors.Add(new OmitOnRecursionBehavior());

       var session = fixture.Create<Session>();

        Debug.Assert(session != null, "Session should not be null");
    }
}
0

All Articles