[NUI] Rebase develnui (DevelNUI only patches --> master) (#3910)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Devel.Tests.Ubuntu / nunit.framework / Attributes / IgnoreAttribute.cs
1 // ***********************************************************************
2 // Copyright (c) 2009 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.Globalization;
31 using NUnit.Framework.Interfaces;
32 using NUnit.Framework.Internal;
33
34 namespace NUnit.Framework
35 {
36     /// <summary>
37     /// Attribute used to mark a test that is to be ignored.
38     /// Ignored tests result in a warning message when the
39     /// tests are run.
40     /// </summary>
41     [AttributeUsage(AttributeTargets.Method|AttributeTargets.Class|AttributeTargets.Assembly, AllowMultiple=false, Inherited=false)]
42     public class IgnoreAttribute : NUnitAttribute, IApplyToTest
43     {
44         private string _reason;
45         private DateTime? _untilDate;
46         private string _until;
47
48         /// <summary>
49         /// Constructs the attribute giving a reason for ignoring the test
50         /// </summary>
51         /// <param name="reason">The reason for ignoring the test</param>
52         public IgnoreAttribute(string reason)
53         {
54             _reason = reason;
55         }
56
57         /// <summary>
58         /// The date in the future to stop ignoring the test as a string in UTC time. 
59         /// For example for a date and time, "2014-12-25 08:10:00Z" or for just a date,
60         /// "2014-12-25". If just a date is given, the Ignore will expire at midnight UTC.
61         /// </summary>
62         /// <remarks>
63         /// Once the ignore until date has passed, the test will be marked
64         /// as runnable. Tests with an ignore until date will have an IgnoreUntilDate
65         /// property set which will appear in the test results.
66         /// </remarks>
67         /// <exception cref="FormatException">The string does not contain a valid string representation of a date and time.</exception> 
68         public string Until
69         {
70             get { return _until; }
71             set
72             {
73                 _until = value;
74                 _untilDate = DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
75             }
76         }
77
78         #region IApplyToTest members
79
80         /// <summary>
81         /// Modifies a test by marking it as Ignored.
82         /// </summary>
83         /// <param name="test">The test to modify</param>
84         public void ApplyToTest(Test test)
85         {
86             if (test.RunState != RunState.NotRunnable)
87             {
88                 if (_untilDate.HasValue)
89                 {
90                     if (_untilDate.Value > DateTime.Now)
91                     {
92                         test.RunState = RunState.Ignored;
93                         string reason = string.Format("Ignoring until {0}. {1}", _untilDate.Value.ToString("u"), _reason);
94                         test.Properties.Set(PropertyNames.SkipReason, reason);
95                     }
96                     test.Properties.Set(PropertyNames.IgnoreUntilDate, _untilDate.Value.ToString("u") );
97
98                     return;
99                 }
100                 test.RunState = RunState.Ignored;
101                 test.Properties.Set(PropertyNames.SkipReason, _reason);
102             }
103         }
104
105         #endregion
106     }
107 }