PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

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