1 // ***********************************************************************
2 // Copyright (c) 2009 Charlie Poole
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:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
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 // ***********************************************************************
25 #define NUNIT_FRAMEWORK
30 using System.Globalization;
31 using NUnit.Framework.Interfaces;
32 using NUnit.Framework.Internal;
34 namespace NUnit.Framework
37 /// Attribute used to mark a test that is to be ignored.
38 /// Ignored tests result in a warning message when the
41 [AttributeUsage(AttributeTargets.Method|AttributeTargets.Class|AttributeTargets.Assembly, AllowMultiple=false, Inherited=false)]
42 public class IgnoreAttribute : NUnitAttribute, IApplyToTest
44 private string _reason;
45 private DateTime? _untilDate;
46 private string _until;
49 /// Constructs the attribute giving a reason for ignoring the test
51 /// <param name="reason">The reason for ignoring the test</param>
52 public IgnoreAttribute(string reason)
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.
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.
67 /// <exception cref="FormatException">The string does not contain a valid string representation of a date and time.</exception>
70 get { return _until; }
74 _untilDate = DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal);
78 #region IApplyToTest members
81 /// Modifies a test by marking it as Ignored.
83 /// <param name="test">The test to modify</param>
84 public void ApplyToTest(Test test)
86 if (test.RunState != RunState.NotRunnable)
88 if (_untilDate.HasValue)
90 if (_untilDate.Value > DateTime.Now)
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);
96 test.Properties.Set(PropertyNames.IgnoreUntilDate, _untilDate.Value.ToString("u") );
100 test.RunState = RunState.Ignored;
101 test.Properties.Set(PropertyNames.SkipReason, _reason);