Merge branch 'master' of git://github.com/mono/mono
[mono.git] / mcs / nunit24 / NUnitFramework / framework / ExpectedExceptionAttribute.cs
1 // ****************************************************************\r
2 // This is free software licensed under the NUnit license. You\r
3 // may obtain a copy of the license as well as information regarding\r
4 // copyright ownership at http://nunit.org/?p=license&r=2.4.\r
5 // ****************************************************************\r
6 \r
7 namespace NUnit.Framework\r
8 {\r
9         using System;\r
10 \r
11         /// <summary>\r
12         /// Enumeration indicating how the expected message parameter is to be used\r
13         /// </summary>\r
14         public enum MessageMatch\r
15         {\r
16                 /// Expect an exact match\r
17                 Exact,  \r
18                 /// Expect a message containing the parameter string\r
19                 Contains,\r
20                 /// Match the regular expression provided as a parameter\r
21                 Regex\r
22         }\r
23 \r
24         /// <summary>\r
25         /// ExpectedExceptionAttribute\r
26         /// </summary>\r
27         /// \r
28         [AttributeUsage(AttributeTargets.Method, AllowMultiple=false)]\r
29         public class ExpectedExceptionAttribute : Attribute\r
30         {\r
31                 private Type expectedException;\r
32                 private string expectedExceptionName;\r
33                 private string expectedMessage;\r
34                 private MessageMatch matchType;\r
35                 private string userMessage;\r
36                 private string handler;\r
37 \r
38                 /// <summary>\r
39                 /// Constructor for a non-specific exception\r
40                 /// </summary>\r
41                 public ExpectedExceptionAttribute()\r
42                 {\r
43                 }\r
44 \r
45                 /// <summary>\r
46                 /// Constructor for a given type of exception\r
47                 /// </summary>\r
48                 /// <param name="exceptionType">The type of the expected exception</param>\r
49                 public ExpectedExceptionAttribute(Type exceptionType)\r
50                 {\r
51                         this.expectedException = exceptionType;\r
52                         this.expectedExceptionName = exceptionType.FullName;\r
53                 }\r
54 \r
55                 /// <summary>\r
56                 /// Constructor for a given exception name\r
57                 /// </summary>\r
58                 /// <param name="exceptionName">The full name of the expected exception</param>\r
59                 public ExpectedExceptionAttribute(string exceptionName)\r
60                 {\r
61                         this.expectedExceptionName = exceptionName;\r
62                 }\r
63 \r
64                 /// <summary>\r
65                 /// Constructor for a given type of exception and expected message text\r
66                 /// </summary>\r
67                 /// <param name="exceptionType">The type of the expected exception</param>\r
68                 /// <param name="expectedMessage">The expected message text</param>\r
69         [Obsolete("Use named parameter format 'ExpectedMessage=...'", false)]\r
70         public ExpectedExceptionAttribute(Type exceptionType, string expectedMessage)\r
71             : this(exceptionType)\r
72         {\r
73             this.expectedMessage = expectedMessage;\r
74             this.matchType = MessageMatch.Exact;\r
75         }\r
76 \r
77                 /// <summary>\r
78                 /// Constructor for a given exception name and expected message text\r
79                 /// </summary>\r
80                 /// <param name="exceptionName">The full name of the expected exception</param>\r
81                 /// <param name="expectedMessage">The expected messge text</param>\r
82         [Obsolete("Use named parameter format 'ExpectedMessage=...'", false)]\r
83         public ExpectedExceptionAttribute(string exceptionName, string expectedMessage)\r
84             : this(exceptionName)\r
85         {\r
86             this.expectedMessage = expectedMessage;\r
87             this.matchType = MessageMatch.Exact;\r
88         }\r
89 \r
90                 /// <summary>\r
91                 /// Gets or sets the expected exception type\r
92                 /// </summary>\r
93                 public Type ExceptionType \r
94                 {\r
95                         get{ return expectedException; }\r
96                         set{ expectedException = value; }\r
97                 }\r
98 \r
99                 /// <summary>\r
100                 /// Gets or sets the full Type name of the expected exception\r
101                 /// </summary>\r
102                 public string ExceptionName\r
103                 {\r
104                         get{ return expectedExceptionName; }\r
105                         set{ expectedExceptionName = value; }\r
106                 }\r
107 \r
108                 /// <summary>\r
109                 /// Gets or sets the expected message text\r
110                 /// </summary>\r
111                 public string ExpectedMessage \r
112                 {\r
113                         get { return expectedMessage; }\r
114                         set { expectedMessage = value; }\r
115                 }\r
116 \r
117                 /// <summary>\r
118                 /// Gets or sets the user message displayed in case of failure\r
119                 /// </summary>\r
120                 public string UserMessage\r
121                 {\r
122                         get { return userMessage; }\r
123                         set { userMessage = value; }\r
124                 }\r
125 \r
126                 /// <summary>\r
127                 ///  Gets or sets the type of match to be performed on the expected message\r
128                 /// </summary>\r
129                 public MessageMatch MatchType\r
130                 {\r
131                         get { return matchType; }\r
132                         set { matchType = value; }\r
133                 }\r
134 \r
135                 /// <summary>\r
136                 ///  Gets the name of a method to be used as an exception handler\r
137                 /// </summary>\r
138                 public string Handler\r
139                 {\r
140                         get { return handler; }\r
141                         set { handler = value; }\r
142                 }\r
143         }\r
144 }\r