コード例 #1
0
        public void Build_EmptyAndNullAreDifferent_CorrectDisplay()
        {
            // Design Dummy Column
            DataColumn col = new DataColumn("DummyColumn");

            col.ExtendedProperties.Add("NBi::Role", ColumnRole.Key);
            col.ExtendedProperties.Add("NBi::Type", ColumnType.Text);

            // Design dummy table
            DataTable table = new DataTable();

            table.Columns.Add(col);

            var row = table.NewRow();

            row[0] = string.Empty;
            row.SetColumnError(0, "(null)");

            ICellFormatter cf = LineFormatter.Build(row, 0);

            // This must not throw an exception when the header is bigger that requested size
            var text = cf.GetText(20);

            Assert.That(text, Is.StringContaining("(empty)"));
            Assert.That(text, Is.StringContaining("<>"));
            Assert.That(text, Is.StringContaining("(null)"));
        }
コード例 #2
0
        public void Build_ColumnWithName_CorrectDisplay()
        {
            // Design Dummy Column
            DataColumn col = new DataColumn("DummyColumn");

            col.ExtendedProperties.Add("NBi::Role", ColumnRole.Key);
            col.ExtendedProperties.Add("NBi::Type", ColumnType.Text);
            col.ColumnName = "My very long name that I want to display!";

            // Design dummy table
            DataTable table = new DataTable();

            table.Columns.Add(col);

            var row = table.NewRow();

            row[0] = "My Value";
            row.SetColumnError(0, "(null)");

            ICellFormatter cf = LineFormatter.BuildHeader(table, 0);

            var length = cf.GetCellLength();
            var name   = cf.GetColumnName(length);

            Assert.That(name, Is.EqualTo("My very long name that I want to display! "));

            // This should be the returned value
            var text = cf.GetText(length);

            Assert.That(text, Is.StringStarting("KEY (Text) "));
        }
コード例 #3
0
        public void GetText_ShortColumn_NoException()
        {
            // Design Dummy Column
            DataColumn col = new DataColumn("DummyColumn");

            col.ExtendedProperties.Add("NBi::Role", ColumnRole.Key);
            col.ExtendedProperties.Add("NBi::Type", ColumnType.Numeric);

            // Design dummy table
            DataTable table = new DataTable();

            table.Columns.Add(col);

            ICellFormatter cf = LineFormatter.BuildHeader(table, 0);

            // This must not throw an exception when the header is bigger that requested size
            cf.GetText(4);
            Assert.Pass();
        }
コード例 #4
0
ファイル: LineFormatterTest.cs プロジェクト: zyh329/nbi
        public void GetText_DateTimeTolerance_CorrectHeader()
        {
            // Design Dummy Column
            DataColumn col = new DataColumn("DummyColumn");

            col.ExtendedProperties.Add("NBi::Role", ColumnRole.Value);
            col.ExtendedProperties.Add("NBi::Type", ColumnType.Numeric);
            col.ExtendedProperties.Add("NBi::Tolerance", new DateTimeTolerance(new TimeSpan(0, 15, 0)));

            // Design dummy table
            DataTable table = new DataTable();

            table.Columns.Add(col);

            ICellFormatter cf = LineFormatter.BuildHeader(table, 0);

            // This must not throw an exception when the header is bigger that requested size
            var text = cf.GetText(cf.GetCellLength());

            Assert.That(text, Is.StringContaining("VALUE"));
            Assert.That(text, Is.StringContaining("Numeric"));
            Assert.That(text, Is.StringContaining("(+/- 00:15:00)"));
        }
