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

EqualStringWithoutUsingConstraint

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 NUnit.Framework.Constraints.Comparers; using System.Runtime.CompilerServices; using System.Text; namespace NUnit.Framework.Constraints { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public class EqualStringWithoutUsingConstraint : Constraint { [System.Runtime.CompilerServices.Nullable(2)] private readonly string _expected; private bool _caseInsensitive; private bool _ignoringWhiteSpace; private bool _clipStrings; [System.Runtime.CompilerServices.Nullable(2)] public string Expected { [System.Runtime.CompilerServices.NullableContext(2)] get { return _expected; } } public EqualStringWithoutUsingConstraint IgnoreCase { get { _caseInsensitive = true; return this; } } public EqualStringWithoutUsingConstraint IgnoreWhiteSpace { get { _ignoringWhiteSpace = true; return this; } } public EqualStringWithoutUsingConstraint NoClip { get { _clipStrings = false; return this; } } public override string Description { get { StringBuilder stringBuilder = new StringBuilder(MsgUtils.FormatValue(_expected)); if (_caseInsensitive) stringBuilder.Append(", ignoring case"); if (_ignoringWhiteSpace) stringBuilder.Append(", ignoring white-space"); return stringBuilder.ToString(); } } [System.Runtime.CompilerServices.NullableContext(2)] public EqualStringWithoutUsingConstraint(string expected) : base(expected) { _expected = expected; _clipStrings = true; } public ConstraintResult ApplyTo([System.Runtime.CompilerServices.Nullable(2)] string actual) { bool hasSucceeded = (actual == null) ? (_expected == null) : (_expected != null && StringsComparer.Equals(_expected, actual, _caseInsensitive, _ignoringWhiteSpace)); return ConstraintResult(actual, hasSucceeded); } public sealed override ConstraintResult ApplyTo<[System.Runtime.CompilerServices.Nullable(2)] TActual>(TActual actual) { bool hasSucceeded; if (actual == null) hasSucceeded = (_expected == null); else { if (_expected != null) return ApplyTo(actual as string); hasSucceeded = false; } return ConstraintResult(actual, hasSucceeded); } private ConstraintResult ConstraintResult<[System.Runtime.CompilerServices.Nullable(2)] T>(T actual, bool hasSucceeded) { return new EqualConstraintResult(this, actual, _caseInsensitive, _ignoringWhiteSpace, _clipStrings, hasSucceeded); } } }