a575963da9
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
// ****************************************************************
|
|
// Copyright 2007, Charlie Poole
|
|
// This is free software licensed under the NUnit license. You may
|
|
// obtain a copy of the license at http://nunit.org/?p=license&r=2.4
|
|
// ****************************************************************
|
|
|
|
using System;
|
|
|
|
namespace NUnit.Framework.Constraints
|
|
{
|
|
/// <summary>
|
|
/// SameAsConstraint tests whether an object is identical to
|
|
/// the object passed to its constructor
|
|
/// </summary>
|
|
public class SameAsConstraint : Constraint
|
|
{
|
|
private object expected;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="T:SameAsConstraint"/> class.
|
|
/// </summary>
|
|
/// <param name="expected">The expected object.</param>
|
|
public SameAsConstraint(object expected)
|
|
{
|
|
this.expected = expected;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test whether the constraint is satisfied by a given value
|
|
/// </summary>
|
|
/// <param name="actual">The value to be tested</param>
|
|
/// <returns>True for success, false for failure</returns>
|
|
public override bool Matches(object actual)
|
|
{
|
|
this.actual = actual;
|
|
|
|
return Object.ReferenceEquals(expected,actual);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Write the constraint description to a MessageWriter
|
|
/// </summary>
|
|
/// <param name="writer">The writer on which the description is displayed</param>
|
|
public override void WriteDescriptionTo(MessageWriter writer)
|
|
{
|
|
writer.WritePredicate("same as");
|
|
writer.WriteExpectedValue(expected);
|
|
}
|
|
}
|
|
}
|