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
9 namespace NUnit.Framework.Constraints
\r
12 /// SameAsConstraint tests whether an object is identical to
\r
13 /// the object passed to its constructor
\r
15 public class SameAsConstraint : Constraint
\r
17 private object expected;
\r
20 /// Initializes a new instance of the <see cref="T:SameAsConstraint"/> class.
\r
22 /// <param name="expected">The expected object.</param>
\r
23 public SameAsConstraint(object expected)
\r
25 this.expected = expected;
\r
29 /// Test whether the constraint is satisfied by a given value
\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
35 this.actual = actual;
\r
37 return Object.ReferenceEquals(expected,actual);
\r
41 /// Write the constraint description to a MessageWriter
\r
43 /// <param name="writer">The writer on which the description is displayed</param>
\r
44 public override void WriteDescriptionTo(MessageWriter writer)
\r
46 writer.WritePredicate("same as");
\r
47 writer.WriteExpectedValue(expected);
\r