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
7 namespace NUnit.Framework
\r
12 /// Enumeration indicating how the expected message parameter is to be used
\r
14 public enum MessageMatch
\r
16 /// Expect an exact match
\r
18 /// Expect a message containing the parameter string
\r
20 /// Match the regular expression provided as a parameter
\r
25 /// ExpectedExceptionAttribute
\r
28 [AttributeUsage(AttributeTargets.Method, AllowMultiple=false)]
\r
29 public class ExpectedExceptionAttribute : Attribute
\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
39 /// Constructor for a non-specific exception
\r
41 public ExpectedExceptionAttribute()
\r
46 /// Constructor for a given type of exception
\r
48 /// <param name="exceptionType">The type of the expected exception</param>
\r
49 public ExpectedExceptionAttribute(Type exceptionType)
\r
51 this.expectedException = exceptionType;
\r
52 this.expectedExceptionName = exceptionType.FullName;
\r
56 /// Constructor for a given exception name
\r
58 /// <param name="exceptionName">The full name of the expected exception</param>
\r
59 public ExpectedExceptionAttribute(string exceptionName)
\r
61 this.expectedExceptionName = exceptionName;
\r
65 /// Constructor for a given type of exception and expected message text
\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
73 this.expectedMessage = expectedMessage;
\r
74 this.matchType = MessageMatch.Exact;
\r
78 /// Constructor for a given exception name and expected message text
\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
86 this.expectedMessage = expectedMessage;
\r
87 this.matchType = MessageMatch.Exact;
\r
91 /// Gets or sets the expected exception type
\r
93 public Type ExceptionType
\r
95 get{ return expectedException; }
\r
96 set{ expectedException = value; }
\r
100 /// Gets or sets the full Type name of the expected exception
\r
102 public string ExceptionName
\r
104 get{ return expectedExceptionName; }
\r
105 set{ expectedExceptionName = value; }
\r
109 /// Gets or sets the expected message text
\r
111 public string ExpectedMessage
\r
113 get { return expectedMessage; }
\r
114 set { expectedMessage = value; }
\r
118 /// Gets or sets the user message displayed in case of failure
\r
120 public string UserMessage
\r
122 get { return userMessage; }
\r
123 set { userMessage = value; }
\r
127 /// Gets or sets the type of match to be performed on the expected message
\r
129 public MessageMatch MatchType
\r
131 get { return matchType; }
\r
132 set { matchType = value; }
\r
136 /// Gets the name of a method to be used as an exception handler
\r
138 public string Handler
\r
140 get { return handler; }
\r
141 set { handler = value; }
\r