Esempio n. 1
0
        public OptionSettings(WpfDrawingSettings wpfSettings, string testPath)
        {
            _wpfSettings = wpfSettings;

            _localSuitePath = testPath;
            _testSuites     = SvgTestSuite.Create();

            if (wpfSettings == null)
            {
                _wpfSettings = new WpfDrawingSettings();
            }

            // For the start the default is selected
            var selectedSuite = SvgTestSuite.GetDefault(_testSuites);

            if (selectedSuite != null)
            {
                if (string.IsNullOrWhiteSpace(testPath))
                {
                    _localSuitePath = selectedSuite.LocalSuitePath;
                }
                _webSuitePath = selectedSuite.WebSuitePath;
            }

            if (!Directory.Exists(_localSuitePath))
            {
                Directory.CreateDirectory(_localSuitePath);
            }
        }
Esempio n. 2
0
        public static SvgTestSuite GetDefault(IList <SvgTestSuite> testSuites)
        {
            SvgTestSuite defaultTestSuite = null;

            if (testSuites != null && testSuites.Count != 0)
            {
                foreach (var testSuite in testSuites)
                {
                    if (testSuite.IsDefault)
                    {
                        defaultTestSuite = testSuite;
                        break;
                    }
                }
            }
            return(defaultTestSuite);
        }
Esempio n. 3
0
        public SvgTestSuite(SvgTestSuite source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source), "The source parameter cannot be null or Nothing.");
            }

            _isDefault      = source._isDefault;
            _isSelected     = source._isSelected;
            _version        = source._version;
            _description    = source._description;
            _suiteName      = source._suiteName;
            _suiteDirName   = source._suiteDirName;
            _webSuitePath   = source._webSuitePath;
            _localSuitePath = source._localSuitePath;
            _testFileName   = source._testFileName;
            _resultFileName = source._resultFileName;
        }
Esempio n. 4
0
        public SvgTestSuite Clone()
        {
            SvgTestSuite clonedSuite = new SvgTestSuite(this);

            if (_version != null)
            {
                clonedSuite._version = string.Copy(_version);
            }
            if (_description != null)
            {
                clonedSuite._description = string.Copy(_description);
            }

            if (_suiteName != null)
            {
                clonedSuite._suiteName = string.Copy(_suiteName);
            }
            if (_suiteDirName != null)
            {
                clonedSuite._suiteDirName = string.Copy(_suiteDirName);
            }

            if (_testFileName != null)
            {
                clonedSuite._testFileName = string.Copy(_testFileName);
            }
            if (_resultFileName != null)
            {
                clonedSuite._resultFileName = string.Copy(_resultFileName);
            }

            if (_webSuitePath != null)
            {
                clonedSuite._webSuitePath = string.Copy(_webSuitePath);
            }
            if (_localSuitePath != null)
            {
                clonedSuite._localSuitePath = string.Copy(_localSuitePath);
            }

            return(clonedSuite);
        }
Esempio n. 5
0
        public SvgTestSuite Clone()
        {
            SvgTestSuite clonedSuite = new SvgTestSuite(this);

            if (_version != null)
            {
                clonedSuite._version = new string(_version.ToCharArray());
            }
            if (_description != null)
            {
                clonedSuite._description = new string(_description.ToCharArray());
            }

            if (_suiteName != null)
            {
                clonedSuite._suiteName = new string(_suiteName.ToCharArray());
            }
            if (_suiteDirName != null)
            {
                clonedSuite._suiteDirName = new string(_suiteDirName.ToCharArray());
            }

            if (_testFileName != null)
            {
                clonedSuite._testFileName = new string(_testFileName.ToCharArray());
            }
            if (_resultFileName != null)
            {
                clonedSuite._resultFileName = new string(_resultFileName.ToCharArray());
            }

            if (_webSuitePath != null)
            {
                clonedSuite._webSuitePath = new string(_webSuitePath.ToCharArray());
            }
            if (_localSuitePath != null)
            {
                clonedSuite._localSuitePath = new string(_localSuitePath.ToCharArray());
            }

            return(clonedSuite);
        }
