Xunit.EnumMemberData is a library containing one attribute ([EnumMemberData]
) to simplify using enums when writing theories (parameterized unittests) using xunit.
[Theory]
[EnumMemberData(typeof(Gender))]
public void TestWithAllEnumValues_UsingEnumMemberData_ByType(Gender gender)
{
_outputWriter.WriteLine($"Gender: {gender}");
}
[Theory]
[EnumMemberData(nameof(Genders))]
public void TestWithAllEnumValues_UsingEnumMemberData_ByProperty(Gender gender)
{
_outputWriter.WriteLine($"Gender: {gender}");
}
// Normally, xunit uses return values like IEnumerable<object[]>
public static IEnumerable<Gender> Genders
{
get
{
return Enum.GetValues(typeof(Gender)).Cast<Gender>();
}
}