public StringArrayAssertions BeEqualTo <TExpected>(TExpected expected, bool ignoreCase = false) where TExpected : IEnumerable <string> { if (Actual is null) { if (expected is not null) { throw new EqualToAssertionException <string[]?, TExpected>(Actual, expected); } } else { if (expected is null) { throw new EqualToAssertionException <string[], TExpected?>(Actual, expected); } var(result, index, actualItem, expectedItem) = Actual.Compare(expected); switch (result) { case EqualityResult.NotEqualAtIndex: { if (actualItem is not null && expectedItem is not null) { var(_, stringIndex) = actualItem !.Compare(expectedItem !, ignoreCase); var(line, character) = actualItem.IndexToLineCharacter(stringIndex); throw new StringEqualToAssertionException( actualItem, expectedItem, stringIndex, $"Arrays differ at index {index}, in line {line} character {character}."); }
public ArrayAssertions <TActualItem> BeEqualTo <TExpected, TExpectedItem>(TExpected expected, Func <TActualItem, TExpectedItem, bool> comparer) where TExpected : IEnumerable <TExpectedItem> { if (Actual is null) { if (expected is not null) { throw new EqualToAssertionException <TActualItem[], TExpected>(Actual, expected); } } else { if (expected is null) { throw new EqualToAssertionException <TActualItem[], TExpected>(Actual, expected); } var(result, index, _, _) = Actual.Compare <TActualItem, TExpected, TExpectedItem>(expected, comparer); switch (result) { case EqualityResult.NotEqualAtIndex: throw new EqualToAssertionException <TActualItem[], TExpected>( Actual, expected, $"Arrays differ at index {index}."); case EqualityResult.LessItem: throw new EqualToAssertionException <TActualItem[], TExpected>( Actual, expected, $"Actual array has less items."); case EqualityResult.MoreItems: throw new EqualToAssertionException <TActualItem[], TExpected>( Actual, expected, $"Actual array has more items."); } } return(this); }