Merge pull request #704 from jgagnon/master
[mono.git] / mcs / nunit24 / NUnitFramework / framework / Constraints / SameAsConstraint.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.Constraints\r
10 {\r
11     /// <summary>\r
12     /// SameAsConstraint tests whether an object is identical to\r
13     /// the object passed to its constructor\r
14     /// </summary>\r
15     public class SameAsConstraint : Constraint\r
16     {\r
17         private object expected;\r
18 \r
19         /// <summary>\r
20         /// Initializes a new instance of the <see cref="T:SameAsConstraint"/> class.\r
21         /// </summary>\r
22         /// <param name="expected">The expected object.</param>\r
23         public SameAsConstraint(object expected)\r
24         {\r
25             this.expected = expected;\r
26         }\r
27 \r
28         /// <summary>\r
29         /// Test whether the constraint is satisfied by a given value\r
30         /// </summary>\r
31         /// <param name="actual">The value to be tested</param>\r
32         /// <returns>True for success, false for failure</returns>\r
33         public override bool Matches(object actual)\r
34         {\r
35             this.actual = actual;\r
36 \r
37             return Object.ReferenceEquals(expected,actual);\r
38         }\r
39 \r
40         /// <summary>\r
41         /// Write the constraint description to a MessageWriter\r
42         /// </summary>\r
43         /// <param name="writer">The writer on which the description is displayed</param>\r
44         public override void WriteDescriptionTo(MessageWriter writer)\r
45         {\r
46             writer.WritePredicate("same as");\r
47             writer.WriteExpectedValue(expected);\r
48         }\r
49     }\r
50 }\r