Exemplo n.º 1
0
        /// <param name="expected">        the expected value </param>
        /// <param name="typeAdapter">     the body type adaptor </param>
        /// <param name="formatter">       the formatter
        ///                        the value determining whether the content should be rendered
        ///                        as a collapseable section. </param>
        /// <param name="minLenForToggle"> the value determining whether the content should be rendered
        ///                        as a collapseable section. </param>
        /// <returns> the formatted content for a cell with a right expectation </returns>
        public static string makeContentForRightCell <T1>(string expected, RestDataTypeAdapter typeAdapter,
                                                          ICellFormatter <T1> formatter, int minLenForToggle)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(HtmlTools.toHtml(expected));
            string actual = typeAdapter.ToString();

            if (formatter.DisplayActual && !expected.Equals(actual))
            {
                sb.Append(HtmlTools.toHtml("\n"));
                sb.Append(formatter.label("expected"));
                sb.Append(HtmlTools.toHtml("-----"));
                sb.Append(HtmlTools.toHtml("\n"));
                if (minLenForToggle >= 0 && actual.Length > minLenForToggle)
                {
                    sb.Append(makeToggleCollapseable("toggle actual", HtmlTools.toHtml(actual)));
                }
                else
                {
                    sb.Append(HtmlTools.toHtml(actual));
                }
                sb.Append(HtmlTools.toHtml("\n"));
                sb.Append(formatter.label("actual"));
            }
            return(sb.ToString());
        }
Exemplo n.º 2
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)"));
        }
Exemplo n.º 3
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) "));
        }
Exemplo n.º 4
0
        public override void DoCells(Parse parse)
        {
            if (restFixture == null)
            {
                restFixture        = new CommonRestFixture <Parse>(this.Symbols);
                restFixture.Config = Config.getConfig(ConfigNameFromArgs);
                string url = BaseUrlFromArgs;
                if (url != null)
                {
                    restFixture.BaseUrl = new Url(HtmlTools.fromSimpleTag(url));
                }
                restFixture.initialize(Runner.FIT);
                ((FitFormatter)restFixture.Formatter).ActionFixtureDelegate = this;
            }
            IRowWrapper <Parse> currentRow = new FitRow(parse);

            try
            {
                restFixture.Formatter.DisplayActual = restFixture.displayActualOnRight;
                restFixture.processRow(currentRow);
            }
            catch (Exception exception)
            {
                // TODO: Sort out CellWrapper vs CellWrapper<Parse>.
                ICellWrapper <Parse> firstCell = currentRow.getCell(0);
                LOG.Error(exception, "Exception when processing row {0}", firstCell.text());
                ICellFormatter <Parse> cellFormatter = restFixture.Formatter;
                cellFormatter.exception(firstCell, exception);
            }
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
        /// <param name="expected">        the expected value </param>
        /// <param name="typeAdapter">     the body adapter for the cell </param>
        /// <param name="formatter">       the formatter </param>
        /// <param name="minLenForToggle"> the value determining whether the content should be rendered
        ///                        as a collapseable section. </param>
        /// <returns> the formatted content for a cell with a wrong expectation </returns>
        public static string makeContentForWrongCell <T1>(string expected, RestDataTypeAdapter typeAdapter,
                                                          ICellFormatter <T1> formatter, int minLenForToggle)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(HtmlTools.toHtml(expected));
            if (formatter.DisplayActual)
            {
                sb.Append(HtmlTools.toHtml("\n"));
                sb.Append(formatter.label("expected"));
                string actual = typeAdapter.ToString();
                sb.Append(HtmlTools.toHtml("-----"));
                sb.Append(HtmlTools.toHtml("\n"));
                if (minLenForToggle >= 0 && actual.Length > minLenForToggle)
                {
                    sb.Append(makeToggleCollapseable("toggle actual", HtmlTools.toHtml(actual)));
                }
                else
                {
                    sb.Append(HtmlTools.toHtml(actual));
                }
                sb.Append(HtmlTools.toHtml("\n"));
                sb.Append(formatter.label("actual"));
            }
            IReadOnlyList <string> errors = typeAdapter.Errors;

            if (errors.Count > 0)
            {
                sb.Append(HtmlTools.toHtml("-----"));
                sb.Append(HtmlTools.toHtml("\n"));
                foreach (string e in errors)
                {
                    sb.Append(HtmlTools.toHtml(e + "\n"));
                }
                sb.Append(HtmlTools.toHtml("\n"));
                sb.Append(formatter.label("errors"));
            }
            return(sb.ToString());
        }
Exemplo n.º 7
0
        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)"));
        }
Exemplo n.º 8
0
        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)"));
        }
 internal JiraConverter(IExtendedJiraFeatureModel extendedFeatures)
 {
     _extendedFeatures = extendedFeatures;
       _cellFormatter = new CellFormatter();
 }
 public MarkdownConverter()
 {
     _cellFormatter = new CellFormatter();
 }
 internal LatexConverter(IExtendedLatexFeaturesModel extendedFeatures)
 {
     _cellFormatter = new AllStylesCellFormatter();
       _extendedFeatures = extendedFeatures;
 }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
 internal LatexConverter(IExtendedLatexFeaturesModel extendedFeatures)
 {
     _cellFormatter    = new AllStylesCellFormatter();
     _extendedFeatures = extendedFeatures;
 }
Exemplo n.º 14
0
 public MarkdownConverter()
 {
     _cellFormatter = new CellFormatter();
 }
 internal JiraConverter(IExtendedJiraFeatureModel extendedFeatures)
 {
     _extendedFeatures = extendedFeatures;
     _cellFormatter    = new CellFormatter();
 }