예제 #1
0
        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());
        }
예제 #2
0
        public static string GetAssertMessage <T>(IEnumerable <T> expected, IEnumerable <T> actual, IEqualityComparer <T> comparer = null, Func <T, string> toString = null, string separator = ",\r\n")
        {
            if (toString == null)
            {
                toString = new Func <T, string>(obj => obj.ToString());
            }

            var message = new StringBuilder();

            message.AppendLine();
            message.AppendLine("Actual:");
            message.AppendLine(string.Join(separator, actual.Select(toString)));
            message.AppendLine("Differences:");
            message.AppendLine(DiffUtil.DiffReport(expected, actual, comparer, toString, separator));
            return(message.ToString());
        }