Esempio n. 6
0
        private void Save(XmlWriter writer)
        {
            writer.WriteStartDocument();
            writer.WriteStartElement("options");

            this.SaveOption(writer, "HidePathsRoot", _hidePathsRoot);
            //this.SaveOption(writer, "WebSuitePath", _webSuitePath);
            //this.SaveOption(writer, "LocalSuitePath", this.GetPath(_localSuitePath));
            this.SaveOption(writer, "SelectedValuePath", _selectedValuePath);

            if (_wpfSettings != null)
            {
                this.SaveOption(writer, "TextAsGeometry", _wpfSettings.TextAsGeometry);
                this.SaveOption(writer, "IncludeRuntime", _wpfSettings.IncludeRuntime);

                this.SaveOption(writer, "IgnoreRootViewbox", _wpfSettings.IgnoreRootViewbox);
                this.SaveOption(writer, "EnsureViewboxSize", _wpfSettings.EnsureViewboxSize);
                this.SaveOption(writer, "EnsureViewboxPosition", _wpfSettings.EnsureViewboxPosition);
            }

            if (_testSuites != null && _testSuites.Count != 0)
            {
                var selectedSuite = SvgTestSuite.GetSelected(_testSuites);
                if (selectedSuite != null)
                {
                    selectedSuite.LocalSuitePath = _localSuitePath;
                    selectedSuite.WebSuitePath   = _webSuitePath;
                }

                writer.WriteStartElement("testSuites");

                foreach (var testSuite in _testSuites)
                {
                    testSuite.WriteXml(writer);
                }

                writer.WriteEndElement();
            }

            writer.WriteEndElement();
            writer.WriteEndDocument();
        }
Esempio n. 7
0
        public OptionSettings(WpfDrawingSettings wpfSettings, string testPath)
        {
            _wpfSettings = wpfSettings;

            _localSuitePath = testPath;
            _testSuites     = SvgTestSuite.Create();

            if (wpfSettings == null)
            {
                _wpfSettings = new WpfDrawingSettings();
            }

            // For the start the default is selected
            var selectedSuite = SvgTestSuite.GetDefault(_testSuites);

            if (selectedSuite != null)
            {
                if (string.IsNullOrWhiteSpace(testPath))
                {
                    _localSuitePath = selectedSuite.LocalSuitePath;
                }
                _webSuitePath = selectedSuite.WebSuitePath;
            }

            if (!Directory.Exists(_localSuitePath))
            {
                Directory.CreateDirectory(_localSuitePath);
            }

            _webFontsPath   = SvgTestSuite.WebDirBase + FontsPrefix + SvgTestSuite.FileExtZip;
            _localFontsPath = Path.GetFullPath(Path.Combine(SvgTestSuite.LocalDirBase, FontsPrefix));

            if (!Directory.Exists(_localFontsPath))
            {
                Directory.CreateDirectory(_localFontsPath);
            }

            _wpfSettings.AddFontLocation(_localFontsPath);
        }
Esempio n. 8
0
        public static SvgTestSuite GetSelected(IList <SvgTestSuite> testSuites)
        {
            SvgTestSuite selectedTestSuite = null;

            if (testSuites != null && testSuites.Count != 0)
            {
                int selectedCount = 0;
                foreach (var testSuite in testSuites)
                {
                    if (testSuite.IsSelected)
                    {
                        selectedTestSuite = testSuite;
                        selectedCount++;
                    }
                }

                if (selectedCount != 1)
                {
                    return(null);
                }
            }

            return(selectedTestSuite);
        }
