[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Attributes / TestFixtureAttribute.cs
1 // ***********************************************************************
2 // Copyright (c) 2009-2015 Charlie Poole
3 //
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:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
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 // ***********************************************************************
23 #define PORTABLE
24 #define TIZEN
25 #define NUNIT_FRAMEWORK
26 #define NUNITLITE
27 #define NET_4_5
28 #define PARALLEL
29 using System;
30 using System.Collections.Generic;
31 using NUnit.Framework.Interfaces;
32 using NUnit.Framework.Internal;
33 using NUnit.Framework.Internal.Builders;
34
35 namespace NUnit.Framework
36 {
37     /// <summary>
38     /// TestFixtureAttribute is used to mark a class that represents a TestFixture.
39     /// </summary>
40     [AttributeUsage(AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
41     public class TestFixtureAttribute : NUnitAttribute, IFixtureBuilder, ITestFixtureData
42     {
43         private readonly NUnitTestFixtureBuilder _builder = new NUnitTestFixtureBuilder();
44
45         #region Constructors
46
47         /// <summary>
48         /// Default constructor
49         /// </summary>
50         public TestFixtureAttribute() : this( new object[0] ) { }
51         
52         /// <summary>
53         /// Construct with a object[] representing a set of arguments. 
54         /// In .NET 2.0, the arguments may later be separated into
55         /// type arguments and constructor arguments.
56         /// </summary>
57         /// <param name="arguments"></param>
58         public TestFixtureAttribute(params object[] arguments)
59         {
60             RunState = RunState.Runnable;
61             Arguments = arguments;
62             TypeArgs = new Type[0];
63             Properties = new PropertyBag();
64         }
65
66         #endregion
67
68         #region ITestData Members
69
70         /// <summary>
71         /// Gets or sets the name of the test.
72         /// </summary>
73         /// <value>The name of the test.</value>
74         public string TestName { get; set; }
75
76         /// <summary>
77         /// Gets or sets the RunState of this test fixture.
78         /// </summary>
79         public RunState RunState { get; private set; }
80
81         /// <summary>
82         /// The arguments originally provided to the attribute
83         /// </summary>
84         public object[] Arguments { get; private set; }
85
86         /// <summary>
87         /// Properties pertaining to this fixture
88         /// </summary>
89         public IPropertyBag Properties { get; private set; }
90
91         #endregion
92
93         #region ITestFixtureData Members
94
95         /// <summary>
96         /// Get or set the type arguments. If not set
97         /// explicitly, any leading arguments that are
98         /// Types are taken as type arguments.
99         /// </summary>
100         public Type[] TypeArgs { get; set; }
101
102         #endregion
103
104         #region Other Properties
105
106         /// <summary>
107         /// Descriptive text for this fixture
108         /// </summary>
109         public string Description
110         {
111             get { return Properties.Get(PropertyNames.Description) as string; }
112             set { Properties.Set(PropertyNames.Description, value); }
113         }
114
115         /// <summary>
116         /// The author of this fixture
117         /// </summary>
118         public string Author
119         {
120             get { return Properties.Get(PropertyNames.Author) as string; }
121             set { Properties.Set(PropertyNames.Author, value); }
122         }
123
124         /// <summary>
125         /// The type that this fixture is testing
126         /// </summary>
127         public Type TestOf 
128         {
129             get { return _testOf;  }
130             set
131             {
132                 _testOf = value;
133                 Properties.Set(PropertyNames.TestOf, value.FullName);
134             }
135         }
136         private Type _testOf;
137
138         /// <summary>
139         /// Gets or sets the ignore reason. May set RunState as a side effect.
140         /// </summary>
141         /// <value>The ignore reason.</value>
142         public string Ignore
143         {
144             get { return IgnoreReason;  }
145             set { IgnoreReason = value; }
146         }
147
148         /// <summary>
149         /// Gets or sets the reason for not running the fixture.
150         /// </summary>
151         /// <value>The reason.</value>
152         public string Reason
153         {
154             get { return this.Properties.Get(PropertyNames.SkipReason) as string; }
155             set { this.Properties.Set(PropertyNames.SkipReason, value); }
156         }
157
158         /// <summary>
159         /// Gets or sets the ignore reason. When set to a non-null
160         /// non-empty value, the test is marked as ignored.
161         /// </summary>
162         /// <value>The ignore reason.</value>
163         public string IgnoreReason
164         {
165             get { return Reason; }
166             set
167             {
168                 RunState = RunState.Ignored;
169                 Reason = value;
170             }
171         }
172
173         /// <summary>
174         /// Gets or sets a value indicating whether this <see cref="NUnit.Framework.TestFixtureAttribute"/> is explicit.
175         /// </summary>
176         /// <value>
177         /// <c>true</c> if explicit; otherwise, <c>false</c>.
178         /// </value>
179         public bool Explicit
180         {
181             get { return RunState == RunState.Explicit; }
182             set { RunState = value ? RunState.Explicit : RunState.Runnable; }
183         }
184
185         /// <summary>
186         /// Gets and sets the category for this fixture.
187         /// May be a comma-separated list of categories.
188         /// </summary>
189         public string Category
190         {
191             get 
192             { 
193                 //return Properties.Get(PropertyNames.Category) as string;
194                 var catList = Properties[PropertyNames.Category];
195                 if (catList == null)
196                     return null;
197
198                 switch (catList.Count)
199                 {
200                     case 0:
201                         return null;
202                     case 1:
203                         return catList[0] as string;
204                     default:
205                         var cats = new string[catList.Count];
206                         int index = 0;
207                         foreach (string cat in catList)
208                             cats[index++] = cat;
209
210                         return string.Join(",", cats);
211                 }
212             }
213             set
214             {
215                 foreach (string cat in value.Split(new char[] { ',' }))
216                     Properties.Add(PropertyNames.Category, cat);
217             }
218         }
219  
220         #endregion
221
222         #region IFixtureBuilder Members
223
224         /// <summary>
225         /// Build a fixture from type provided. Normally called for a Type
226         /// on which the attribute has been placed.
227         /// </summary>
228         /// <param name="typeInfo">The type info of the fixture to be used.</param>
229         /// <returns>A an IEnumerable holding one TestFixture object.</returns>
230         public IEnumerable<TestSuite> BuildFrom(ITypeInfo typeInfo)
231         {
232             yield return _builder.BuildFrom(typeInfo, this);
233         }
234
235         #endregion
236     }
237 }