鉴于枚举:
public enum MyEnum
{
DoNotInclude,
IncludeThis,
IncludeThisToo
}
和一个班级:
public class MyClass
{
public MyEnum MyEnum { get; set; }
}
和测试:
[TestMethod]
public void MyTest()
{
var fixture = new Fixture();
var myClasses = fixture.CreateMany<MyClass>(4);
}
myClasses
现在包含每个MyEnum
值
我希望它排除DoNotInclude
值。
我知道如何.Customize<>()
使用.With()
强制它为每个实例使用特定值,但找不到明显的选项来使用除一个值以外的所有值。
e.g:
[TestMethod]
public void MyTest()
{
var fixture = new Fixture();
var myClasses = new List<MyClass>();
fixture.Customize<MyClass>(c => c.With(x => x.MyEnum, MyEnum.IncludeThis));
myClasses.AddRange(fixture.CreateMany<MyClass>(2));
fixture.Customize<MyClass>(c => c.With(x => x.MyEnum, MyEnum.IncludeThisToo));
myClasses.AddRange(fixture.CreateMany<MyClass>(2));
}
如何使用单个.CreateMany
?
编辑:根据问题的回答这是重复的,这是我的解决方案基于创建具有枚举属性的类:
var myClasses = fixture.Create<Generator<MyClass>>().Where(c => c.MyEnum != MyEnum.DoNotInclude).Take(4);