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(this._label, other._label))
     {
         return(false);
     }
     if (this._total != other._total)
     {
         return(false);
     }
     if (this._unknowns != other._unknowns)
     {
         return(false);
     }
     if (this._failures != other._failures)
     {
         return(false);
     }
     if (this._successes != other._successes)
     {
         return(false);
     }
     if (this._partials != other._partials)
     {
         return(false);
     }
     return(true);
 }
        private string CreateResultTable(IList <SvgTestCategory> testCategories)
        {
            var resultTable = new StringBuilder();
            var tableStyle  = new StringBuilder();

            tableStyle.Append("border:1px solid gray;");
            tableStyle.AppendFormat("margin:{0}px {1}px {2}px {3}px;", 0, 16, 16, 16);
            tableStyle.Append("width:95%;");
            resultTable.AppendLine(string.Format(
                                       "<table style=\"{0}\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">", tableStyle));

            tableStyle.Length = 0;
            var headerGroup = new StringBuilder();

            tableStyle.Append("border-color:lightgray;");
            headerGroup.AppendLine(string.Format("<tr style=\"{0}\">", tableStyle));

            headerGroup.AppendLine(CreateHeaderCell("Category", false, false));
            headerGroup.AppendLine(CreateHeaderCell("Failure", false, false));
            headerGroup.AppendLine(CreateHeaderCell("Success", false, false));
            headerGroup.AppendLine(CreateHeaderCell("Partial", false, false));
            headerGroup.AppendLine(CreateHeaderCell("Unknown", false, false));
            headerGroup.AppendLine(CreateHeaderCell("Total", true, false));

            headerGroup.AppendLine("</tr>");
            resultTable.AppendLine(headerGroup.ToString());

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

                var resultGroup = new StringBuilder();
                resultGroup.AppendLine("<tr>");

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

                resultGroup.AppendLine(CreateCell(testCategory.Label, false, lastBottom));
                resultGroup.AppendLine(CreateCell(testCategory.Failures, false, lastBottom));
                resultGroup.AppendLine(CreateCell(testCategory.Successes, false, lastBottom));
                resultGroup.AppendLine(CreateCell(testCategory.Partials, false, lastBottom));
                resultGroup.AppendLine(CreateCell(testCategory.Unknowns, false, lastBottom));
                resultGroup.AppendLine(CreateCell(testCategory.Total, true, lastBottom));

                resultGroup.AppendLine("</tr>");
                resultTable.AppendLine(resultGroup.ToString());
            }

            resultTable.AppendLine("</table>");
            return(resultTable.ToString());
        }
Example #4
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 #5
0
        private void SaveTreeViewCategory(XmlWriter writer, TreeNode categoryItem, SvgTestCategory testCategory)
        {
            int total = 0, unknowns = 0, failures = 0, successes = 0, partials = 0;

            writer.WriteStartElement("category");

            writer.WriteAttributeString("label", testCategory.Label);

            TreeNodeCollection treeItems = categoryItem.Nodes;

            for (int j = 0; j < treeItems.Count; j++)
            {
                TreeNode treeItem = treeItems[j] as TreeNode;
                if (treeItem != null)
                {
                    SvgTestInfo testInfo = treeItem.Tag as SvgTestInfo;
                    if (testInfo != null)
                    {
                        testInfo.WriteXml(writer);

                        total++;
                        SvgTestState testState = testInfo.State;

                        switch (testState)
                        {
                        case SvgTestState.Unknown:
                            unknowns++;
                            break;

                        case SvgTestState.Failure:
                            failures++;
                            break;

                        case SvgTestState.Success:
                            successes++;
                            break;

                        case SvgTestState.Partial:
                            partials++;
                            break;
                        }
                    }
                }
            }

            writer.WriteEndElement();

            testCategory.SetValues(total, unknowns, failures, successes, partials);
        }
Example #6
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 #7
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 #8
0
        private void SaveTreeView(XmlWriter writer)
        {
            if (writer == null)
            {
                return;
            }

            TreeNodeCollection treeNodes = treeView.Nodes;

            if (treeNodes == null || treeNodes.Count == 0)
            {
                return;
            }

            SvgTestResult testResult = new SvgTestResult();

            writer.WriteStartDocument();
            writer.WriteStartElement("tests");

            var selectedSuite = _optionSettings.SelectedTestSuite;

            if (selectedSuite != null)
            {
                writer.WriteAttributeString("version", selectedSuite.Version);
                writer.WriteAttributeString("description", selectedSuite.Description);
            }

            for (int i = 0; i < treeNodes.Count; i++)
            {
                TreeNode categoryItem = treeNodes[i] as TreeNode;
                if (categoryItem != null)
                {
                    SvgTestCategory testCategory = new SvgTestCategory(categoryItem.Text);

                    this.SaveTreeViewCategory(writer, categoryItem, testCategory);

                    if (testCategory.IsValid)
                    {
                        testResult.Categories.Add(testCategory);
                    }
                }
            }

            writer.WriteEndElement();
            writer.WriteEndDocument();

            if (_testResults == null)
            {
                _testResults = new List <SvgTestResult>();
            }

            if (testResult.IsValid)
            {
                if (_testResults.Count == 0)
                {
                    _testResults.Add(testResult);
                }
            }
            else
            {
                int foundAt = -1;
                for (int i = 0; i < _testResults.Count; i++)
                {
                    SvgTestResult nextResult = _testResults[i];
                    if (nextResult != null && nextResult.IsValid)
                    {
                        if (string.Equals(nextResult.Version, testResult.Version))
                        {
                            foundAt = i;
                            break;
                        }
                    }
                }

                if (foundAt >= 0)
                {
                    SvgTestResult nextResult = _testResults[foundAt];

                    if (!SvgTestResult.AreEqual(nextResult, testResult))
                    {
                        _testResults[foundAt] = testResult;
                    }
                }
                else
                {
                    _testResults.Add(testResult);
                }
            }
        }
Example #9
0
        private void LoadTreeViewCategory(XmlReader reader, TreeNode categoryItem,
                                          SvgTestCategory testCategory, bool categorySelected, string selectedTest)
        {
            int total = 0, unknowns = 0, failures = 0, successes = 0, partials = 0;

            int itemCount = 0;

            var comparer = StringComparison.OrdinalIgnoreCase;

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (string.Equals(reader.Name, "test", comparer))
                    {
                        SvgTestInfo testInfo = new SvgTestInfo(reader);
                        if (!testInfo.IsEmpty)
                        {
                            testInfo.Category = testCategory.Label;

                            var      itemLabel = string.Format("({0:D3}) - {1}", itemCount, testInfo.Title);
                            TreeNode treeItem  = new TreeNode(itemLabel);
                            treeItem.ImageIndex         = testInfo.ImageIndex;
                            treeItem.SelectedImageIndex = testInfo.ImageIndex;
                            treeItem.Tag = testInfo;

                            categoryItem.Nodes.Add(treeItem);

                            if (categorySelected &&
                                string.Equals(testInfo.Title, selectedTest, comparer))
                            {
                                treeItem.Expand();

                                treeView.SelectedNode = treeItem;
                            }

                            itemCount++;

                            total++;
                            SvgTestState testState = testInfo.State;

                            switch (testState)
                            {
                            case SvgTestState.Unknown:
                                unknowns++;
                                break;

                            case SvgTestState.Failure:
                                failures++;
                                break;

                            case SvgTestState.Success:
                                successes++;
                                break;

                            case SvgTestState.Partial:
                                partials++;
                                break;
                            }
                        }
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (string.Equals(reader.Name, "category", comparer))
                    {
                        break;
                    }
                }
            }

            testCategory.SetValues(total, unknowns, failures, successes, partials);
        }
