public void Decode_Should_ReturnInputString_When_InputStringDoesNotContainEntity() { // Arrange const string expected = "&NotAnEntity"; // Act var actual = XmlEncoder.Decode(expected); // Assert Assert.Equal(expected, actual); }
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); }
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); }
public void Decode_Should_ReturnCorrectlyEncodedString_When_StringContainsLessThan() { // Arrange const string expected = "<"; const string source = "<"; // Act var actual = XmlEncoder.Decode(source); // Assert Assert.Equal(expected, actual); }
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); }
/// <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); }
/// <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); }