Example #1
0
        public void WriteXml(XmlWriter writer)
        {
            if (writer == null || !this.IsValid)
            {
                return;
            }

            // <result version="" date="">
            //  <category label="" total="0" unknowns="0" failures="0" successes="0" partials="0"/>
            //  <category label="" total="0" unknowns="0" failures="0" successes="0" partials="0"/>
            // </result>
            writer.WriteStartElement("result");
            writer.WriteAttributeString("version", _version);
            writer.WriteAttributeString("date", XmlConvert.ToString(_date, XmlDateTimeSerializationMode.RoundtripKind));

            for (int i = 0; i < _categories.Count; i++)
            {
                SvgTestCategory category = _categories[i];
                if (category != null && category.IsValid)
                {
                    category.WriteXml(writer);
                }
            }

            writer.WriteEndElement();
        }
Example #2
0
 public bool IsEqualTo(SvgTestCategory other)
 {
     if (other == null)
     {
         return(false);
     }
     if (!string.Equals(_label, other._label))
     {
         return(false);
     }
     if (_total != other._total)
     {
         return(false);
     }
     if (_unknowns != other._unknowns)
     {
         return(false);
     }
     if (_failures != other._failures)
     {
         return(false);
     }
     if (_successes != other._successes)
     {
         return(false);
     }
     if (_partials != other._partials)
     {
         return(false);
     }
     return(true);
 }
Example #3
0
        public void ReadXml(XmlReader reader)
        {
            if (reader == null || reader.NodeType != XmlNodeType.Element)
            {
                return;
            }
            if (!string.Equals(reader.Name, "result", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            if (_categories == null | _categories.Count != 0)
            {
                _categories = new List <SvgTestCategory>();
            }

            // <result version="" date="">
            //  <category label="" total="0" unknowns="0" failures="0" successes="0" partials="0"/>
            //  <category label="" total="0" unknowns="0" failures="0" successes="0" partials="0"/>
            // </result>
            string version = reader.GetAttribute("version");
            string date    = reader.GetAttribute("date");

            if (!string.IsNullOrWhiteSpace(version) && !string.IsNullOrWhiteSpace(date))
            {
                _version = version;
                _date    = XmlConvert.ToDateTime(date, XmlDateTimeSerializationMode.RoundtripKind);

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (string.Equals(reader.Name, "category", StringComparison.OrdinalIgnoreCase))
                        {
                            SvgTestCategory category = new SvgTestCategory(reader);
                            if (category.IsValid)
                            {
                                _categories.Add(category);
                            }
                        }
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        if (string.Equals(reader.Name, "result", StringComparison.OrdinalIgnoreCase))
                        {
                            break;
                        }
                    }
                }
            }
        }
Example #4
0
 public static bool AreEqual(SvgTestCategory left, SvgTestCategory right)
 {
     if (left == null && right == null)
     {
         return(true);
     }
     if (left == null && right != null)
     {
         return(false);
     }
     if (left != null && right == null)
     {
         return(false);
     }
     return(left.IsEqualTo(right));
 }
