Beispiel #1
0
        public void Decode_Should_ReturnInputString_When_InputStringDoesNotContainEntity()
        {
            // Arrange
            const string expected = "&NotAnEntity";

            // Act
            var actual = XmlEncoder.Decode(expected);

            // Assert
            Assert.Equal(expected, actual);
        }
Beispiel #2
0
        public void Decode_Should_ReturnCorrectlyEncodedString_When_StringContainsSingleQuote()
        {
            // Arrange
            const string expected = "\'";
            const string source   = "'";

            // Act
            var actual = XmlEncoder.Decode(source);

            // Assert
            Assert.Equal(expected, actual);
        }
Beispiel #3
0
        public void Decode_Should_ReturnCorrectlyEncodedString_When_StringContainsNonPrintableInHexaDecimal()
        {
            // Arrange
            const string expected = "\n";
            const string source   = "
";

            // Act
            var actual = XmlEncoder.Decode(source);

            // Assert
            Assert.Equal(expected, actual);
        }
Beispiel #4
0
        public void Decode_Should_ReturnCorrectlyEncodedString_When_StringContainsLessThan()
        {
            // Arrange
            const string expected = "<";
            const string source   = "&lt;";

            // Act
            var actual = XmlEncoder.Decode(source);

            // Assert
            Assert.Equal(expected, actual);
        }
Beispiel #5
0
        public void Decode_Should_ReturnCorrectlyEncodedString_When_StringIsANormalString()
        {
            // Arrange
            const string expected = "Normal";
            const string source   = "Normal";

            // Act
            var actual = XmlEncoder.Decode(source);

            // Assert
            Assert.Equal(expected, actual);
        }
Beispiel #6
0
        /// <summary>
        /// Returns the values contained in the _properties using an XPath query.
        /// </summary>
        /// <param name="xpathQuery">an XPath Query.</param>
        /// <returns>List of string values of the nodes.</returns>
        protected List <string> GetNodeListValues(string xpathQuery)
        {
            var nodeListValues = new List <string>();

            try
            {
                var list = _properties.SelectNodes(xpathQuery);

                if (list == null)
                {
                    return(nodeListValues);
                }

                foreach (XmlNode node in list)
                {
                    string value;

                    if (node.Attributes?[0].InnerText == "System.String")
                    {
                        value = XmlEncoder.Decode(node.InnerText);
                    }
                    else
                    {
                        value = node.InnerText;
                    }

                    if (_debugMode)
                    {
                        _log.Debug($"{xpathQuery} --> {value}");
                    }

                    nodeListValues.Add(value);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                throw;
            }

            return(nodeListValues);
        }
Beispiel #7
0
        /// <summary>
        /// Returns the value in the node using an XPath query.
        /// </summary>
        /// <param name="xpathQuery">an XPath Query.</param>
        /// <returns>value of the node.</returns>
        protected string GetNodeValue(string xpathQuery)
        {
            string value = null;

            try
            {
                var node = _properties.SelectSingleNode(xpathQuery);

                if (node == null)
                {
                    _log.Debug($"{xpathQuery} --> null");
                }
                else
                {
                    if (node.Attributes?[0].InnerText == "System.String")
                    {
                        if (!string.IsNullOrEmpty(node.InnerText))
                        {
                            value = XmlEncoder.Decode(node.InnerText);
                        }

                        _log.Debug($"{xpathQuery} --> \"{value}\"");
                    }
                    else
                    {
                        value = node.InnerText;
                        _log.Debug($"{xpathQuery} --> \"{value}\"");
                    }
                }
            }
            catch (ArgumentNullException ex)
            {
                _log.Warn($"{xpathQuery} --> null", ex);
            }

            return(value);
        }