TestParameters
TestParameters is the abstract base class for all classes
that know how to provide data for constructing a test.
using NUnit.Framework.Interfaces;
using System;
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Internal
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public abstract class TestParameters : ITestData, IApplyToTest
{
internal static readonly object[] NoArguments = Array.Empty<object>();
[System.Runtime.CompilerServices.Nullable(2)]
private string _testName;
[System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
private string[] _argDisplayNames;
public RunState RunState { get; set; }
[System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2
})]
[field: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2
})]
public object[] Arguments {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2
})]
get;
[param: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2
})]
internal set;
}
[System.Runtime.CompilerServices.Nullable(2)]
public string TestName {
[System.Runtime.CompilerServices.NullableContext(2)]
get {
return _testName;
}
[System.Runtime.CompilerServices.NullableContext(2)]
set {
Guard.OperationValid(ArgDisplayNames == null || value == null, "TestName cannot be set when argument display names are set.");
_testName = value;
}
}
public IPropertyBag Properties { get; set; }
[System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2
})]
[field: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2
})]
public object[] OriginalArguments {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2
})]
get;
[param: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2
})]
protected internal set;
}
[System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
internal string[] ArgDisplayNames {
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
get {
return _argDisplayNames;
}
[param: System.Runtime.CompilerServices.Nullable(new byte[] {
2,
1
})]
set {
Guard.OperationValid(TestName == null || value == null, "Argument display names cannot be set when TestName is set.");
_argDisplayNames = value;
}
}
public TestParameters()
: this(RunState.Runnable, NoArguments)
{
Properties = new PropertyBag();
}
public TestParameters([System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2
})] object[] args)
: this(RunState.Runnable, args)
{
Properties = new PropertyBag();
}
public TestParameters(Exception exception)
: this(RunState.NotRunnable, NoArguments)
{
Properties = new PropertyBag();
Properties.Set("_SKIPREASON", ExceptionHelper.BuildMessage(exception, false));
Properties.Set("_PROVIDERSTACKTRACE", ExceptionHelper.BuildStackTrace(exception));
}
public TestParameters(ITestData data)
: this(data.RunState, data.Arguments)
{
TestName = data.TestName;
foreach (string key in data.Properties.Keys) {
Properties[key] = data.Properties[key];
}
}
private TestParameters(RunState runState, [System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2
})] object[] args)
{
RunState = runState;
OriginalArguments = args;
int num = args.Length;
Arguments = new object[num];
Array.Copy(args, Arguments, num);
Properties = new PropertyBag();
}
public void ApplyToTest(Test test)
{
if (RunState != RunState.Runnable)
test.RunState = RunState;
foreach (string key in Properties.Keys) {
foreach (object item in Properties[key]) {
test.Properties.Add(key, item);
}
}
}
}
}