EachItemConstraintResult
Provides a ConstraintResult for the constraints
that are applied to each item in the collection
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Constraints
{
[NullableContext(1)]
[Nullable(0)]
internal sealed class EachItemConstraintResult : ConstraintResult
{
private readonly object _nonMatchingItem;
private readonly int _nonMatchingItemIndex;
public EachItemConstraintResult(IConstraint constraint, [Nullable(2)] object actualValue, object nonMatchingItem, int nonMatchingIndex)
: base(constraint, actualValue, false)
{
_nonMatchingItem = nonMatchingItem;
_nonMatchingItemIndex = nonMatchingIndex;
}
public override void WriteAdditionalLinesTo(MessageWriter writer)
{
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(40, 1);
defaultInterpolatedStringHandler.AppendLiteral(" First non-matching item at index [");
defaultInterpolatedStringHandler.AppendFormatted(_nonMatchingItemIndex);
defaultInterpolatedStringHandler.AppendLiteral("]: ");
string value = defaultInterpolatedStringHandler.ToStringAndClear() + MsgUtils.FormatValue(_nonMatchingItem);
writer.WriteLine(value);
}
}
}