[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Attributes / SetUpFixtureAttribute.cs
1 // ***********************************************************************
2 // Copyright (c) 2014 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
32 namespace NUnit.Framework
33 {
34     using Interfaces;
35     using Internal;
36
37     /// <summary>
38     /// SetUpFixtureAttribute is used to identify a SetUpFixture
39     /// </summary>
40     [AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
41     public class SetUpFixtureAttribute : NUnitAttribute, IFixtureBuilder
42     {
43         #region ISuiteBuilder Members
44
45         /// <summary>
46         /// Build a SetUpFixture from type provided. Normally called for a Type
47         /// on which the attribute has been placed.
48         /// </summary>
49         /// <param name="typeInfo">The type info of the fixture to be used.</param>
50         /// <returns>A SetUpFixture object as a TestSuite.</returns>
51         public IEnumerable<TestSuite> BuildFrom(ITypeInfo typeInfo)
52         {
53             SetUpFixture fixture = new SetUpFixture(typeInfo);
54
55             if (fixture.RunState != RunState.NotRunnable)
56             {
57                 string reason = null;
58                 if (!IsValidFixtureType(typeInfo, ref reason))
59                 {
60                     fixture.RunState = RunState.NotRunnable;
61                     fixture.Properties.Set(PropertyNames.SkipReason, reason);
62                 }
63             }
64
65             return new TestSuite[] { fixture };
66         }
67
68         #endregion
69
70         #region Helper Methods
71
72         private bool IsValidFixtureType(ITypeInfo typeInfo, ref string reason)
73         {
74             if (typeInfo.IsAbstract)
75             {
76                 reason = string.Format("{0} is an abstract class", typeInfo.FullName);
77                 return false;
78             }
79
80             if (!typeInfo.HasConstructor(new Type[0]))
81             {
82                 reason = string.Format("{0} does not have a default constructor", typeInfo.FullName);
83                 return false;
84             }
85
86             var invalidAttributes = new Type[] { 
87                 typeof(SetUpAttribute), 
88                 typeof(TearDownAttribute),
89 #pragma warning disable 618 // Obsolete Attributes
90                 typeof(TestFixtureSetUpAttribute), 
91                 typeof(TestFixtureTearDownAttribute) };
92 #pragma warning restore
93
94             foreach (Type invalidType in invalidAttributes)
95                 if (typeInfo.HasMethodWithAttribute(invalidType))
96                 {
97                     reason = invalidType.Name + " attribute not allowed in a SetUpFixture";
98                     return false;
99                 }
100
101             return true;
102         }
103
104         #endregion
105     }
106 }