1 // ****************************************************************
2 // Copyright 2007, Charlie Poole
3 // This is free software licensed under the NUnit license. You may
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
5 // ****************************************************************
6 
7 using System;
8 
9 namespace NUnit.Framework
10 {
11 	/// <summary>
12 	/// Abstract base for Attributes that are used to include tests
13 	/// in the test run based on environmental settings.
14 	/// </summary>
15 	public abstract class IncludeExcludeAttribute : Attribute
16 	{
17 		private string include;
18 		private string exclude;
19 		private string reason;
20 
21 		/// <summary>
22 		/// Constructor with no included items specified, for use
23 		/// with named property syntax.
24 		/// </summary>
IncludeExcludeAttribute()25 		public IncludeExcludeAttribute() { }
26 
27 		/// <summary>
28 		/// Constructor taking one or more included items
29 		/// </summary>
30 		/// <param name="include">Comma-delimited list of included items</param>
IncludeExcludeAttribute( string include )31 		public IncludeExcludeAttribute( string include )
32 		{
33 			this.include = include;
34 		}
35 
36 		/// <summary>
37 		/// Name of the item that is needed in order for
38 		/// a test to run. Multiple itemss may be given,
39 		/// separated by a comma.
40 		/// </summary>
41 		public string Include
42 		{
43 			get { return this.include; }
44 			set { include = value; }
45 		}
46 
47 		/// <summary>
48 		/// Name of the item to be excluded. Multiple items
49 		/// may be given, separated by a comma.
50 		/// </summary>
51 		public string Exclude
52 		{
53 			get { return this.exclude; }
54 			set { this.exclude = value; }
55 		}
56 
57 		/// <summary>
58 		/// The reason for including or excluding the test
59 		/// </summary>
60 		public string Reason
61 		{
62 			get { return reason; }
63 			set { reason = value; }
64 		}
65 	}
66 
67 	/// <summary>
68 	/// PlatformAttribute is used to mark a test fixture or an
69 	/// individual method as applying to a particular platform only.
70 	/// </summary>
71 	[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Assembly, AllowMultiple=true)]
72 	public class PlatformAttribute : IncludeExcludeAttribute
73 	{
74 		/// <summary>
75 		/// Constructor with no platforms specified, for use
76 		/// with named property syntax.
77 		/// </summary>
PlatformAttribute()78 		public PlatformAttribute() { }
79 
80 		/// <summary>
81 		/// Constructor taking one or more platforms
82 		/// </summary>
83 		/// <param name="platforms">Comma-deliminted list of platforms</param>
PlatformAttribute( string platforms )84 		public PlatformAttribute( string platforms ) : base( platforms ) { }
85 	}
86 
87 	/// <summary>
88 	/// CultureAttribute is used to mark a test fixture or an
89 	/// individual method as applying to a particular Culture only.
90 	/// </summary>
91 	[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Assembly, AllowMultiple=false)]
92 	public class CultureAttribute : IncludeExcludeAttribute
93 	{
94 		/// <summary>
95 		/// Constructor with no cultures specified, for use
96 		/// with named property syntax.
97 		/// </summary>
CultureAttribute()98 		public CultureAttribute() { }
99 
100 		/// <summary>
101 		/// Constructor taking one or more cultures
102 		/// </summary>
103 		/// <param name="cultures">Comma-deliminted list of cultures</param>
CultureAttribute( string cultures )104 		public CultureAttribute( string cultures ) : base( cultures ) { }
105 	}
106 }
107