<PackageReference Include="NUnit" Version="4.2.1" />

ValuesAttribute

Provides literal arguments for an individual parameter of a test.
using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System; using System.Collections; using System.Runtime.CompilerServices; namespace NUnit.Framework { [System.Runtime.CompilerServices.NullableContext(2)] [System.Runtime.CompilerServices.Nullable(0)] [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] public class ValuesAttribute : NUnitAttribute, IParameterDataSource { [System.Runtime.CompilerServices.Nullable(new byte[] { 1, 2 })] protected object[] data; public ValuesAttribute() { data = NUnit.Framework.Internal.TestParameters.NoArguments; } public ValuesAttribute(object arg1) { data = new object[1] { arg1 }; } public ValuesAttribute(object arg1, object arg2) { data = new object[2] { arg1, arg2 }; } public ValuesAttribute(object arg1, object arg2, object arg3) { data = new object[3] { arg1, arg2, arg3 }; } public ValuesAttribute(params object[] args) { data = (args ?? new object[1]); } [System.Runtime.CompilerServices.NullableContext(1)] public IEnumerable GetData(IParameterInfo parameter) { if (data.Length == 0) return GenerateData(parameter.ParameterType); return ParamAttributeTypeConversions.ConvertData(data, parameter.ParameterType); } [System.Runtime.CompilerServices.NullableContext(1)] private static IEnumerable GenerateData(Type targetType) { Type type = targetType.IsByRef ? targetType.GetElementType() : targetType; if (IsNullableEnum(type)) { Array values = Enum.GetValues(Nullable.GetUnderlyingType(type)); object[] array = new object[values.Length + 1]; Array.Copy(values, array, values.Length); return array; } if (type.IsEnum) return Enum.GetValues(type); if (type == typeof(bool?)) return new object[3] { null, true, false }; if (type == typeof(bool)) return new object[2] { true, false }; return NUnit.Framework.Internal.TestParameters.NoArguments; } [System.Runtime.CompilerServices.NullableContext(1)] private static bool IsNullableEnum(Type t) { return Nullable.GetUnderlyingType(t)?.IsEnum ?? false; } } }