Created
September 2, 2021 00:26
-
-
Save flakey-bit/68368fd8b65e0c72e3e68003f1439fa7 to your computer and use it in GitHub Desktop.
xUnit data atrtibute for generating theory cases based on an Enum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[AttributeUsage(AttributeTargets.Method)] | |
public class EnumDataAttribute : DataAttribute | |
{ | |
private readonly Type _tEnum; | |
public EnumDataAttribute(Type tEnum) => this._tEnum = tEnum; | |
/// <summary>Returns the data to be used to test the theory.</summary> | |
/// <param name="methodUnderTest">The method that is being tested</param> | |
/// <param name="parameterTypes">The types of the parameters for the test method</param> | |
/// <returns>The theory data, in table form</returns> | |
public override IEnumerable<object[]> GetData( | |
MethodInfo methodUnderTest, | |
Type[] parameterTypes) | |
{ | |
foreach (var value in Enum.GetValues(_tEnum)) | |
{ | |
yield return new object[] {value}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment