Question

In this test, I expected dummyVar to be empty. However, regardless of what I set OmitAutoProperty to, it is not.

Is this correct behavior and why? What would be the AutoFixture way of creating an empty dummy collection?

[Fact]
public void ShouldBeEmpty()
{
    var fixture = new Fixture();
    fixture.Customize(new AutoMoqCustomization());
    fixture.OmitAutoProperties = true;
    var dummyVar = fixture.Create<IEnumerable<IComparable>>();
    Assert.Empty(dummyVar);
}
Was it helpful?

Solution

This is by design in AutoFixture 3.0. However, if you rather want enumerables to be empty, you can configure that as well.

If you explicitly want only IEnumerable<IComparable> (but not other collections) to be empty, an easier way is to do this:

fixture.Inject<IEnumerable<IComparable>>(new IComparable[0]);

OmitAutoProperties control whether or not object properties (and fields) are populated or not. It doesn't affect the size of collections. (IEnumerable<T> defines no writable properties.)

RepeatCount controls the size of collections, but as the previously mentioned issue reports, you cant set RepeatCount to 0 (again by design).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top