Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

Linq-To-XML Style of Node Creation for C++

, 7 Jun 2012 Ms-PL
Linq-To-XML Node Creation for Native C++
elmax-84498.zip
BuildProcessTemplates
Elmax.vsmdi
ElmaxNet
Properties
Elmax
Elmax.vcxproj.user
StringUtils
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
TryoutNet
Properties
Settings.settings
Tryout
res
Tryout.ico
Tryout.vcxproj.user
elmax-ver083.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver084.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver085.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver086.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
elmax-ver087.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
Elmax-ver089.zip
Elmax-ver089
Elmax.vsmdi
Elmax
Elmax.vcxproj.user
StringUtils
ElmaxNet
Properties
Local.testsettings
TestNativeElmax
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax
Properties
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Tryout
res
Tryout.ico
Tryout.vcxproj.user
TryoutNet
Properties
Settings.settings
ElmaxSrcVer082.zip
Elmax.vsmdi
Elmax.vcxproj.user
Local.testsettings
app.ico
TestNativeElmax.vcxproj.user
TestNetElmax.csproj.user
TraceAndTestImpact.testsettings
Settings.settings
Tryout.ico
Tryout.vcxproj.user
using System;
using System.Xml;
using System.Text;
using System.IO;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Elmax;

namespace TestNetElmax
{
	[TestClass]
	public class UnitTestAttribute
	{
		private bool CreateAndInitDom(out XmlDocument doc)
		{
			doc = new XmlDocument();
			if (doc!=null)
			{
				XmlProcessingInstruction pi = doc.CreateProcessingInstruction("xml", " version='1.0' encoding='UTF-8'");
				doc.AppendChild(pi);
			}
			else
				return false;
			return true;
		}
        private bool CreateAndLoadXmlString(out XmlDocument doc, System.String strXml)
        {
            doc = new XmlDocument();
            try
            {
                doc.LoadXml(strXml);
            }
            catch (System.Exception)
            {
                return false;
            }
            return true;
        }
		[TestMethod]
		public void NetAttributeDelete()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				int dd = 2000000000;
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetInt(dd);
				int dd3 = elem.Attribute("Attr").GetInt(10);
				Assert.AreEqual(dd, dd3);

				Elmax.Attribute attr = elem.Attribute("Attr");

				Assert.IsTrue(attr.Exists);

				Assert.IsTrue(attr.Delete());

				dd3 = elem.Attribute("Attr").GetInt(10);
				Assert.AreEqual(10, dd3);

				XmlDocument doc2;

                Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				int dd2 = elem2.Attribute("Attr").GetInt(10);

