diff --git a/ICD.Common.Utils.Tests/Xml/XmlUtilsTest.cs b/ICD.Common.Utils.Tests/Xml/XmlUtilsTest.cs
index 5ec66a7..b198848 100644
--- a/ICD.Common.Utils.Tests/Xml/XmlUtilsTest.cs
+++ b/ICD.Common.Utils.Tests/Xml/XmlUtilsTest.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using ICD.Common.Properties;
@@ -29,6 +30,14 @@ namespace ICD.Common.Utils.Tests.Xml
+ ""
+ "";
+ [Flags]
+ public enum eTestEnum
+ {
+ A = 1,
+ B = 2,
+ C = 4
+ }
+
#region Attributes
[Test]
@@ -185,5 +194,159 @@ namespace ICD.Common.Utils.Tests.Xml
Assert.AreEqual(expected, XmlUtils.Format(xml));
}
+
+ #region Read Child Element
+
+ [TestCase("Test", "Child", "Test")]
+ public void ReadChildElementContentAsStringTest(string xml, string childElement, string expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.ReadChildElementContentAsString(xml, childElement));
+ }
+
+ [TestCase("1", "Child", 1)]
+ public void ReadChildElementContentAsIntTest(string xml, string childElement, int expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.ReadChildElementContentAsInt(xml, childElement));
+ }
+
+ [TestCase("1", "Child", (uint)1)]
+ public void ReadChildElementContentAsUintTest(string xml, string childElement, uint expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.ReadChildElementContentAsUint(xml, childElement));
+ }
+
+ [TestCase("1", "Child", (long)1)]
+ public void ReadChildElementContentAsLongTest(string xml, string childElement, long expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.ReadChildElementContentAsLong(xml, childElement));
+ }
+
+ [TestCase("1", "Child", (ushort)1)]
+ public void ReadChildElementContentAsUShortTest(string xml, string childElement, ushort expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.ReadChildElementContentAsUShort(xml, childElement));
+ }
+
+ [TestCase("1", "Child", 1.0f)]
+ public void ReadChildElementContentAsFloatTest(string xml, string childElement, float expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.ReadChildElementContentAsFloat(xml, childElement), 0.001f);
+ }
+
+ [TestCase("True", "Child", true)]
+ [TestCase("true", "Child", true)]
+ [TestCase("False", "Child", false)]
+ [TestCase("false", "Child", false)]
+ public void ReadChildElementContentAsBooleanTest(string xml, string childElement, bool expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.ReadChildElementContentAsBoolean(xml, childElement));
+ }
+
+ [TestCase("1", "Child", (byte)1)]
+ [TestCase("0x01", "Child", (byte)1)]
+ [TestCase("0X01", "Child", (byte)1)]
+ public void ReadChildElementContentAsByteTest(string xml, string childElement, byte expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.ReadChildElementContentAsByte(xml, childElement));
+ }
+
+ [TestCase("A", "Child", true, eTestEnum.A)]
+ [TestCase("A, B", "Child", true, eTestEnum.A | eTestEnum.B)]
+ public void ReadChildElementContentAsEnumTest(string xml, string childElement, bool ignoreCase, T expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.ReadChildElementContentAsEnum(xml, childElement, ignoreCase));
+ }
+
+ #endregion
+
+ #region Try Read Child Element
+
+ [TestCase("Test", "Child", "Test")]
+ [TestCase("", "Child", null)]
+ public void TryReadChildElementContentAsStringTest(string xml, string childElement, string expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.TryReadChildElementContentAsString(xml, childElement));
+ }
+
+ [TestCase("1", "Child", 1)]
+ [TestCase("fgfdgfd", "Child", null)]
+ [TestCase("", "Child", null)]
+ public void TryReadChildElementContentAsIntTest(string xml, string childElement, int? expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.TryReadChildElementContentAsInt(xml, childElement));
+ }
+
+ [TestCase("1", "Child", (long)1)]
+ [TestCase("fgfdgfd", "Child", null)]
+ [TestCase("", "Child", null)]
+ public void TryReadChildElementContentAsLongTest(string xml, string childElement, long? expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.TryReadChildElementContentAsLong(xml, childElement));
+ }
+
+ [TestCase("1", "Child", (ushort)1)]
+ [TestCase("fgfdgfd", "Child", null)]
+ [TestCase("", "Child", null)]
+ public void TryReadChildElementContentAsUShortTest(string xml, string childElement, ushort? expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.TryReadChildElementContentAsUShort(xml, childElement));
+ }
+
+ [TestCase("1", "Child", 1.0f)]
+ [TestCase("fgfdgfd", "Child", null)]
+ [TestCase("", "Child", null)]
+ public void TryReadChildElementContentAsFloatTest(string xml, string childElement, float? expected)
+ {
+ float? result = XmlUtils.TryReadChildElementContentAsFloat(xml, childElement);
+
+ if (result == null)
+ Assert.AreEqual(expected, null);
+ else if (expected == null)
+ Assert.Fail();
+ else
+ Assert.AreEqual((float)expected, (float)result, 0.001f);
+ }
+
+ [TestCase("True", "Child", true)]
+ [TestCase("true", "Child", true)]
+ [TestCase("False", "Child", false)]
+ [TestCase("false", "Child", false)]
+ [TestCase("fgfdgfd", "Child", null)]
+ [TestCase("", "Child", null)]
+ public void TryReadChildElementContentAsBooleanTest(string xml, string childElement, bool? expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.TryReadChildElementContentAsBoolean(xml, childElement));
+ }
+
+ [TestCase("1", "Child", (byte)1)]
+ [TestCase("0x01", "Child", (byte)1)]
+ [TestCase("0X01", "Child", (byte)1)]
+ [TestCase("fgfdgfd", "Child", null)]
+ [TestCase("", "Child", null)]
+ public void TryReadChildElementContentAsByteTest(string xml, string childElement, byte? expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.TryReadChildElementContentAsByte(xml, childElement));
+ }
+
+ [TestCase("A", "Child", true, eTestEnum.A)]
+ [TestCase("A, B", "Child", true, eTestEnum.A | eTestEnum.B)]
+ [TestCase("fgfdgfd", "Child", true, null)]
+ [TestCase("", "Child", true, null)]
+ public void TryReadChildElementContentAsEnumTest(string xml, string childElement, bool ignoreCase, eTestEnum? expected)
+ {
+ Assert.AreEqual(expected, XmlUtils.TryReadChildElementContentAsEnum(xml, childElement, ignoreCase));
+ }
+
+ [TestCase("A", "Child", true, true)]
+ [TestCase("A, B", "Child", true, true)]
+ [TestCase("fgfdgfd", "Child", true, false)]
+ [TestCase("", "Child", true, false)]
+ public void TryReadChildElementContentAsEnumTest(string xml, string childElement, bool ignoreCase, bool expected)
+ {
+ eTestEnum output;
+ Assert.AreEqual(expected, XmlUtils.TryReadChildElementContentAsEnum(xml, childElement, ignoreCase, out output));
+ }
+
+ #endregion
}
}
\ No newline at end of file