From 13bc7035063dd722623f9a27ba1ab98c821dd093 Mon Sep 17 00:00:00 2001 From: Ron2 Date: Fri, 12 Sep 2014 17:38:21 -0700 Subject: [PATCH] Added DomNode.IsAttributeSet(AttributeInfo) Closes #15 --- Framework/Atf.Core/Dom/DomNode.cs | 11 +++++++++++ Test/UnitTests/Sce.Atf/Dom/TestDomNode.cs | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/Framework/Atf.Core/Dom/DomNode.cs b/Framework/Atf.Core/Dom/DomNode.cs index a63589ee..548e9357 100644 --- a/Framework/Atf.Core/Dom/DomNode.cs +++ b/Framework/Atf.Core/Dom/DomNode.cs @@ -362,6 +362,17 @@ public string GetId() return id; } + /// + /// Gets whether or not the attribute has been set, even if it was set to its default value. + /// Attribute metadata + /// True iff the attribute has been set to anything other than null + /// Setting an attribute to null is special, and makes the attribute look like it + /// was never set. + public bool IsAttributeSet(AttributeInfo attributeInfo) + { + return GetLocalAttribute(attributeInfo) != null; + } + /// /// Gets whether or not the attribute's value (like by calling GetAttribute) is equal to /// the default value. diff --git a/Test/UnitTests/Sce.Atf/Dom/TestDomNode.cs b/Test/UnitTests/Sce.Atf/Dom/TestDomNode.cs index 275ec76a..c346f7a2 100644 --- a/Test/UnitTests/Sce.Atf/Dom/TestDomNode.cs +++ b/Test/UnitTests/Sce.Atf/Dom/TestDomNode.cs @@ -352,20 +352,24 @@ public void TestGetAttribute() Assert.True(test.IsAttributeDefault(info)); Assert.Null(test.GetLocalAttribute(info)); + Assert.False(test.IsAttributeSet(info)); test.SetAttribute(info, 2); Assert.AreEqual(test.GetAttribute(info), 2); Assert.AreEqual(test.GetLocalAttribute(info), 2); Assert.False(test.IsAttributeDefault(info)); + Assert.True(test.IsAttributeSet(info)); test.SetAttribute(info, null); Assert.True(test.IsAttributeDefault(info)); Assert.Null(test.GetLocalAttribute(info)); + Assert.False(test.IsAttributeSet(info)); test.SetAttribute(info, 0); Assert.AreEqual(test.GetAttribute(info), 0); Assert.True(test.IsAttributeDefault(info)); Assert.AreEqual(test.GetLocalAttribute(info), 0); + Assert.True(test.IsAttributeSet(info)); } [Test] @@ -376,13 +380,16 @@ public void TestSetAttribute() type.Define(info); DomNode test = new DomNode(type); + Assert.False(test.IsAttributeSet(info)); test.SetAttribute(info, 2); Assert.AreEqual(test.GetAttribute(info), 2); Assert.AreEqual(test.GetLocalAttribute(info), 2); + Assert.True(test.IsAttributeSet(info)); test.SetAttribute(info, null); Assert.True(test.IsAttributeDefault(info)); Assert.Null(test.GetLocalAttribute(info)); + Assert.False(test.IsAttributeSet(info)); } [Test]