Skip to content

Commit

Permalink
Added DomNode.IsAttributeSet(AttributeInfo)
Browse files Browse the repository at this point in the history
Closes #15
  • Loading branch information
Ron2 committed Sep 13, 2014
1 parent 710bd4e commit 13bc703
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Framework/Atf.Core/Dom/DomNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,17 @@ public string GetId()
return id;
}

/// <summary>
/// Gets whether or not the attribute has been set, even if it was set to its default value.</summary>
/// <param name="attributeInfo">Attribute metadata</param>
/// <returns>True iff the attribute has been set to anything other than null</returns>
/// <remarks>Setting an attribute to null is special, and makes the attribute look like it
/// was never set.</remarks>
public bool IsAttributeSet(AttributeInfo attributeInfo)
{
return GetLocalAttribute(attributeInfo) != null;
}

/// <summary>
/// Gets whether or not the attribute's value (like by calling GetAttribute) is equal to
/// the default value.</summary>
Expand Down
7 changes: 7 additions & 0 deletions Test/UnitTests/Sce.Atf/Dom/TestDomNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit 13bc703

Please sign in to comment.