Esempio n. 9
0
        private void Load(XmlReader reader)
        {
            var comparer = StringComparison.OrdinalIgnoreCase;

            List <SvgTestSuite> testSuites = new List <SvgTestSuite>(SvgTestSuite.TestSuiteCount);

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (string.Equals(reader.Name, "option", comparer))
                    {
                        string optionName = reader.GetAttribute("name");
                        string optionType = reader.GetAttribute("type");
                        if (string.Equals(optionType, "String", comparer))
                        {
                            string optionValue = reader.ReadElementContentAsString();

                            switch (optionName)
                            {
                            case "SelectedValuePath":
                                _selectedValuePath = optionValue;
                                break;
                            }
                        }
                        else if (string.Equals(optionType, "Boolean", comparer))
                        {
                            bool optionValue = reader.ReadElementContentAsBoolean();
                            switch (optionName)
                            {
                            case "HidePathsRoot":
                                _hidePathsRoot = optionValue;
                                break;

                            case "TextAsGeometry":
                                _wpfSettings.TextAsGeometry = optionValue;
                                break;

                            case "IncludeRuntime":
                                _wpfSettings.IncludeRuntime = optionValue;
                                break;

                            case "IgnoreRootViewbox":
                                _wpfSettings.IgnoreRootViewbox = optionValue;
                                break;

                            case "EnsureViewboxSize":
                                _wpfSettings.EnsureViewboxSize = optionValue;
                                break;

                            case "EnsureViewboxPosition":
                                _wpfSettings.EnsureViewboxPosition = optionValue;
                                break;
                            }
                        }
                    }
                    else if (string.Equals(reader.Name, "testSuite", comparer))
                    {
                        if (!reader.IsEmptyElement)
                        {
                            SvgTestSuite testSuite = new SvgTestSuite(reader);
                            if (testSuite.IsValid())
                            {
                                testSuites.Add(testSuite);
                            }
                        }
                    }
                }
            }

            if (testSuites.Count == SvgTestSuite.TestSuiteCount)
            {
                var selectedSuite = SvgTestSuite.GetSelected(testSuites);
                if (selectedSuite != null)
                {
                    _localSuitePath = selectedSuite.LocalSuitePath;
                    _webSuitePath   = selectedSuite.WebSuitePath;

                    _testSuites = testSuites;
                }
            }
        }
