SameAsConstraint
SameAsConstraint tests whether an object is identical to
the object passed to its constructor
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Constraints
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class SameAsConstraint : Constraint
{
[System.Runtime.CompilerServices.Nullable(2)]
private readonly object _expected;
public override string Description => "same as " + MsgUtils.FormatValue(_expected);
[System.Runtime.CompilerServices.NullableContext(2)]
public SameAsConstraint(object expected)
: base(expected)
{
_expected = expected;
}
public override ConstraintResult ApplyTo<[System.Runtime.CompilerServices.Nullable(2)] TActual>(TActual actual)
{
bool isSuccess = _expected == (object)actual;
return new ConstraintResult(this, actual, isSuccess);
}
}
}