Example #10
0
        private void LoadTreeView(XmlReader reader)
        {
            SvgTestResult testResult = new SvgTestResult();

            // Suppress repainting the TreeView until all the objects have been created.
            treeView.BeginUpdate();
            // Clear the TreeView each time the method is called.
            treeView.Nodes.Clear();

            string selectedCategory = string.Empty;
            string selectedTest     = string.Empty;

            if (_optionSettings != null &&
                !string.IsNullOrWhiteSpace(_optionSettings.SelectedValuePath))
            {
                var selectedPaths = _optionSettings.SelectedValuePath.Split('/');
                if (selectedPaths != null && selectedPaths.Length == 2)
                {
                    selectedCategory = selectedPaths[0];
                    selectedTest     = selectedPaths[1];
                }
            }
            TreeNode selectedCategoryItem = null;

            var treeFont = this.treeView.Font;

            this.treeView.ItemHeight = 22;
            var categoryFont = new Font(treeFont.FontFamily, treeFont.Size + 1, FontStyle.Bold, GraphicsUnit.Pixel);

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element &&
                    string.Equals(reader.Name, "category", StringComparison.OrdinalIgnoreCase))
                {
                    // <category label="Animations">
                    string categoryLabel = reader.GetAttribute("label");
                    if (!string.IsNullOrWhiteSpace(categoryLabel))
                    {
                        SvgTestCategory testCategory = new SvgTestCategory(categoryLabel);

                        TreeNode categoryItem = new TreeNode(categoryLabel);
                        categoryItem.NodeFont           = categoryFont;
                        categoryItem.ImageIndex         = 0;
                        categoryItem.SelectedImageIndex = 0;
                        categoryItem.Tag = testCategory;

                        treeView.Nodes.Add(categoryItem);

                        bool categorySelected = false;
                        if (!string.IsNullOrWhiteSpace(selectedCategory) &&
                            selectedCategory.Equals(categoryLabel, StringComparison.OrdinalIgnoreCase))
                        {
                            selectedCategoryItem = categoryItem;
                            categorySelected     = true;
                        }
                        LoadTreeViewCategory(reader, categoryItem, testCategory, categorySelected, selectedTest);

                        if (testCategory.IsValid)
                        {
                            testResult.Categories.Add(testCategory);
                        }
                    }
                }
            }

            if (_testResults == null)
            {
                _testResults = new List <SvgTestResult>();
            }

            bool saveResults = false;

            if (testResult.IsValid)
            {
                if (_testResults.Count == 0)
                {
                    _testResults.Add(testResult);

                    saveResults = true;
                }
                else
                {
                    int foundAt = -1;
                    for (int i = 0; i < _testResults.Count; i++)
                    {
                        SvgTestResult nextResult = _testResults[i];
                        if (nextResult != null && nextResult.IsValid)
                        {
                            if (string.Equals(nextResult.Version, testResult.Version))
                            {
                                foundAt = i;
                                break;
                            }
                        }
                    }

                    if (foundAt >= 0)
                    {
                        SvgTestResult nextResult = _testResults[foundAt];

                        if (!SvgTestResult.AreEqual(nextResult, testResult))
                        {
                            _testResults[foundAt] = testResult;
                            saveResults           = true;
                        }
                    }
                    else
                    {
                        _testResults.Add(testResult);

                        saveResults = true;
                    }
                }
            }
            if (saveResults)
            {
                if (!string.IsNullOrWhiteSpace(_testResultsPath))
                {
                    string backupFile = null;
                    if (File.Exists(_testResultsPath))
                    {
                        backupFile = Path.ChangeExtension(_testResultsPath, ".bak");
                        try
                        {
                            if (File.Exists(backupFile))
                            {
                                File.Delete(backupFile);
                            }
                            File.Move(_testResultsPath, backupFile);
                        }
                        catch (Exception ex)
                        {
                            if (!string.IsNullOrWhiteSpace(backupFile) && File.Exists(backupFile))
                            {
                                File.Delete(backupFile);
                            }
                            MessageBox.Show(ex.ToString(), MainForm.AppErrorTitle,
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }

                    try
                    {
                        XmlWriterSettings settings = new XmlWriterSettings();
                        settings.Indent      = true;
                        settings.IndentChars = "    ";
                        settings.Encoding    = Encoding.UTF8;

                        using (XmlWriter writer = XmlWriter.Create(_testResultsPath, settings))
                        {
                            this.SaveTestResults(writer);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (!string.IsNullOrWhiteSpace(backupFile) && File.Exists(backupFile))
                        {
                            File.Move(backupFile, _testResultsPath);
                        }

                        MessageBox.Show(ex.ToString(), MainForm.AppErrorTitle,
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    if (!string.IsNullOrWhiteSpace(backupFile) && File.Exists(backupFile))
                    {
                        File.Delete(backupFile);
                    }
                }
            }

            if (selectedCategoryItem != null)
            {
                selectedCategoryItem.ExpandAll();
            }

            // Begin repainting the TreeView.
            treeView.EndUpdate();
            treeView.Focus();
        }
        private string CreateSummaryTable()
        {
            int resultCount = _testResults.Count;

            var summaryTable = new StringBuilder();
            var tableStyle   = new StringBuilder();

            tableStyle.Append("border:1px solid gray;");
            tableStyle.AppendFormat("margin:{0}px {1}px {2}px {3}px;", 0, 16, 16, 16);
            tableStyle.Append("width:95%;");
            summaryTable.AppendLine(string.Format(
                                        "<table style=\"{0}\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\">", tableStyle));

            tableStyle.Length = 0;
            var headerGroup = new StringBuilder();

            tableStyle.Append("border-color:lightgray;");
            headerGroup.AppendLine(string.Format("<tr style=\"{0}\">", tableStyle));

            headerGroup.AppendLine(CreateHeaderCell("Category", false, false, true));
            headerGroup.AppendLine(CreateHeaderCell("Total", false, false, true));

            for (int i = 0; i < resultCount; i++)
            {
                SvgTestResult testResult = _testResults[i];
                headerGroup.AppendLine(CreateHeaderCellEx(testResult.Version,
                                                          (i == (resultCount - 1)), false, true));
            }
            headerGroup.AppendLine("</tr>");

            summaryTable.AppendLine(headerGroup.ToString());

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

            // Start with color of newer vesions
            string[] changedBrushes =
            {
                "lightsalmon",    // Brushes.LightSalmon
                "lightseagreen",  // Brushes.LightSeaGreen  - Version 1.2
                "lightskyblue",   // Brushes.LightSkyBlue   - Version 1.1
                "lightpink",      // Brushes.LightPink
                "lightsteelblue", // Brushes.LightSteelBlue
                "lightskyblue",   // Brushes.LightSkyBlue
                "lightskyblue"    // Brushes.LightSkyBlue
            };

            for (int k = 0; k < _categoryLabels.Count; k++)
            {
                var resultCells = new List <string>();

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

                resultCells.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)
                    {
                        resultCells.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);

                    resultCells.Add(CreateCellSummary(percentValue.ToString("00.00"), lastRight, lastBottom));
                }

                int cellCount       = resultCells.Count;
                var cellBackgrounds = new string[cellCount];

                if (IsAllZero(successValues))
                {
                    for (int i = 1; i < cellCount; i++)
                    {
                        cellBackgrounds[i] = "background-color:palevioletred;"; // Brushes.PaleVioletRed;
                    }
                }
                else if (IsAllDone(successValues, totalValue))
                {
                    for (int i = 1; i < cellCount; i++)
                    {
                        cellBackgrounds[i] = "background-color:silver;"; // Brushes.Silver
                    }
                }
                else
                {
                    if (IsNowDone(successValues, totalValue))
                    {
                        for (int i = 1; i < cellCount; i++)
                        {
                            cellBackgrounds[i] = "background-color:silver;"; // Brushes.Silver
                        }
                    }

                    if (resultCount > 1)
                    {
                        int i = 0;
                        for (int j = (resultCount - 1); j >= 1; j--)
                        {
                            var selectedBrush = string.Format("background-color:{0};", changedBrushes[i]);

                            i++;
                            if (IsBetterResult(successValues, j))
                            {
                                cellBackgrounds[cellCount - i] = selectedBrush; // selectedBrush
                            }
                        }
                    }
                }

                var resultGroup = new StringBuilder();
                resultGroup.AppendLine("<tr>");
                for (int i = 0; i < cellCount; i++)
                {
                    string resultRow      = resultCells[i];
                    var    cellBackground = cellBackgrounds[i];
                    if (string.IsNullOrWhiteSpace(cellBackground))
                    {
                        resultRow = resultRow.Replace("background-color:transparent;", "");
                    }
                    else
                    {
                        resultRow = resultRow.Replace("background-color:transparent;", cellBackground);
                    }
                    resultGroup.AppendLine(resultRow);
                }
                resultGroup.AppendLine("</tr>");

                summaryTable.AppendLine(resultGroup.ToString());
            }

            summaryTable.AppendLine("</table>");
            return(summaryTable.ToString());
        }