1 // ***********************************************************************
2 // Copyright (c) 2015 Charlie Poole
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 // ***********************************************************************
25 #define NUNIT_FRAMEWORK
30 using NUnit.Framework.Interfaces;
32 namespace NUnit.Framework.Internal
35 /// TestParameters is the abstract base class for all classes
36 /// that know how to provide data for constructing a test.
38 public abstract class TestParameters : ITestData, IApplyToTest
43 /// Default Constructor creates an empty parameter set
45 public TestParameters()
47 RunState = RunState.Runnable;
48 Properties = new PropertyBag();
52 /// Construct a parameter set with a list of arguments
54 /// <param name="args"></param>
55 public TestParameters(object[] args)
57 RunState = RunState.Runnable;
58 InitializeAguments(args);
59 Properties = new PropertyBag();
63 /// Construct a non-runnable ParameterSet, specifying
64 /// the provider exception that made it invalid.
66 public TestParameters(Exception exception)
68 RunState = RunState.NotRunnable;
69 Properties = new PropertyBag();
71 Properties.Set(PropertyNames.SkipReason, ExceptionHelper.BuildMessage(exception));
72 Properties.Set(PropertyNames.ProviderStackTrace, ExceptionHelper.BuildStackTrace(exception));
76 /// Construct a ParameterSet from an object implementing ITestData
78 /// <param name="data"></param>
79 public TestParameters(ITestData data)
81 RunState = data.RunState;
82 Properties = new PropertyBag();
84 TestName = data.TestName;
86 InitializeAguments(data.Arguments);
88 foreach (string key in data.Properties.Keys)
89 this.Properties[key] = data.Properties[key];
92 private void InitializeAguments(object[] args)
94 OriginalArguments = args;
96 // We need to copy args, since we may change them
97 var numArgs = args.Length;
98 Arguments = new object[numArgs];
99 Array.Copy(args, Arguments, numArgs);
104 #region ITestData Members
107 /// The RunState for this set of parameters.
109 public RunState RunState { get; set; }
112 /// The arguments to be used in running the test,
113 /// which must match the method signature.
115 public object[] Arguments { get; internal set; }
118 /// A name to be used for this test case in lieu
119 /// of the standard generated name containing
120 /// the argument list.
122 public string TestName { get; set; }
125 /// Gets the property dictionary for this test
127 public IPropertyBag Properties { get; private set; }
131 #region IApplyToTest Members
134 /// Applies ParameterSet _values to the test itself.
136 /// <param name="test">A test.</param>
137 public void ApplyToTest(Test test)
139 if (this.RunState != RunState.Runnable)
140 test.RunState = this.RunState;
142 foreach (string key in Properties.Keys)
143 foreach (object value in Properties[key])
144 test.Properties.Add(key, value);
149 #region Other Public Properties
152 /// The original arguments provided by the user,
153 /// used for display purposes.
155 public object[] OriginalArguments { get; private set; }