Given an enum:
public enum MyEnum
{
DoNotInclude,
IncludeThis,
IncludeThisToo
}
and a class:
public class MyClass
{
public MyEnum MyEnum { get; set; }
}
and a test:
[TestMethod]
public void MyTest()
{
var fixture = new Fixture();
var myClasses = fixture.CreateMany<MyClass>(4);
}
myClasses
now contains one of each of the MyEnum
values
I want it to exclude the DoNotInclude
value.
I know how to .Customize<>()
using .With()
to force it to use a specific value for each instance but cannot find an obvious option to use all except one value.
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));
}
How do I do this with a single .CreateMany
?
EDIT: Following the answer from the question this is a duplicate of, here is my solution based on creating classes with enum properties:
var myClasses = fixture.Create<Generator<MyClass>>().Where(c => c.MyEnum != MyEnum.DoNotInclude).Take(4);