PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/src/NUnit/framework/Attributes/CategoryAttribute.cs

#
C# | 57 lines | 23 code | 5 blank | 29 comment | 1 complexity | a0b786a0f17df514f9a19aef7d9623ae MD5 | raw file
 1// ****************************************************************
 2// This is free software licensed under the NUnit license. You
 3// may obtain a copy of the license as well as information regarding
 4// copyright ownership at http://nunit.org.
 5// ****************************************************************
 6
 7using System;
 8
 9namespace NUnit.Framework
10{
11	/// <summary>
12	/// Attribute used to apply a category to a test
13	/// </summary>
14	[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Assembly, AllowMultiple=true, Inherited=true)]
15	public class CategoryAttribute : Attribute
16	{
17		/// <summary>
18		/// The name of the category
19		/// </summary>
20		protected string categoryName;
21
22		/// <summary>
23		/// Construct attribute for a given category based on
24        /// a name. The name may not contain the characters ',',
25        /// '+', '-' or '!'. However, this is not checked in the
26        /// constructor since it would cause an error to arise at
27        /// as the test was loaded without giving a clear indication
28        /// of where the problem is located. The error is handled
29        /// in NUnitFramework.cs by marking the test as not
30        /// runnable.
31		/// </summary>
32		/// <param name="name">The name of the category</param>
33		public CategoryAttribute(string name)
34		{
35			this.categoryName = name.Trim();
36		}
37
38		/// <summary>
39		/// Protected constructor uses the Type name as the name
40		/// of the category.
41		/// </summary>
42		protected CategoryAttribute()
43		{
44			this.categoryName = this.GetType().Name;
45			if ( categoryName.EndsWith( "Attribute" ) )
46				categoryName = categoryName.Substring( 0, categoryName.Length - 9 );
47		}
48
49		/// <summary>
50		/// The name of the category
51		/// </summary>
52		public string Name 
53		{
54			get { return categoryName; }
55		}
56	}
57}