コード例 #5
0
ファイル: LineFormatterTest.cs プロジェクト: zyh329/nbi
        public void GetText_NumericRounding_CorrectHeader()
        {
            // Design Dummy Column
            DataColumn col = new DataColumn("DummyColumn");

            col.ExtendedProperties.Add("NBi::Role", ColumnRole.Value);
            col.ExtendedProperties.Add("NBi::Type", ColumnType.Numeric);
            col.ExtendedProperties.Add("NBi::Rounding", new NumericRounding(10.5, Rounding.RoundingStyle.Round));

            // Design dummy table
            DataTable table = new DataTable();

            table.Columns.Add(col);

            ICellFormatter cf = LineFormatter.BuildHeader(table, 0);

            // This must not throw an exception when the header is bigger that requested size
            var text = cf.GetText(cf.GetCellLength());

            Assert.That(text, Is.StringContaining("VALUE"));
            Assert.That(text, Is.StringContaining("Numeric"));
            Assert.That(text, Is.StringContaining("(round 10.5)"));
        }
コード例 #6
0
ファイル: ResultSetTextWriter.cs プロジェクト: zyh329/nbi
        public virtual IEnumerable <string> BuildContent(IEnumerable <DataRow> rows, int rowCount, bool compare)
        {
            var output = new List <string>();

            //Empty resultset

            if (rows.Count() == 0)
            {
                output.Add("This result set is empty.");
                return(output);
            }

            //calculate row count to diplay
            int         maxRows     = (rowCount <= Math.Min(rows.Count(), MAX_ROWS_DISPLAYED)) ? rowCount : Math.Min(rows.Count(), MAX_ROWS_DISPLAYED);
            var         subsetRows  = rows.Take(maxRows);
            IList <int> fieldLength = GetFieldsLength(subsetRows);

            //information about #Rows and #Cols
            var sbInfo = new System.Text.StringBuilder();

            sbInfo.AppendFormat("ResultSet with {0} row", rowCount);
            if (rowCount > 1)
            {
                sbInfo.Append('s');
            }
            output.Add(sbInfo.ToString());


            //separator
            output.Add(GetFirstIndentation() + GetSeparator(fieldLength));

            //header
            var sbHeader = new System.Text.StringBuilder();

            sbHeader.Append(' ', 4);
            for (int i = 0; i < fieldLength.Count; i++)
            {
                var displayHeader = LineFormatter.BuildHeader(rows.ElementAt(0).Table, i);
                if (displayHeader != null)
                {
                    sbHeader.AppendFormat("| {0} ", displayHeader.GetText(fieldLength[i]));
                }
            }
            sbHeader.Append("|");
            output.Add(sbHeader.ToString());

            //separator
            output.Add(GetFirstIndentation() + GetSeparator(fieldLength));

            //TestCases
            for (int i = 0; i < maxRows; i++)
            {
                var sbRow = new System.Text.StringBuilder();

                sbRow.Append(GetFirstIndentation());
                for (int j = 0; j < subsetRows.ElementAt(i).ItemArray.Count(); j++)
                {
                    ICellFormatter display = null;
                    if (compare)
                    {
                        display = LineFormatter.Build(rows.ElementAt(i), j);
                    }
                    else
                    {
                        display = LineFormatter.BuildValue(rows.ElementAt(i), j);
                    }
                    sbRow.AppendFormat("| {0} ", display.GetText(fieldLength[j]));
                }
                sbRow.Append("|");
                output.Add(sbRow.ToString());
            }

            //footer (separator)
            output.Add(GetFirstIndentation() + GetSeparator(fieldLength));


            //If needed display # skipped rows
            if (rowCount > MAX_ROWS_DISPLAYED)
            {
                var sbSkip = new System.Text.StringBuilder();
                sbSkip.AppendFormat(GetFirstIndentation());
                sbSkip.Append(new string('.', 3));
                sbSkip.Append(new string(' ', 3));
                sbSkip.AppendFormat("{0} (of {1}) rows skipped for display purpose", rowCount - MAX_ROWS_DISPLAYED, rowCount);
                sbSkip.Append(new string(' ', 3));
                sbSkip.Append(new string('.', 3));
                output.Add(sbSkip.ToString());
            }

            output.Add("");

            return(output);
        }