EqualConstraint<T>
EqualConstraint is able to compare an actual value with the
expected value provided in its constructor. Two objects are
considered equal if both are null, or if both have the same
value. NUnit has special semantics for some object types.
using System;
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Constraints
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class EqualConstraint<[System.Runtime.CompilerServices.Nullable(2)] T> : EqualConstraint
{
[System.Runtime.CompilerServices.NullableContext(2)]
public EqualConstraint(object expected)
: base(expected)
{
}
public EqualConstraint UsingPropertiesComparer(Func<PropertiesComparerConfiguration<T>, PropertiesComparerConfiguration<T>> configure)
{
base.Comparer.CompareProperties = true;
base.Comparer.ComparePropertiesConfiguration = configure(new PropertiesComparerConfiguration<T>());
return this;
}
public override EqualConstraint UsingPropertiesComparer<[System.Runtime.CompilerServices.Nullable(2)] TParam>(Func<PropertiesComparerConfiguration<TParam>, PropertiesComparerConfiguration<TParam>> configure)
{
if (typeof(TParam) != typeof(T))
throw new ArgumentException("The type parameter " + typeof(TParam).Name + " does not match the type parameter " + typeof(T).Name + " of this constraint.", "configure");
base.Comparer.CompareProperties = true;
base.Comparer.ComparePropertiesConfiguration = configure(new PropertiesComparerConfiguration<TParam>());
return this;
}
}
}