예제 #1
0
 private void AssertVersions(PackageStatus status, AnsiColor color, string wanted, string stable, string latest)
 {
     Assert.AreEqual(color, status.GetStatusColor());
     Assert.AreEqual(wanted, status.WantedVersion.ToString());
     Assert.AreEqual(stable, status.StableVersion?.ToString());
     Assert.AreEqual(latest, status.LatestVersion.ToString());
 }
예제 #2
0
        public static void DrawTable <T>(IEnumerable <T> valuesEnumerable, string[] columnHeaders, Func <T, AnsiColor> colorSelector, params Func <T, object>[] valueSelectors)
        {
            Debug.Assert(columnHeaders.Length == valueSelectors.Length);

            T[] values       = valuesEnumerable.ToArray();
            var colors       = new AnsiColor[values.Length + 1];
            var matrixValues = new string[values.Length + 1, valueSelectors.Length];

            // headers
            colors[0] = AnsiColor.White;
            for (int column = 0; column < matrixValues.GetLength(1); column++)
            {
                matrixValues[0, column] = columnHeaders[column];
            }

            // table rows
            for (int row = 1; row < matrixValues.GetLength(0); row++)
            {
                colors[row] = colorSelector.Invoke(values[row - 1]);
                for (int column = 0; column < matrixValues.GetLength(1); column++)
                {
                    matrixValues[row, column] = Convert.ToString(valueSelectors[column].Invoke(values[row - 1]));
                }
            }

            DrawStringTable(matrixValues, colors);
        }