[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Attributes / TestAttribute.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
30 namespace NUnit.Framework
31 {
32     using System;
33     using System.Collections.Generic;
34     using NUnit.Framework.Interfaces;
35     using NUnit.Framework.Internal;
36     using NUnit.Framework.Internal.Builders;
37
38     /// <summary>
39     /// Adding this attribute to a method within a <seealso cref="TestFixtureAttribute"/> 
40     /// class makes the method callable from the NUnit test runner. There is a property 
41     /// called Description which is optional which you can provide a more detailed test
42     /// description. This class cannot be inherited.
43     /// </summary>
44     /// 
45     /// <example>
46     /// [TestFixture]
47     /// public class Fixture
48     /// {
49     ///   [Test]
50     ///   public void MethodToTest()
51     ///   {}
52     ///   
53     ///   [Test(Description = "more detailed description")]
54     ///   public void TestDescriptionMethod()
55     ///   {}
56     /// }
57     /// </example>
58     /// 
59     [AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)]
60     public class TestAttribute : NUnitAttribute, ISimpleTestBuilder, IApplyToTest, IImplyFixture
61     {
62         private object _expectedResult;
63         private readonly NUnitTestCaseBuilder _builder = new NUnitTestCaseBuilder();
64
65         /// <summary>
66         /// Descriptive text for this test
67         /// </summary>
68         public string Description { get; set; }
69
70         /// <summary>
71         /// The author of this test
72         /// </summary>
73         public string Author { get; set; }
74
75         /// <summary>
76         /// The type that this test is testing
77         /// </summary>
78         public Type TestOf { get; set; }
79
80         #region IApplyToTest Members
81
82         /// <summary>
83         /// Modifies a test by adding a description, if not already set.
84         /// </summary>
85         /// <param name="test">The test to modify</param>
86         public void ApplyToTest(Test test)
87         {
88             if (!test.Properties.ContainsKey(PropertyNames.Description) && Description != null)
89                 test.Properties.Set(PropertyNames.Description, Description);
90
91             if (!test.Properties.ContainsKey(PropertyNames.Author) && Author != null)
92                 test.Properties.Set(PropertyNames.Author, Author);
93
94             if (!test.Properties.ContainsKey(PropertyNames.TestOf) && TestOf != null)
95                 test.Properties.Set(PropertyNames.TestOf, TestOf.FullName);
96             
97         }
98
99         #endregion
100
101         #region ITestExpectedResult Members
102
103         /// <summary>
104         /// Gets or sets the expected result.
105         /// </summary>
106         /// <value>The result.</value>
107         public object ExpectedResult
108         {
109             get { return _expectedResult; }
110             set
111             {
112                 _expectedResult = value;
113                 HasExpectedResult = true;
114             }
115         }
116
117         /// <summary>
118         /// Returns true if an expected result has been set
119         /// </summary>
120         public bool HasExpectedResult { get; private set; }
121
122         #endregion
123
124         #region ISimpleTestBuilder Members
125
126         /// <summary>
127         /// Construct a TestMethod from a given method.
128         /// </summary>
129         /// <param name="method">The method for which a test is to be constructed.</param>
130         /// <param name="suite">The suite to which the test will be added.</param>
131         /// <returns>A TestMethod</returns>
132         public TestMethod BuildFrom(IMethodInfo method, Test suite)
133         {
134             TestCaseParameters parms = null;
135
136             if (this.HasExpectedResult)
137             {
138                 parms = new TestCaseParameters();
139                 parms.ExpectedResult = this.ExpectedResult;
140             }
141
142             return _builder.BuildTestMethod(method, suite, parms);
143         }
144         
145         #endregion
146     }
147 }