[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / TestParameters.cs
1 #define PORTABLE
2 #define TIZEN
3 #define NUNIT_FRAMEWORK
4 #define NUNITLITE
5 #define NET_4_5
6 #define PARALLEL
7 using System;
8 using System.Collections.Generic;
9 using System.Text;
10
11 namespace NUnit.Framework
12 {
13     /// <summary>
14     /// TestParameters class holds any named parameters supplied to the test run
15     /// </summary>
16     public class TestParameters
17     {
18         private readonly Dictionary<string, string> _parameters = new Dictionary<string, string>();
19
20         /// <summary>
21         /// Gets the number of test parameters
22         /// </summary>
23         public int Count
24         {
25             get { return _parameters.Count; }
26         }
27
28         /// <summary>
29         /// Gets a collection of the test parameter names
30         /// </summary>
31         public ICollection<string> Names
32         {
33             get { return _parameters.Keys; }
34         }
35
36         /// <summary>
37         /// Gets a flag indicating whether a parameter with the specified name exists.N
38         /// </summary>
39         /// <param name="name">Name of the parameter</param>
40         /// <returns>True if it exists, otherwise false</returns>
41         public bool Exists(string name)
42         {
43             return _parameters.ContainsKey(name);
44         }
45
46         /// <summary>
47         /// Indexer provides access to the internal dictionary
48         /// </summary>
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]
52         {
53             get { return Get(name); }
54         }
55
56         /// <summary>
57         /// Get method is a simple alternative to the indexer
58         /// </summary>
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)
62         {
63             return Exists(name) ? _parameters[name] : null;
64         }
65
66         /// <summary>
67         /// Get the value of a parameter or a default string
68         /// </summary>
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)
73         {
74             return Get(name) ?? defaultValue;
75         }
76
77         /// <summary>
78         /// Get the value of a parameter or return a default
79         /// </summary>
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)
85         {
86             string val = Get(name);
87             return val != null ? (T)Convert.ChangeType(val, typeof(T), null) : defaultValue;
88         }
89
90         /// <summary>
91         /// Adds a parameter to the list
92         /// </summary>
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)
96         {
97             _parameters[name] = value;
98         }
99     }
100 }