3 #define NUNIT_FRAMEWORK
8 using System.Collections.Generic;
11 namespace NUnit.Framework
14 /// TestParameters class holds any named parameters supplied to the test run
16 public class TestParameters
18 private readonly Dictionary<string, string> _parameters = new Dictionary<string, string>();
21 /// Gets the number of test parameters
25 get { return _parameters.Count; }
29 /// Gets a collection of the test parameter names
31 public ICollection<string> Names
33 get { return _parameters.Keys; }
37 /// Gets a flag indicating whether a parameter with the specified name exists.N
39 /// <param name="name">Name of the parameter</param>
40 /// <returns>True if it exists, otherwise false</returns>
41 public bool Exists(string name)
43 return _parameters.ContainsKey(name);
47 /// Indexer provides access to the internal dictionary
49 /// <param name="name">Name of the parameter</param>
50 /// <returns>Value of the parameter or null if not present</returns>
51 public string this[string name]
53 get { return Get(name); }
57 /// Get method is a simple alternative to the indexer
59 /// <param name="name">Name of the paramter</param>
60 /// <returns>Value of the parameter or null if not present</returns>
61 public string Get(string name)
63 return Exists(name) ? _parameters[name] : null;
67 /// Get the value of a parameter or a default string
69 /// <param name="name">Name of the parameter</param>
70 /// <param name="defaultValue">Default value of the parameter</param>
71 /// <returns>Value of the parameter or default value if not present</returns>
72 public string Get(string name, string defaultValue)
74 return Get(name) ?? defaultValue;
78 /// Get the value of a parameter or return a default
80 /// <typeparam name="T">The return Type</typeparam>
81 /// <param name="name">Name of the parameter</param>
82 /// <param name="defaultValue">Default value of the parameter</param>
83 /// <returns>Value of the parameter or default value if not present</returns>
84 public T Get<T>(string name, T defaultValue)
86 string val = Get(name);
87 return val != null ? (T)Convert.ChangeType(val, typeof(T), null) : defaultValue;
91 /// Adds a parameter to the list
93 /// <param name="name">Name of the parameter</param>
94 /// <param name="value">Value of the parameter</param>
95 internal void Add(string name, string value)
97 _parameters[name] = value;