				Assert.AreEqual(10, dd2);
			}
		}
		[TestMethod]
        public void NetAttributeDateTime()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				DateTime dd = new DateTime(2006, 7, 23, 9, 0, 23);
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetDateTime(dd);
				DateTime ddcheck = new DateTime();
				DateTime dd3 = elem.Attribute("Attr").GetDateTime(ddcheck);

				Assert.AreEqual(dd.Year, dd3.Year);
				Assert.AreEqual(dd.Month, dd3.Month);
				Assert.AreEqual(dd.Day, dd3.Day);
				Assert.AreEqual(dd.Hour, dd3.Hour);
				Assert.AreEqual(dd.Minute, dd3.Minute);
				Assert.AreEqual(dd.Second, dd3.Second);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				DateTime dd2 = elem2.Attribute("Attr").GetDateTime(ddcheck);

				Assert.AreEqual(dd.Year, dd2.Year);
				Assert.AreEqual(dd.Month, dd2.Month);
				Assert.AreEqual(dd.Day, dd2.Day);
				Assert.AreEqual(dd.Hour, dd2.Hour);
				Assert.AreEqual(dd.Minute, dd2.Minute);
				Assert.AreEqual(dd.Second, dd2.Second);
			}
		}
		[TestMethod]
        public void NetAttributeDate()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				DateTime dd = new DateTime(2010, 10, 1);
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetDate(dd);
				DateTime ddcheck = new DateTime();
				DateTime dd3 = elem.Attribute("Attr").GetDate(ddcheck);

				Assert.AreEqual(dd.Year, dd3.Year);
				Assert.AreEqual(dd.Month, dd3.Month);
				Assert.AreEqual(dd.Day, dd3.Day);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				DateTime dd2 = elem2.Attribute("Attr").GetDate(ddcheck);

				Assert.AreEqual(dd.Year, dd2.Year);
				Assert.AreEqual(dd.Month, dd2.Month);
				Assert.AreEqual(dd.Day, dd2.Day);
			}
		}
		[TestMethod]
        public void NetAttributeGuid()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				Guid dd = Guid.NewGuid();
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetGuid(dd, false);
				Guid random1 = Guid.NewGuid();
				Guid dd3 = elem.Attribute("Attr").GetGuid(random1);

                Assert.AreEqual(dd.ToString(), dd3.ToString());

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				Guid dd2 = elem2.Attribute("Attr").GetGuid(random1);

                Assert.AreEqual(dd.ToString(), dd2.ToString());
			}
		}
		[TestMethod]
        public void NetAttributeGuidNoBraces()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				Guid dd = Guid.NewGuid();
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetGuid(dd, true);
				Guid random1 = Guid.NewGuid();
				Guid dd3 = elem.Attribute("Attr").GetGuid(random1);

                Assert.AreEqual(dd.ToString(), dd3.ToString());

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				Guid dd2 = elem2.Attribute("Attr").GetGuid(random1);

                Assert.AreEqual(dd.ToString(), dd2.ToString());
			}
		}
		[TestMethod]
        public void NetAttributeBoolean()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				bool dd = true;
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetBool(dd);
				bool dd3 = elem.Attribute("Attr").GetBool(false);

				Assert.AreEqual(dd, dd3);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				bool dd2 = elem2.Attribute("Attr").GetBool(false);

				Assert.AreEqual(dd, dd2);
			}
		}
		[TestMethod]
        public void NetAttributeLong()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				long dd = 14000000000L;
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetLong(dd);
				long dd3 = elem.Attribute("Attr").GetLong(10);

				Assert.AreEqual(dd, dd3);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				long dd2 = elem2.Attribute("Attr").GetLong(10);

				Assert.AreEqual(dd, dd2);
			}
		}
		[TestMethod]
        public void NetAttributeInt()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				int dd = 2000000000;
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetInt(dd);
				int dd3 = elem.Attribute("Attr").GetInt(10);

				Assert.AreEqual(dd, dd3);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				int dd2 = elem2.Attribute("Attr").GetInt(10);

				Assert.AreEqual(dd, dd2);
			}
		}
		[TestMethod]
        public void NetAttributeShort()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				short dd = 32000;
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetShort(dd);
				short dd3 = elem.Attribute("Attr").GetShort(10);

				Assert.AreEqual(dd, dd3);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				short dd2 = elem2.Attribute("Attr").GetShort(10);

				Assert.AreEqual(dd, dd2);
			}
		}
		[TestMethod]
        public void NetAttributeSByte()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				sbyte dd = 127;
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetSByte(dd);
				sbyte dd3 = elem.Attribute("Attr").GetSByte(10);

				Assert.AreEqual(dd, dd3);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				sbyte dd2 = elem2.Attribute("Attr").GetSByte(10);

				Assert.AreEqual(dd, dd2);
			}
		}
		[TestMethod]
        public void NetAttributeULong()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				ulong dd = 14000000000UL;
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetULong(dd);
				ulong dd3 = elem.Attribute("Attr").GetULong(10);

				Assert.AreEqual(dd, dd3);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				ulong dd2 = elem2.Attribute("Attr").GetULong(10);

				Assert.AreEqual(dd, dd2);
			}
		}
		[TestMethod]
        public void NetAttributeUInt()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				uint dd = 4000000000;
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetUInt(dd);
				uint dd3 = elem.Attribute("Attr").GetUInt(10);

				Assert.AreEqual(dd, dd3);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				uint dd2 = elem2.Attribute("Attr").GetUInt(10);

				Assert.AreEqual(dd, dd2);
			}
		}
		[TestMethod]
        public void NetAttributeUShort()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				ushort dd = 65000;
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetUShort(dd);
				ushort dd3 = elem.Attribute("Attr").GetUShort(10);

				Assert.AreEqual(dd, dd3);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				ushort dd2 = elem2.Attribute("Attr").GetUShort(10);

				Assert.AreEqual(dd, dd2);
			}
		}
		[TestMethod]
        public void NetAttributeByte()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				byte dd = 255;
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetByte(dd);
				byte dd3 = elem.Attribute("Attr").GetByte(12);

				Assert.AreEqual(dd, dd3);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				byte dd2 = elem2.Attribute("Attr").GetByte(12);

				Assert.AreEqual(dd, dd2);
			}
		}
		[TestMethod]
        public void NetAttributeString()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				System.String dd = "ABCD";
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetString(dd);
				System.String dd3 = elem.Attribute("Attr").GetString("A");

				System.String s1 = dd;
				System.String s2 = dd3;

				Assert.AreEqual(s1, s2);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				System.String dd2 = elem2.Attribute("Attr").GetString("A");

				s2 = dd2;

				Assert.AreEqual(s1, s2);
			}
		}
		[TestMethod]
        public void NetAttributeDouble()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				double dd = 123.0;
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetDouble(dd);
				double dd3 = elem.Attribute("Attr").GetDouble(10.0);

				Assert.AreEqual(dd, dd3);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				double dd2 = elem2.Attribute("Attr").GetDouble(10.0);

				Assert.AreEqual(dd, dd2);
			}
		}
		[TestMethod]
        public void NetAttributeFloat()
		{
			XmlDocument doc;
			bool created = CreateAndInitDom(out doc);
			if (created)
			{
				Element root = new Element();
				root.SetDomDoc(doc);

				Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
				float dd = 123.0f;
				Assert.IsTrue(elem.Exists);
				elem.Attribute("Attr").SetFloat(dd);
				float dd3 = elem.Attribute("Attr").GetFloat(10.0f);

				Assert.AreEqual(dd, dd3);

				XmlDocument doc2;
				Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


				Element root2 = new Element();
				root2.SetDomDoc(doc2);

				Element elem2 = root2["aa"]["bb"]["cc"];
				Assert.IsTrue(elem2.Exists);

				float dd2 = elem2.Attribute("Attr").GetFloat(10.0f);

				Assert.AreEqual(dd, dd2);
			}
		}
        [TestMethod]
        public void NetAttributeHex()
        {
            XmlDocument doc;
            bool created = CreateAndInitDom(out doc);
            if (created)
            {
                Element root = new Element();
                root.SetDomDoc(doc);

                Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
                uint dd = 0xACAC;
                Assert.IsTrue(elem.Exists);
                elem.Attribute("dd").SetHex(dd, false);

                uint ans = elem.Attribute("dd").ReadHex(0xee);

                Assert.AreEqual(dd, ans);

                XmlDocument doc2;
                Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));

                Element root2 = new Element();
                root2.SetDomDoc(doc2);

                Element elem2 = root2["aa"]["bb"]["cc"];
                Assert.IsTrue(elem2.Exists);

                uint dd2 = elem2.Attribute("dd").ReadHex(0xee);

                Assert.AreEqual(dd, dd2);
            }
        }
        [TestMethod]
        public void NetAttributeHexWithPrefix()
        {
            XmlDocument doc;
            bool created = CreateAndInitDom(out doc);
            if (created)
            {
                Element root = new Element();
                root.SetDomDoc(doc);

                Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
                uint dd = 0xACAC;
                Assert.IsTrue(elem.Exists);
                elem.Attribute("dd").SetHex(dd, true);

                uint ans = elem.Attribute("dd").ReadHex(0xee);
                Assert.AreEqual(dd, ans);

                string strAns = elem.Attribute("dd").GetString("0xee");
                Assert.AreEqual("0xACAC", strAns);

                XmlDocument doc2;
                Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));

                Element root2 = new Element();
                root2.SetDomDoc(doc2);

                Element elem2 = root2["aa"]["bb"]["cc"];
                Assert.IsTrue(elem2.Exists);

                uint dd2 = elem2.Attribute("dd").ReadHex(0xee);

                Assert.AreEqual(dd, dd2);
            }
        }
        [TestMethod]
        public void NetAttributeHexWithLowerCase()
        {
            XmlDocument doc;
            bool created = CreateAndInitDom(out doc);
            if (created)
            {
                Element root = new Element();
                root.SetDomDoc(doc);

                Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
                uint dd = 0xACAC;
                Assert.IsTrue(elem.Exists);
                elem.Attribute("dd").SetString("acac");

                uint ans = elem.Attribute("dd").ReadHex(0xee);

                Assert.AreEqual(dd, ans);

                XmlDocument doc2;
                Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));

                Element root2 = new Element();
                root2.SetDomDoc(doc2);

                Element elem2 = root2["aa"]["bb"]["cc"];
                Assert.IsTrue(elem2.Exists);

                uint dd2 = elem2.Attribute("dd").ReadHex(0xee);

                Assert.AreEqual(dd, dd2);
            }
        }
        [TestMethod]
        public void NetAttributeInvalidElementString()
        {
            XmlDocument doc;
            bool created = CreateAndInitDom(out doc);
            if (created)
            {
                Element root = new Element();
                root.SetDomDoc(doc);

                Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
                System.String dd = "ABCD";
                Assert.IsTrue(elem.Exists);
                bool bExceptionThrown = false;
                try
                {
                    elem["dd"].Attribute("Attr").SetString(dd);
                }
                catch (System.InvalidOperationException)
                {
                    bExceptionThrown = true;
                }
                Assert.IsTrue(bExceptionThrown);

                bExceptionThrown = false;
                try
                {
                    System.String dd3 = elem["dd"].Attribute("Attr").GetString("A");
                }
                catch (System.InvalidOperationException)
                {
                    bExceptionThrown = true;
                }
                Assert.IsTrue(bExceptionThrown);


                XmlDocument doc2;
                Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


                Element root2 = new Element();
                root2.SetDomDoc(doc2);

                Element elem2 = root2["aa"]["bb"]["cc"];
                Assert.IsTrue(elem2.Exists);

                bExceptionThrown = false;
                try
                {
                    System.String dd2 = elem2["dd"].Attribute("Attr").GetString("A");
                }
                catch (System.InvalidOperationException)
                {
                    bExceptionThrown = true;
                }
                Assert.IsTrue(bExceptionThrown);
            }
        }
        [TestMethod]
        public void NetAttributeNonExistantString()
        {
            XmlDocument doc;
            bool created = CreateAndInitDom(out doc);
            if (created)
            {
                Element root = new Element();
                root.SetDomDoc(doc);

                Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
                Assert.IsTrue(elem.Exists);
                System.String dd3 = elem.Attribute("Attr").GetString("A");

                System.String s1 = "A";
                System.String s2 = dd3;

                Assert.AreEqual(s1, s2);

                XmlDocument doc2;
                Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


                Element root2 = new Element();
                root2.SetDomDoc(doc2);

                Element elem2 = root2["aa"]["bb"]["cc"];
                Assert.IsTrue(elem2.Exists);

                System.String dd2 = elem2.Attribute("Attr").GetString("A");

                s2 = dd2;

                Assert.AreEqual(s1, s2);
            }
        }
        [TestMethod]
        public void NetAttributeInvalidElementInt()
        {
            XmlDocument doc;
            bool created = CreateAndInitDom(out doc);
            if (created)
            {
                Element root = new Element();
                root.SetDomDoc(doc);

                Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
                Assert.IsTrue(elem.Exists);
                bool bExceptionThrown = false;
                try
                {
                    elem["dd"].Attribute("Attr").SetInt(1234);
                }
                catch (System.InvalidOperationException)
                {
                    bExceptionThrown = true;
                }
                Assert.IsTrue(bExceptionThrown);

                bExceptionThrown = false;
                try
                {
                    int dd3 = elem["dd"].Attribute("Attr").GetInt(123);
                }
                catch (System.InvalidOperationException)
                {
                    bExceptionThrown = true;
                }
                Assert.IsTrue(bExceptionThrown);


                XmlDocument doc2;
                Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


                Element root2 = new Element();
                root2.SetDomDoc(doc2);

                Element elem2 = root2["aa"]["bb"]["cc"];
                Assert.IsTrue(elem2.Exists);

                bExceptionThrown = false;
                try
                {
                    int dd2 = elem2["dd"].Attribute("Attr").GetInt(123);
                }
                catch (System.InvalidOperationException)
                {
                    bExceptionThrown = true;
                }
                Assert.IsTrue(bExceptionThrown);
            }
        }
        [TestMethod]
        public void NetAttributeNonExistantInt()
        {
            XmlDocument doc;
            bool created = CreateAndInitDom(out doc);
            if (created)
            {
                Element root = new Element();
                root.SetDomDoc(doc);

                Element elem = root["aa"]["bb"]["cc"].CreateNew(null);
                Assert.IsTrue(elem.Exists);
                int dd3 = elem.Attribute("Attr").GetInt(123);

                Assert.AreEqual(123, dd3);

                XmlDocument doc2;
                Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


                Element root2 = new Element();
                root2.SetDomDoc(doc2);

                Element elem2 = root2["aa"]["bb"]["cc"];
                Assert.IsTrue(elem2.Exists);

                int dd2 = elem2.Attribute("Attr").GetInt(123);

                Assert.AreEqual(123, dd2);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Shao Voon Wong
Software Developer
Singapore Singapore
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141216.1 | Last Updated 7 Jun 2012
Article Copyright 2011 by Shao Voon Wong
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid