public void TestDiffTester() { // Make sure the diff tester is working! Assert.Equal(DiffUtil.DiffReport( @"A B C D E F", @"A 1 B C E 2"), @" A ++> 1 B C --> D E ++> 2 --> F"); }
public static string GetAssertMessage <T>( IEnumerable <T> expected, IEnumerable <T> actual, IEqualityComparer <T> comparer = null, Func <T, string> itemInspector = null, string itemSeparator = null, string expectedValueSourcePath = null, int expectedValueSourceLine = 0) { if (itemInspector == null) { if (typeof(T) == typeof(byte)) { itemInspector = b => $"0x{b:X2}"; } else { itemInspector = new Func <T, string>(obj => (obj != null) ? obj.ToString() : "<null>"); } } if (itemSeparator == null) { if (typeof(T) == typeof(byte)) { itemSeparator = ", "; } else { itemSeparator = "," + Environment.NewLine; } } var expectedString = string.Join(itemSeparator, expected.Take(10).Select(itemInspector)); var actualString = string.Join(itemSeparator, actual.Select(itemInspector)); var message = new StringBuilder(); message.AppendLine(); message.AppendLine("Expected:"); message.AppendLine(expectedString); if (expected.Count() > 10) { message.AppendLine("... truncated ..."); } message.AppendLine("Actual:"); message.AppendLine(actualString); message.AppendLine("Differences:"); message.AppendLine(DiffUtil.DiffReport(expected, actual, itemSeparator, comparer, itemInspector)); if (TryGenerateExpectedSourceFileAndGetDiffLink(actualString, expected.Count(), expectedValueSourcePath, expectedValueSourceLine, out var link)) { message.AppendLine(link); } return(message.ToString()); }
public static string GetAssertMessage <T>( IEnumerable <T> expected, IEnumerable <T> actual, Func <T, T, bool> comparer = null, Func <T, string> itemInspector = null, string itemSeparator = null, string expectedValueSourcePath = null, int expectedValueSourceLine = 0) { if (itemInspector == null) { if (expected is IEnumerable <byte> ) { itemInspector = b => $"0x{b:X2}"; } else { itemInspector = new Func <T, string>(obj => (obj != null) ? obj.ToString() : "<null>"); } } if (itemSeparator == null) { if (expected is IEnumerable <byte> ) { itemSeparator = ", "; } else { itemSeparator = ",\r\n"; } } var message = new StringBuilder(); message.AppendLine(); message.AppendLine("Actual:"); message.AppendLine(string.Join(itemSeparator, actual.Select(itemInspector))); message.AppendLine(); message.AppendLine("Expected:"); message.AppendLine(string.Join(itemSeparator, expected.Select(itemInspector))); message.AppendLine(); message.AppendLine("Diff:"); message.Append(DiffUtil.DiffReport(expected, actual, comparer, itemInspector, itemSeparator)); return(message.ToString()); }