Example #5
0
        public bool IsEqualTo(SvgTestResult other)
        {
            if (other == null)
            {
                return(false);
            }
            if (!string.Equals(this._version, other._version))
            {
                return(false);
            }
            if (this._categories == null && other._categories == null)
            {
                return(true);
            }
            if (this._categories == null && other._categories != null)
            {
                return(false);
            }
            if (this._categories != null && other._categories == null)
            {
                return(false);
            }
            if (this._categories.Count != other._categories.Count)
            {
                return(false);
            }

            int itemCount = _categories.Count;

            for (int i = 0; i < itemCount; i++)
            {
                if (!SvgTestCategory.AreEqual(this._categories[i], other._categories[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #6
0
        private Table CreateSummaryTable()
        {
            int resultCount = _testResults.Count;

            Table summaryTable = new Table();

            summaryTable.CellSpacing     = 0;
            summaryTable.BorderBrush     = Brushes.Gray;
            summaryTable.BorderThickness = new Thickness(1);
            summaryTable.Margin          = new Thickness(16, 0, 16, 16);

            TableColumn categoryCol = new TableColumn();

            categoryCol.Width = new GridLength(2, GridUnitType.Star);
            summaryTable.Columns.Add(categoryCol);

            TableColumn totalCol = new TableColumn();

            totalCol.Width = new GridLength(1, GridUnitType.Star);
            summaryTable.Columns.Add(totalCol);

            for (int i = 0; i < resultCount; i++)
            {
                TableColumn successCol = new TableColumn();
                successCol.Width = new GridLength(1, GridUnitType.Star);
                summaryTable.Columns.Add(successCol);
            }

            TableRowGroup headerGroup = new TableRowGroup();

            headerGroup.Background = Brushes.LightGray;
            TableRow headerRow = new TableRow();

            headerRow.Cells.Add(CreateHeaderCell("Category", false, false));
            headerRow.Cells.Add(CreateHeaderCell("Total", false, false));

            for (int i = 0; i < resultCount; i++)
            {
                SvgTestResult testResult = _testResults[i];
                headerRow.Cells.Add(CreateHeaderCellEx(testResult.Version,
                                                       (i == (resultCount - 1)), false));
            }

            headerGroup.Rows.Add(headerRow);
            summaryTable.RowGroups.Add(headerGroup);

            int[] successValues = new int[resultCount];
            int   totalValue    = 0;

            // Start with color of newer vesions
            Brush[] changedBrushes =
            {
                Brushes.LightCyan,
                Brushes.LightGoldenrodYellow,
                Brushes.LightGreen,
                Brushes.LightSalmon,
                Brushes.LightSeaGreen,  // Version 1.2
                Brushes.LightSkyBlue,   // Version 1.1
                Brushes.LightPink,
                Brushes.LightSteelBlue,
                Brushes.LightSkyBlue,
                Brushes.LightSkyBlue
            };

            for (int k = 0; k < _categoryLabels.Count; k++)
            {
                TableRowGroup resultGroup = new TableRowGroup();
                TableRow      resultRow   = new TableRow();

                bool lastBottom = (k == (_categoryLabels.Count - 1));

                resultRow.Cells.Add(CreateCell(_categoryLabels[k], false, lastBottom));

                for (int i = 0; i < resultCount; i++)
                {
                    SvgTestResult testResult = _testResults[i];

                    IList <SvgTestCategory> testCategories = testResult.Categories;

                    SvgTestCategory testCategory = testCategories[k];
                    if (!testCategory.IsValid)
                    {
                        continue;
                    }

                    int total = testCategory.Total;

                    if (i == 0)
                    {
                        resultRow.Cells.Add(CreateCell(total, false, lastBottom));
                    }

                    successValues[i] = testCategory.Successes;
                    totalValue       = total;
                    bool lastRight = (i == (resultCount - 1));

                    double percentValue = Math.Round(testCategory.Successes * 100.0d / total, 2);

                    resultRow.Cells.Add(CreateCell(percentValue.ToString("00.00"),
                                                   lastRight, lastBottom, false, false));
                }

                int cellCount = resultRow.Cells.Count;
                if (IsAllZero(successValues))
                {
                    for (int i = 1; i < cellCount; i++)
                    {
                        resultRow.Cells[i].Background = Brushes.PaleVioletRed;
                    }
                }
                else if (IsAllDone(successValues, totalValue))
                {
                    for (int i = 1; i < cellCount; i++)
                    {
                        resultRow.Cells[i].Background = Brushes.Silver;
                    }
                }
                else
                {
                    if (IsNowDone(successValues, totalValue))
                    {
                        for (int i = 1; i < cellCount; i++)
                        {
                            resultRow.Cells[i].Background = Brushes.Silver;
                        }
                    }

                    if (resultCount > 1)
                    {
                        int i = 0;
                        for (int j = (resultCount - 1); j >= 1; j--)
                        {
                            var selectedBrush = changedBrushes[i];

                            i++;
                            if (IsBetterResult(successValues, j))
                            {
                                resultRow.Cells[cellCount - i].Background = selectedBrush;
                            }
                        }
                    }
                }

                resultGroup.Rows.Add(resultRow);
                summaryTable.RowGroups.Add(resultGroup);
            }

            return(summaryTable);
        }
Example #7
0
        private Table CreateResultTable(IList <SvgTestCategory> testCategories)
        {
            Table resultTable = new Table();

            resultTable.CellSpacing     = 0;
            resultTable.BorderBrush     = Brushes.Gray;
            resultTable.BorderThickness = new Thickness(1);
            resultTable.Margin          = new Thickness(16, 0, 16, 16);

            TableColumn categoryCol = new TableColumn();
            TableColumn failureCol  = new TableColumn();
            TableColumn successCol  = new TableColumn();
            TableColumn partialCol  = new TableColumn();
            TableColumn unknownCol  = new TableColumn();
            TableColumn totalCol    = new TableColumn();

            categoryCol.Width = new GridLength(2, GridUnitType.Star);
            failureCol.Width  = new GridLength(1, GridUnitType.Star);
            successCol.Width  = new GridLength(1, GridUnitType.Star);
            partialCol.Width  = new GridLength(1, GridUnitType.Star);
            unknownCol.Width  = new GridLength(1, GridUnitType.Star);
            totalCol.Width    = new GridLength(1, GridUnitType.Star);

            resultTable.Columns.Add(categoryCol);
            resultTable.Columns.Add(failureCol);
            resultTable.Columns.Add(successCol);
            resultTable.Columns.Add(partialCol);
            resultTable.Columns.Add(unknownCol);
            resultTable.Columns.Add(totalCol);

            TableRowGroup headerGroup = new TableRowGroup();

            headerGroup.Background = Brushes.LightGray;
            TableRow headerRow = new TableRow();

            headerRow.Cells.Add(CreateHeaderCell("Category", false, false));
            headerRow.Cells.Add(CreateHeaderCell("Failure", false, false));
            headerRow.Cells.Add(CreateHeaderCell("Success", false, false));
            headerRow.Cells.Add(CreateHeaderCell("Partial", false, false));
            headerRow.Cells.Add(CreateHeaderCell("Unknown", false, false));
            headerRow.Cells.Add(CreateHeaderCell("Total", true, false));

            headerGroup.Rows.Add(headerRow);
            resultTable.RowGroups.Add(headerGroup);

            for (int i = 0; i < testCategories.Count; i++)
            {
                SvgTestCategory testCategory = testCategories[i];
                if (!testCategory.IsValid)
                {
                    continue;
                }

                TableRowGroup resultGroup = new TableRowGroup();
                TableRow      resultRow   = new TableRow();

                bool lastBottom = (i == (testCategories.Count - 1));

                resultRow.Cells.Add(CreateCell(testCategory.Label, false, lastBottom));
                resultRow.Cells.Add(CreateCell(testCategory.Failures, false, lastBottom));
                resultRow.Cells.Add(CreateCell(testCategory.Successes, false, lastBottom));
                resultRow.Cells.Add(CreateCell(testCategory.Partials, false, lastBottom));
                resultRow.Cells.Add(CreateCell(testCategory.Unknowns, false, lastBottom));
                resultRow.Cells.Add(CreateCell(testCategory.Total, true, lastBottom));

                resultGroup.Rows.Add(resultRow);
                resultTable.RowGroups.Add(resultGroup);
            }

            return(resultTable);
        }