You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When ReadonlyCollectionPropertiesBehavior and OmitOnRecursionBehavior are used together, there may be an InvalidCastException thrown from CreateMany call in ReadonlyCollectionPropertiesCommand
InvalidCastException
Unable to cast object of type 'AutoFixture.Kernel.OmitSpecimen' to type 'System.Collections.Generic.IEnumerable1[System.Object]'.
using System.Collections.Generic;using System.Linq;using AutoFixture;using Xunit;
#nullable enable
publicclassBugs{publicclassRecursionModel{publicRecursionItem?Item{get;set;}}publicclassRecursionItem{publicList<RecursionItem> Items {get;}=new();}[Fact]publicvoidOmitRecursion(){varfixture=new Fixture();
fixture.Behaviors.Add(new ReadonlyCollectionPropertiesBehavior());
fixture.Behaviors.OfType<ThrowingRecursionBehavior>().ToList().ForEach(b => fixture.Behaviors.Remove(b));
fixture.Behaviors.Add(new OmitOnRecursionBehavior());// Throws
fixture.Create<RecursionModel>();}}/*System.InvalidCastExceptionUnable to cast object of type 'AutoFixture.Kernel.OmitSpecimen' to type 'System.Collections.Generic.IEnumerable`1[System.Object]'. at AutoFixture.SpecimenFactory.CreateMany(ISpecimenContext context, Type type) at AutoFixture.Kernel.ReadonlyCollectionPropertiesCommand.Execute(Object specimen, ISpecimenContext context) at AutoFixture.Kernel.Postprocessor`1.Create(Object request, ISpecimenContext context) at AutoFixture.Fixture.Create(Object request, ISpecimenContext context) at AutoFixture.Kernel.SpecimenContext.Resolve(Object request) at AutoFixture.Kernel.SeedIgnoringRelay.Create(Object request, ISpecimenContext context) at AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context) at AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context) at AutoFixture.Kernel.Postprocessor`1.Create(Object request, ISpecimenContext context) at AutoFixture.AutoPropertiesTarget.Create(Object request, ISpecimenContext context) at AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context) at AutoFixture.Kernel.TerminatingWithPathSpecimenBuilder.Create(Object request, ISpecimenContext context)*/
Expected Behavior
The code above should not throw. The first level collection should probably be empty
More Information
Using AutoFixture 4.17
The text was updated successfully, but these errors were encountered:
Describe the Bug
When
ReadonlyCollectionPropertiesBehavior
andOmitOnRecursionBehavior
are used together, there may be anInvalidCastException
thrown fromCreateMany
call inReadonlyCollectionPropertiesCommand
AutoFixture/Src/AutoFixture/Kernel/ReadonlyCollectionPropertiesCommand.cs
Lines 64 to 66 in 730b478
Scenario
Expected Behavior
The code above should not throw. The first level collection should probably be empty
More Information
Using AutoFixture 4.17
The text was updated successfully, but these errors were encountered: