I am using the latest version of Autofixture, and I would like it to not automatically populate child collections.
For example, I have a Person class that has a List property. I want all properties to be populated except the list.
I tried using this setting:
public class RemoveMultiples : ICustomization { public void Customize(IFixture fixture) { fixture.Customizations .OfType<FilteringSpecimenBuilder>() .Where(x => x.Specification is DictionarySpecification) .ToList().ForEach(c => fixture.Customizations.Remove(c)); fixture.Customizations .OfType<FilteringSpecimenBuilder>() .Where(x => x.Specification is CollectionSpecification) .ToList().ForEach(c => fixture.Customizations.Remove(c)); fixture.Customizations .OfType<FilteringSpecimenBuilder>() .Where(x => x.Specification is HashSetSpecification) .ToList().ForEach(c => fixture.Customizations.Remove(c)); fixture.Customizations .OfType<FilteringSpecimenBuilder>() .Where(x => x.Specification is ListSpecification) .ToList().ForEach(c => fixture.Customizations.Remove(c)); } }
But it also stops me from using .CreateMany() .
edit: I can use .CreateMany(3) and it works.
Is there any parameter that could allow me to autofill collections only when I need to?
edit2: The class person should look like this:
[Serializable] public class Person { private ICollection<OtherClass> _otherClasses; private string _something; public virtual ICollection<OtherClass> OtherClasses { get { return _otherClasses; } set { _otherClasses = value; } } }
Please note that this is not always a Collection , but sometimes an IList
Note2: I just realized that someone also removed the setting for IEnumerable , so why CreateMany() does not create anything.
source share