Esempio n. 10
0
        private bool LoadFile(Stream stream, SvgTestInfo testInfo)
        {
            testDetailsDoc.Blocks.Clear();

            Regex rgx = new Regex("\\s+");

            testTitle.Text      = testInfo.Title;
            testDescrition.Text = rgx.Replace(testInfo.Description, " ").Trim();
            testFilePath.Text   = _svgFilePath;

            btnFilePath.IsEnabled = true;

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace             = false;
            settings.IgnoreComments               = true;
            settings.IgnoreProcessingInstructions = true;
            settings.DtdProcessing = DtdProcessing.Parse;
            settings.XmlResolver   = null;

            SvgTestSuite selectedTestSuite = null;

            if (_optionSettings != null)
            {
                selectedTestSuite = _optionSettings.SelectedTestSuite;
            }
            if (selectedTestSuite == null)
            {
                selectedTestSuite = SvgTestSuite.GetDefault(SvgTestSuite.Create());
            }

            int majorVersion = selectedTestSuite.MajorVersion;
            int minorVersion = selectedTestSuite.MinorVersion;

            using (XmlReader reader = XmlReader.Create(stream, settings))
            {
                if (majorVersion == 1 && minorVersion == 1)
                {
                    if (reader.ReadToFollowing("d:SVGTestCase"))
                    {
                        _testCase = new SvgTestCase();

                        while (reader.Read())
                        {
                            string      nodeName = reader.Name;
                            XmlNodeType nodeType = reader.NodeType;
                            if (nodeType == XmlNodeType.Element)
                            {
                                if (string.Equals(nodeName, "d:operatorScript", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    Paragraph titlePara = new Paragraph();
                                    titlePara.FontWeight = FontWeights.Bold;
                                    titlePara.FontSize   = 16;
                                    titlePara.Inlines.Add(new Run("Operator Script"));

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);
                                        if (nextSection != null)
                                        {
                                            testDetailsDoc.Blocks.Add(titlePara);
                                            testDetailsDoc.Blocks.Add(nextSection);
                                        }
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(titlePara);
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }
                                }
                                else if (string.Equals(nodeName, "d:passCriteria", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    Paragraph titlePara = new Paragraph();
                                    titlePara.FontWeight = FontWeights.Bold;
                                    titlePara.FontSize   = 16;
                                    titlePara.Inlines.Add(new Run("Pass Criteria"));

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);
                                        if (nextSection != null)
                                        {
                                            testDetailsDoc.Blocks.Add(titlePara);
                                            testDetailsDoc.Blocks.Add(nextSection);
                                        }
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(titlePara);
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }
                                }
                                else if (string.Equals(nodeName, "d:testDescription", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    Paragraph titlePara = new Paragraph();
                                    titlePara.FontWeight = FontWeights.Bold;
                                    titlePara.FontSize   = 16;
                                    titlePara.Inlines.Add(new Run("Test Description"));

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);
                                        if (nextSection != null)
                                        {
                                            testDetailsDoc.Blocks.Add(titlePara);
                                            testDetailsDoc.Blocks.Add(nextSection);
                                        }
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(titlePara);
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }

                                    _testCase.Paragraphs.Add(inputText);
                                }
                            }
                            else if (nodeType == XmlNodeType.EndElement &&
                                     string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                            {
                                break;
                            }
                        }
                    }
                }
                else if (majorVersion == 1 && minorVersion == 2)
                {
                    if (reader.ReadToFollowing("SVGTestCase"))
                    {
                        _testCase = new SvgTestCase();

                        while (reader.Read())
                        {
                            string      nodeName = reader.Name;
                            XmlNodeType nodeType = reader.NodeType;
                            if (nodeType == XmlNodeType.Element)
                            {
                                if (string.Equals(nodeName, "d:OperatorScript", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);
                                        if (nextSection != null)
                                        {
                                            testDetailsDoc.Blocks.Add(nextSection);
                                        }
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }
                                }
                                else if (string.Equals(nodeName, "d:PassCriteria", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);
                                        if (nextSection != null)
                                        {
                                            testDetailsDoc.Blocks.Add(nextSection);
                                        }
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }
                                }
                                else if (string.Equals(nodeName, "d:TestDescription", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);
                                        if (nextSection != null)
                                        {
                                            testDetailsDoc.Blocks.Add(nextSection);
                                        }
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }

                                    _testCase.Paragraphs.Add(inputText);
                                }
                            }
                            else if (nodeType == XmlNodeType.EndElement &&
                                     string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (reader.ReadToFollowing("SVGTestCase"))
                    {
                        _testCase = new SvgTestCase();

                        while (reader.Read())
                        {
                            string      nodeName = reader.Name;
                            XmlNodeType nodeType = reader.NodeType;
                            if (nodeType == XmlNodeType.Element)
                            {
                                if (string.Equals(nodeName, "OperatorScript", StringComparison.OrdinalIgnoreCase))
                                {
                                    string revisionText = reader.GetAttribute("version");
                                    if (!string.IsNullOrWhiteSpace(revisionText))
                                    {
                                        revisionText       = revisionText.Replace("$", string.Empty);
                                        _testCase.Revision = revisionText.Trim();
                                    }
                                    string nameText = reader.GetAttribute("testname");
                                    if (!string.IsNullOrWhiteSpace(nameText))
                                    {
                                        _testCase.Name = nameText.Trim();
                                    }
                                }
                                else if (string.Equals(nodeName, "Paragraph", StringComparison.OrdinalIgnoreCase))
                                {
                                    string inputText = reader.ReadInnerXml();
                                    string xamlText  = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(inputText, false);

                                    if (_useConverter)
                                    {
                                        StringReader stringReader = new StringReader(xamlText);
                                        XmlReader    xmlReader    = XmlReader.Create(stringReader);

                                        Section nextSection = (Section)XamlReader.Load(xmlReader);

                                        testDetailsDoc.Blocks.Add(nextSection);
                                    }
                                    else
                                    {
                                        Section   pageSession = new Section();
                                        Paragraph nextPara    = new Paragraph();
                                        //nextPara.Padding = new Thickness(3, 5, 3, 5);
                                        string paraText = rgx.Replace(inputText, " ").Trim();
                                        nextPara.Inlines.Add(new Run(paraText));
                                        pageSession.Blocks.Add(nextPara);

                                        testDetailsDoc.Blocks.Add(pageSession);
                                    }

                                    _testCase.Paragraphs.Add(inputText);
                                }
                            }
                            else if (nodeType == XmlNodeType.EndElement &&
                                     string.Equals(nodeName, "SVGTestCase", StringComparison.OrdinalIgnoreCase))
                            {
                                break;
                            }
                        }
                    }
                }
            }

            SubscribeToAllHyperlinks();

            return(true);
        }