I want to create a customization to restrict the values of an enum
supplied by AutoFixture. The only examples I've been able to find so far use the imperative style (such as this).
Given the following enum
definition:
public enum AnEnum
{
A,
B,
C
}
I would like to restrict the values to AnEnum.B
and AnEnum.C
. I've tried some variations of the following code.
public class EnumCustomization : ICustomization
{
public virtual void Customize(IFixture fixture)
{
fixture.Customize<AnEnum>(
c => c.FromFactory(() => new Generator<AnEnum>(fixture).First(e => e != AnEnum.A)));
}
}
However, they all inevitably lead to an AutoFixture.ObjectCreationExceptionWithPath
exception. Without the customization AutoFixture will create a value of AnEnum
as normal. Therefore, I think the problem lies with my attempts at customization rather than any circular references elsewhere.