<PackageReference Include="NUnit" Version="4.3.2" />

IEqualWithUsingConstraintExtensions

Allows specifying a custom comparer for the EqualConstraint.
using NUnit.Framework.Constraints; using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; namespace NUnit.Framework { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public static class IEqualWithUsingConstraintExtensions { public static EqualUsingConstraint<TExpected> Using<[System.Runtime.CompilerServices.Nullable(2)] TExpected>(this IEqualWithUsingConstraint<TExpected> constraint, Func<TExpected, TExpected, bool> comparer) { return new EqualUsingConstraint<TExpected>(constraint.Expected, comparer); } public static EqualUsingConstraint<TExpected> Using<[System.Runtime.CompilerServices.Nullable(2)] TExpected>(this IEqualWithUsingConstraint<TExpected> constraint, IEqualityComparer<TExpected> comparer) { return new EqualUsingConstraint<TExpected>(constraint.Expected, comparer); } public static EqualUsingConstraint<TExpected> Using<[System.Runtime.CompilerServices.Nullable(2)] TExpected>(this IEqualWithUsingConstraint<TExpected> constraint, IComparer<TExpected> comparer) { return new EqualUsingConstraint<TExpected>(constraint.Expected, comparer); } public static EqualUsingConstraint<TExpected> Using<[System.Runtime.CompilerServices.Nullable(2)] TExpected>(this IEqualWithUsingConstraint<TExpected> constraint, Comparison<TExpected> comparer) { return new EqualUsingConstraint<TExpected>(constraint.Expected, comparer); } public static EqualUsingConstraint<TExpected> Using<[System.Runtime.CompilerServices.Nullable(2)] TActual, [System.Runtime.CompilerServices.Nullable(2)] TExpected>(this IEqualWithUsingConstraint<TExpected> constraint, Func<TActual, TExpected, bool> comparer) { return new EqualUsingConstraint<TExpected>(constraint.Expected, (Func<object, object, bool>)((object x, object y) => comparer((TActual)x, (TExpected)y))); } public static EqualUsingConstraint<TExpected> Using<[System.Runtime.CompilerServices.Nullable(2)] TActual, [System.Runtime.CompilerServices.Nullable(2)] TExpected>(this IEqualWithUsingConstraint<TExpected> constraint, IComparer<TActual> comparer) { return new EqualUsingConstraint<TExpected>(constraint.Expected, (Func<object, object, bool>)((object x, object y) => comparer.Compare((TActual)x, (TActual)y) == 0)); } public static EqualUsingConstraint<TExpected> Using<[System.Runtime.CompilerServices.Nullable(2)] TExpected>(this IEqualWithUsingConstraint<TExpected> constraint, IEqualityComparer comparer) { return new EqualUsingConstraint<TExpected>(constraint.Expected, comparer); } public static EqualUsingConstraint<TExpected> Using<[System.Runtime.CompilerServices.Nullable(2)] TExpected>(this IEqualWithUsingConstraint<TExpected> constraint, IComparer comparer) { return new EqualUsingConstraint<TExpected>(constraint.Expected, comparer); } } }