Merge remote-tracking branch 'local/msvc-updates' into msvc-updates
[mono.git] / mcs / nunit24 / NUnitFramework / framework / AbstractAsserter.cs
1 // ****************************************************************\r
2 // Copyright 2007, Charlie Poole\r
3 // This is free software licensed under the NUnit license. You may\r
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4\r
5 // ****************************************************************\r
6 \r
7 using System;\r
8 \r
9 namespace NUnit.Framework\r
10 {\r
11         /// <summary>\r
12         /// NOTE: The use of asserters for extending NUnit has\r
13         /// now been replaced by the use of constraints. This\r
14         /// class is marked obsolete.\r
15         /// \r
16         /// AbstractAsserter is the base class for all asserters.\r
17         /// Asserters encapsulate a condition test and generation \r
18         /// of an AssertionException with a tailored message. They\r
19         /// are used by the Assert class as helper objects.\r
20         /// \r
21         /// User-defined asserters may be passed to the \r
22         /// Assert.DoAssert method in order to implement \r
23         /// extended asserts.\r
24         /// </summary>\r
25         [Obsolete("Use Constraints rather than Asserters for new work")]\r
26         public abstract class AbstractAsserter : IAsserter\r
27         {\r
28                 /// <summary>\r
29                 /// The user-defined message for this asserter.\r
30                 /// </summary>\r
31                 protected readonly string userMessage;\r
32                 \r
33                 /// <summary>\r
34                 /// Arguments to use in formatting the user-defined message.\r
35                 /// </summary>\r
36                 protected readonly object[] args;\r
37 \r
38                 /// <summary>\r
39                 /// Our failure message object, initialized as needed\r
40                 /// </summary>\r
41                 private AssertionFailureMessage failureMessage;\r
42 \r
43                 /// <summary>\r
44                 /// Constructs an AbstractAsserter\r
45                 /// </summary>\r
46                 /// <param name="message">The message issued upon failure</param>\r
47                 /// <param name="args">Arguments to be used in formatting the message</param>\r
48                 public AbstractAsserter( string message, params object[] args )\r
49                 {\r
50                         this.userMessage = message;\r
51                         this.args = args;\r
52                 }\r
53 \r
54                 /// <summary>\r
55                 /// AssertionFailureMessage object used internally\r
56                 /// </summary>\r
57                 protected AssertionFailureMessage FailureMessage\r
58                 {\r
59                         get\r
60                         {\r
61                                 if ( failureMessage == null )\r
62                                         failureMessage = new AssertionFailureMessage( userMessage, args );\r
63                                 return failureMessage;\r
64                         }\r
65                 }\r
66 \r
67                 #region IAsserter Interface\r
68                 /// <summary>\r
69                 /// Test method to be implemented by derived types.\r
70                 /// Default always succeeds.\r
71                 /// </summary>\r
72                 /// <returns>True if the test succeeds</returns>\r
73                 public abstract bool Test();\r
74 \r
75                 /// <summary>\r
76                 /// Message related to a failure. If no failure has\r
77                 /// occured, the result is unspecified.\r
78                 /// </summary>\r
79                 public virtual string Message\r
80                 {\r
81                         get\r
82                         {\r
83                                 return FailureMessage.ToString();\r
84                         }\r
85                 }\r
86                 #endregion\r
87         }\r
88 }\r