Esempio n. 1
0
        /// <summary>
        /// Output style:
        ///   FieldName1 = FieldValue1 (tag), FieldName1 = FieldValue2 (tag)
        /// </summary>
        public static string ActualCollectionFancyTostring <T>(Table table, IEnumerable <T> actual)
        {
            StringBuilder actualStringListing = new StringBuilder();

            actualStringListing.AppendLine();
            actualStringListing.AppendLine("Actual:");

            var comparer = TableAid.ComparerCreator <T>(table);

            foreach (T record in actual)
            {
                actualStringListing.AppendLine("\t" + comparer.GetFieldEqualValueStringWithSymbolicLink(record));
            }

            actualStringListing.AppendLine();

            return(actualStringListing.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// Output style:
        ///   | FieldName1  | FieldName2  |
        ///   | FieldValue1 | FieldValue2 |
        /// </summary>
        public static string ActualCollectionWithMatchesSpecflowFancyTostring <T>(Table table, IEnumerable <T> actual, Dictionary <int, int> dataToTableRowMatches)
        {
            StringBuilder actualStringListing = new StringBuilder();

            actualStringListing.AppendLine();
            actualStringListing.AppendLine("Actual:");

            // Get Header and Column data in Property order.

            var comparer = TableAid.ComparerCreator <T>(table);

            var output = new List <List <string> >();

            output.Add(comparer.GetHeaderValuesInPropertyOrder());

            foreach (T record in actual)
            {
                output.Add(comparer.GetColumnValuesInPropertyOrder(record));
            }

            if (output.Count < 2)
            {
                return("Actual: Collection is Empty");
            }

            // Add Match List if Avalible.

            if (dataToTableRowMatches != null)
            {
                // Add Matched Column
                output[0].Insert(0, "Matches");

                for (int i = 1 /* Skip the Header*/; i < output.Count; i++)
                {
                    int zeroRelativeDataIndex = i - 1;

                    if (dataToTableRowMatches.ContainsKey(zeroRelativeDataIndex))
                    {
                        int    oneRelativeTableRowIndex = dataToTableRowMatches[zeroRelativeDataIndex] + 1;
                        string tableRowMatch            = oneRelativeTableRowIndex.ToString();
                        output[i].Insert(0, tableRowMatch);
                    }
                    else
                    {
                        // Bump the column over one
                        output[i].Insert(0, "");
                    }
                }
            }

            var numberOfTotalColumns = new int[output[0].Count];

            // Get max width of each column
            foreach (var outLine in output)
            {
                for (int i = 0; i < outLine.Count; i++)
                {
                    if (numberOfTotalColumns[i] < outLine[i].Length)
                    {
                        numberOfTotalColumns[i] = outLine[i].Length;
                    }
                }
            }

            // Create pipe delimited fixed with output
            foreach (var outLine in output)
            {
                actualStringListing.Append("\t");
                actualStringListing.Append("| ");
                for (int i = 0; i < outLine.Count; i++)
                {
                    actualStringListing.Append(outLine[i].PadRight(numberOfTotalColumns[i]));
                    actualStringListing.Append(" | ");
                }
                actualStringListing.AppendLine();
            }
            return(actualStringListing.ToString());
        }