AutoFixture IEnumerable<T> behavior with CreateMany()

本小妞迷上赌 提交于 2019-12-01 03:35:17

This is indeed the expected default behavior. There are many reasons for that, but basically it boils down to that when you ask for a IEnumerable<T> AutoFixture actually goes to great lengths to ensure that you get only what you ask for.

This is surprising behavior to many. The good news is that you can change it.

fixture.Customizations.Add(new StableFiniteSequenceRelay());

This will change the behavior such that subsequently all sequences are stable. You can package that method call into a Customization for better reusability. That might look something like this (totally optional):

public class StableFiniteSequenceCustomization : ICustomization
{
    public void Customize(IFixture fixture)
    {
        fixture.Customizations.Add(new StableFiniteSequenceRelay());
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!