public void TestCopy_MultipleNodes() { DomNodeType type = new DomNodeType("type"); ChildInfo info = new ChildInfo("child", type); ChildInfo infoList = new ChildInfo("childList", type, true); type.Define(info); type.Define(infoList); ChildInfo rootInfo = new ChildInfo("root", type, true); DomNode test = new DomNode(type, rootInfo); DomNode child1 = new DomNode(type); test.SetChild(info, child1); DomNode child2 = new DomNode(type); DomNode child3 = new DomNode(type); IList <DomNode> list = test.GetChildList(infoList); list.Add(child2); list.Add(child3); DomNode[] result = DomNode.Copy(new DomNode[] { test }); Assert.AreEqual(result.Length, 1); Assert.True(Equals(result[0], test)); DomNode singleResult = DomNode.Copy(test); Assert.True(Equals(singleResult, test)); }
public void TestFreezing() { DomNodeType type = new DomNodeType("child"); DomNode test = new DomNode(type); Assert.Throws <InvalidOperationException>(delegate { type.Define(GetStringAttribute("foo")); }); Assert.Throws <InvalidOperationException>(delegate { type.Define(new ChildInfo("foo", type)); }); Assert.Throws <InvalidOperationException>(delegate { type.Define(new ExtensionInfo <TestDomNode>()); }); }
public void TestChildRemoveEvents() { DomNodeType type = new DomNodeType("type"); ChildInfo info = new ChildInfo("child", type); ChildInfo infoList = new ChildInfo("childList", type, true); type.Define(info); type.Define(infoList); DomNode test = new DomNode(type); test.ChildRemoving += new EventHandler <ChildEventArgs>(test_ChildRemoving); test.ChildRemoved += new EventHandler <ChildEventArgs>(test_ChildRemoved); // test child DomNode child = new DomNode(type); test.SetChild(info, child); ChildRemovingArgs = null; ChildRemovedArgs = null; test.SetChild(info, null); ChildEventArgs expected = new ChildEventArgs(test, info, child, 0); Assert.True(Equals(ChildRemovingArgs, expected)); Assert.True(Equals(ChildRemovedArgs, expected)); // test inserting a child when there is one there already test.SetChild(info, child); DomNode newChild = new DomNode(type); ChildRemovingArgs = null; ChildRemovedArgs = null; test.SetChild(info, newChild); expected = new ChildEventArgs(test, info, child, 0); Assert.True(Equals(ChildRemovingArgs, expected)); Assert.True(Equals(ChildRemovedArgs, expected)); // test child list IList <DomNode> list = test.GetChildList(infoList); DomNode child2 = new DomNode(type); list.Add(child2); DomNode child3 = new DomNode(type); list.Add(child3); ChildRemovingArgs = null; ChildRemovedArgs = null; list.Remove(child3); expected = new ChildEventArgs(test, infoList, child3, 1); Assert.True(Equals(ChildRemovingArgs, expected)); Assert.True(Equals(ChildRemovedArgs, expected)); ChildRemovingArgs = null; ChildRemovedArgs = null; list.Remove(child2); expected = new ChildEventArgs(test, infoList, child2, 0); Assert.True(Equals(ChildRemovingArgs, expected)); Assert.True(Equals(ChildRemovedArgs, expected)); }
public void TestGetDecorators() { DomNodeType type = new DomNodeType("type"); type.Define(new ExtensionInfo <SimpleAdapter>()); type.Define(new ExtensionInfo <DerivedAdapter>()); DomNode node = new DomNode(type); object simple = node.GetAdapter(typeof(SimpleAdapter)); object derived = node.GetAdapter(typeof(DerivedAdapter)); // test that they're returned in order of definition on node Utilities.TestSequenceEqual(node.GetDecorators(typeof(SimpleAdapter)), simple, derived); }
public void TestGetExtension() { DomNodeType type = new DomNodeType("type"); type.Define(new ExtensionInfo <VisibleAdapter>()); ExtensionInfo info = new ExtensionInfo <TestDomNodeAdapter>(); type.Define(info); DomNode node = new DomNode(type); VisibleAdapter test = node.GetAdapter(typeof(VisibleAdapter)) as VisibleAdapter; Assert.NotNull(test.GetExtension <TestDomNodeAdapter>(info)); }
public void TestGetAdapter() { DomNodeType type = new DomNodeType("type"); type.Define(new ExtensionInfo <VisibleAdapter>()); type.Define(new ExtensionInfo <SimpleAdapter>()); DomNode node = new DomNode(type); VisibleAdapter test = node.GetAdapter(typeof(VisibleAdapter)) as VisibleAdapter; Assert.AreSame(test.GetAdapter(typeof(object)), node.GetAdapter(typeof(object))); Assert.AreEqual(test.GetAdapterType, typeof(object)); Assert.AreSame(test.GetAdapter(typeof(VisibleAdapter)), node.GetAdapter(typeof(VisibleAdapter))); Assert.AreSame(test.GetAdapter(typeof(SimpleAdapter)), node.GetAdapter(typeof(SimpleAdapter))); }
public void TestExtensionsAfterConstructing() { DomNodeType type = new DomNodeType("test"); ExtensionInfo info1 = new ExtensionInfo <TestDomNode>(); type.Define(info1); ExtensionInfo info2 = new ExtensionInfo <int>(); type.Define(info2); DomNode test = new DomNode(type); Assert.True(test.GetExtension(info1) as TestDomNode != null); Assert.True(test.GetExtension(info2) is int); }
public void TestGetDecorators() { DomNodeType type = new DomNodeType("type"); type.Define(new ExtensionInfo <VisibleAdapter>()); type.Define(new ExtensionInfo <SimpleAdapter>()); DomNode node = new DomNode(type); VisibleAdapter test = node.GetAdapter(typeof(VisibleAdapter)) as VisibleAdapter; Assert.True(test.GetDecorators(typeof(DomNodeAdapter)).SequenceEqual(node.GetDecorators(typeof(DomNodeAdapter)))); Assert.AreEqual(test.GetDecoratorsType, typeof(DomNodeAdapter)); Assert.True(test.GetDecorators(typeof(SimpleAdapter)).SequenceEqual(node.GetDecorators(typeof(SimpleAdapter)))); }
public void TestGetSetReference() { DomNodeType type = new DomNodeType("type"); AttributeInfo refInfo = GetRefAttribute("ref"); type.Define(refInfo); type.Define(new ExtensionInfo <VisibleAdapter>()); DomNode node = new DomNode(type); DomNode refNode = new DomNode(type); VisibleAdapter test = node.GetAdapter(typeof(VisibleAdapter)) as VisibleAdapter; VisibleAdapter adapter = refNode.GetAdapter(typeof(VisibleAdapter)) as VisibleAdapter; test.SetReference(refInfo, adapter); Assert.AreSame(test.GetReference <VisibleAdapter>(refInfo), adapter); }
public void TestBaseOfAllTypes() { DomNodeType test = DomNodeType.BaseOfAllTypes; Assert.NotNull(test); CollectionAssert.IsEmpty(test.Attributes); CollectionAssert.IsEmpty(test.Children); CollectionAssert.IsEmpty(test.Extensions); Assert.Null(test.BaseType); // test that it's frozen Assert.Throws <InvalidOperationException>(delegate { test.BaseType = new DomNodeType("foo"); }); Assert.Throws <InvalidOperationException>(delegate { test.Define(GetStringAttribute("foo")); }); Assert.Throws <InvalidOperationException>(delegate { test.Define(new ChildInfo("foo", new DomNodeType("foo"))); }); Assert.Throws <InvalidOperationException>(delegate { test.Define(new ExtensionInfo <int>()); }); }
public void TestGetLowestCommonAncestor() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); DomNode child1 = new DomNode(type); DomNode child2 = new DomNode(type); parent.GetChildList(childInfo).Add(child1); parent.GetChildList(childInfo).Add(child2); DomNode grandchild1 = new DomNode(type); child1.GetChildList(childInfo).Add(grandchild1); DomNode grandchild2 = new DomNode(type); child2.GetChildList(childInfo).Add(grandchild2); Assert.AreSame(DomNode.GetLowestCommonAncestor(child1, child2), parent); Assert.AreSame(DomNode.GetLowestCommonAncestor(grandchild1, grandchild2), parent); Assert.AreSame(DomNode.GetLowestCommonAncestor(child1, grandchild1), child1); Assert.AreSame(DomNode.GetLowestCommonAncestor(new DomNode[] { child1, child2, grandchild1 }), parent); }
public void TestGetAttribute() { DomNodeType type = new DomNodeType("child"); AttributeInfo info = GetIntAttribute("int"); type.Define(info); DomNode test = new DomNode(type); 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)); }
// Tests http://tracker.ship.scea.com/jira/browse/WWSATF-1370 // Test adding two types of extensions that have the same Name but different FullName. public void TestDuplicateNames() { var domType = new DomNodeType("domType"); var extension = new ExtensionInfo <TestExtensionInfo>(); domType.Define(extension); var domDerivedType = new DomNodeType("domDerivedType", domType); var anotherExtension = new ExtensionInfo <AnotherName.TestExtensionInfo>(); domDerivedType.Define(anotherExtension); var domNode = new DomNode(domDerivedType); domNode.InitializeExtensions(); Assert.IsTrue(domNode.GetExtension(extension).GetType() == typeof(TestExtensionInfo)); Assert.IsTrue(domNode.GetExtension(anotherExtension).GetType() == typeof(AnotherName.TestExtensionInfo)); ExtensionInfo getInfo = domType.GetExtensionInfo("UnitTests.Atf.Dom.TestExtensionInfo"); Assert.IsNotNull(getInfo); Assert.AreEqual(getInfo, extension); getInfo = domDerivedType.GetExtensionInfo("UnitTests.Atf.Dom.TestExtensionInfo"); Assert.IsNotNull(getInfo); Assert.AreEqual(getInfo, extension); ExtensionInfo anotherGetInfo = domDerivedType.GetExtensionInfo("UnitTests.Atf.Dom.AnotherName.TestExtensionInfo"); Assert.IsNotNull(anotherGetInfo); Assert.AreEqual(anotherGetInfo, anotherExtension); }
public void TestValidate() { DomNodeType childType = new DomNodeType("child"); DomNodeType parentType = new DomNodeType("parent"); ChildInfo childInfo = new ChildInfo("child", childType, true); parentType.Define(childInfo); DomNode parent = new DomNode(parentType); IList <DomNode> childList = parent.GetChildList(childInfo); DomNode child1 = new DomNode(childType); DomNode child2 = new DomNode(childType); DomNode child3 = new DomNode(childType); ChildCountRule test = new ChildCountRule(1, 2); // 0 children. Not valid. Assert.False(test.Validate(parent, null, childInfo)); // 1 child. Valid. childList.Add(child1); Assert.True(test.Validate(parent, null, childInfo)); // 2 children. Valid. childList.Add(child2); Assert.True(test.Validate(parent, null, childInfo)); // 3 children. Not valid. childList.Add(child3); Assert.False(test.Validate(parent, null, childInfo)); // 0 children. Not valid. childList.Clear(); Assert.False(test.Validate(parent, null, childInfo)); }
// Tests http://tracker.ship.scea.com/jira/browse/WWSATF-1370 // Test adding two types of extensions that have the same Name but different FullName. public void TestDuplicateNames() { var domType = new DomNodeType("domType"); var extension = new ExtensionInfo<TestExtensionInfo>(); domType.Define(extension); var domDerivedType = new DomNodeType("domDerivedType", domType); var anotherExtension = new ExtensionInfo<AnotherName.TestExtensionInfo>(); domDerivedType.Define(anotherExtension); var domNode = new DomNode(domDerivedType); domNode.InitializeExtensions(); Assert.IsTrue(domNode.GetExtension(extension).GetType() == typeof(TestExtensionInfo)); Assert.IsTrue(domNode.GetExtension(anotherExtension).GetType() == typeof(AnotherName.TestExtensionInfo)); ExtensionInfo getInfo = domType.GetExtensionInfo("UnitTests.Atf.Dom.TestExtensionInfo"); Assert.IsNotNull(getInfo); Assert.AreEqual(getInfo, extension); getInfo = domDerivedType.GetExtensionInfo("UnitTests.Atf.Dom.TestExtensionInfo"); Assert.IsNotNull(getInfo); Assert.AreEqual(getInfo, extension); ExtensionInfo anotherGetInfo = domDerivedType.GetExtensionInfo("UnitTests.Atf.Dom.AnotherName.TestExtensionInfo"); Assert.IsNotNull(anotherGetInfo); Assert.AreEqual(anotherGetInfo, anotherExtension); }
public void TestDefaultValue() { AttributeType type = new AttributeType("test", typeof(string)); AttributeInfo test = new AttributeInfo("test", type); test.DefaultValue = "foo"; Assert.AreEqual(test.DefaultValue, "foo"); test.DefaultValue = null; Assert.AreEqual(test.DefaultValue, type.GetDefault()); Assert.Throws<InvalidOperationException>(delegate { test.DefaultValue = 1; }); AttributeType length2Type = new AttributeType("length2Type", typeof(int[]), 2); AttributeInfo length2Info = new AttributeInfo("length2", length2Type); Assert.AreEqual(length2Info.DefaultValue, length2Type.GetDefault()); Assert.AreEqual(length2Info.DefaultValue, new int[] { default(int), default(int) }); DomNodeType nodeType = new DomNodeType("testNodeType"); nodeType.Define(length2Info); DomNode node = new DomNode(nodeType); Assert.AreEqual(node.GetAttribute(length2Info), length2Info.DefaultValue); node.SetAttribute(length2Info, new int[] { 1, 2 }); Assert.AreEqual(node.GetAttribute(length2Info), new int[] { 1, 2 }); node.SetAttribute(length2Info, new int[] { 1 }); Assert.AreEqual(node.GetAttribute(length2Info), new int[] { 1 }); AttributeType length1Type = new AttributeType("length1Type", typeof(int[]), 1); AttributeInfo length1Info = new AttributeInfo("length1", length1Type); Assert.AreEqual(length1Info.DefaultValue, length1Type.GetDefault()); Assert.AreEqual(length1Info.DefaultValue, new int[] { default(int) }); nodeType = new DomNodeType("testNodeType"); nodeType.Define(length1Info); node = new DomNode(nodeType); Assert.AreEqual(node.GetAttribute(length1Info), length1Info.DefaultValue); node.SetAttribute(length1Info, new int[] { 1 }); Assert.AreEqual(node.GetAttribute(length1Info), new int[] { 1 }); }
public void TestValidate() { DomNodeType childType = new DomNodeType("child"); DomNodeType parentType = new DomNodeType("parent"); ChildInfo childInfo = new ChildInfo("child", childType, true); parentType.Define(childInfo); DomNode parent = new DomNode(parentType); IList<DomNode> childList = parent.GetChildList(childInfo); DomNode child1 = new DomNode(childType); DomNode child2 = new DomNode(childType); DomNode child3 = new DomNode(childType); ChildCountRule test = new ChildCountRule(1, 2); // 0 children. Not valid. Assert.False(test.Validate(parent, null, childInfo)); // 1 child. Valid. childList.Add(child1); Assert.True(test.Validate(parent, null, childInfo)); // 2 children. Valid. childList.Add(child2); Assert.True(test.Validate(parent, null, childInfo)); // 3 children. Not valid. childList.Add(child3); Assert.False(test.Validate(parent, null, childInfo)); // 0 children. Not valid. childList.Clear(); Assert.False(test.Validate(parent, null, childInfo)); }
public void TestGetChildList() { DomNodeType type = new DomNodeType("type"); ChildInfo info = new ChildInfo("child", type, true); type.Define(info); type.Define(new ExtensionInfo <VisibleAdapter>()); DomNode node = new DomNode(type); DomNode child = new DomNode(type); VisibleAdapter test = node.GetAdapter(typeof(VisibleAdapter)) as VisibleAdapter; VisibleAdapter adapter = child.GetAdapter(typeof(VisibleAdapter)) as VisibleAdapter; IList <VisibleAdapter> list = test.GetChildList <VisibleAdapter>(info); Assert.NotNull(list); }
public void TestParentChildren() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo1 = new ChildInfo("child1", type); type.Define(childInfo1); ChildInfo childInfo2 = new ChildInfo("child2", type, true); type.Define(childInfo2); DomNode child1 = new DomNode(type); DomNode child2 = new DomNode(type); DomNode parent = new DomNode(type); parent.SetChild(childInfo1, child1); parent.GetChildList(childInfo2).Add(child2); Utilities.TestSequenceEqual(parent.Children, child1, child2); }
public TestValidator() { // define a tree of validation contexts m_childType = new DomNodeType("test"); m_stringAttrInfo = GetStringAttribute("string"); m_childType.Define(m_stringAttrInfo); m_refAttrInfo = GetRefAttribute("ref"); m_childType.Define(m_refAttrInfo); m_childInfo = new ChildInfo("child", m_childType); m_childType.Define(m_childInfo); m_childType.Define(new ExtensionInfo<ValidationContext>()); // define a distinct root type with the validator m_rootType = new DomNodeType("root"); m_rootType.BaseType = m_childType; m_rootType.Define(new ExtensionInfo<Validator>()); IEnumerable<AttributeInfo> attributes = m_rootType.Attributes; // freezes the types }
public TestValidator() { // define a tree of validation contexts m_childType = new DomNodeType("test"); m_stringAttrInfo = GetStringAttribute("string"); m_childType.Define(m_stringAttrInfo); m_refAttrInfo = GetRefAttribute("ref"); m_childType.Define(m_refAttrInfo); m_childInfo = new ChildInfo("child", m_childType); m_childType.Define(m_childInfo); m_childType.Define(new ExtensionInfo <ValidationContext>()); // define a distinct root type with the validator m_rootType = new DomNodeType("root"); m_rootType.BaseType = m_childType; m_rootType.Define(new ExtensionInfo <Validator>()); IEnumerable <AttributeInfo> attributes = m_rootType.Attributes; // freezes the types }
public void TestGetSetAttribute() { DomNodeType type = new DomNodeType("type"); AttributeInfo intInfo = GetIntAttribute("int"); type.Define(intInfo); AttributeInfo stringInfo = GetStringAttribute("string"); type.Define(stringInfo); type.Define(new ExtensionInfo <VisibleAdapter>()); DomNode node = new DomNode(type); VisibleAdapter test = node.GetAdapter(typeof(VisibleAdapter)) as VisibleAdapter; test.SetAttribute(intInfo, 1); Assert.AreEqual(test.GetAttribute <int>(intInfo), 1); test.SetAttribute(stringInfo, "foo"); Assert.AreEqual(test.GetAttribute <string>(stringInfo), "foo"); }
public void TestGetSetChild() { DomNodeType type = new DomNodeType("type"); ChildInfo info = new ChildInfo("child", type); type.Define(info); type.Define(new ExtensionInfo <VisibleAdapter>()); DomNode node = new DomNode(type); DomNode child = new DomNode(type); VisibleAdapter test = node.GetAdapter(typeof(VisibleAdapter)) as VisibleAdapter; VisibleAdapter adapter = child.GetAdapter(typeof(VisibleAdapter)) as VisibleAdapter; test.SetChild(info, adapter); Assert.AreSame(test.GetChild <VisibleAdapter>(info), adapter); test.SetChild(info, null); Assert.Null(test.GetChild <VisibleAdapter>(info)); }
public void TestEquality() { var attrType1 = new AttributeType("xkcd", typeof(string)); var attrInfo1 = new AttributeInfo("xkcd", attrType1); var domNodeType = new DomNodeType("WebComic", DomNodeType.BaseOfAllTypes); var childInfo1 = new ChildInfo("xkcd", domNodeType); attrInfo1.DefaultValue = "Firefly"; var desc1 = new ChildAttributePropertyDescriptor( "xkcd", attrInfo1, childInfo1, "Category 1", "A commonly used word or phrase in the xkcd comic", true); int originalHashCode = desc1.GetHashCode(); // test if two identically created property descriptors compare as being equal var desc2 = new ChildAttributePropertyDescriptor( "xkcd", attrInfo1, childInfo1, "Category 1", "A commonly used word or phrase in the xkcd comic", true); Assert.AreEqual(desc1, desc2); Assert.AreEqual(desc1.GetHashCode(), desc2.GetHashCode()); // test category being different; oddly, although I think they should not be considered equal, // the .Net PropertyDescriptor ignores the difference in category name. So, I'm guessing that // the AttributePropertyDescriptor should behave the same as PropertyDescriptor. var desc3 = new ChildAttributePropertyDescriptor( "xkcd", attrInfo1, childInfo1, "Category 2", "A commonly used word or phrase in the xkcd comic", true); Assert.AreEqual(desc1, desc3); Assert.AreEqual(desc1.GetHashCode(), desc3.GetHashCode()); // test description being different; similarly here, the .Net PropertyDescriptor doesn't care. var desc4 = new ChildAttributePropertyDescriptor( "xkcd", attrInfo1, childInfo1, "Category 1", "slightly different description", true); Assert.AreEqual(desc1, desc4); Assert.AreEqual(desc1.GetHashCode(), desc4.GetHashCode()); // test readOnly being different; ditto for read-only flag! var desc5 = new ChildAttributePropertyDescriptor( "xkcd", attrInfo1, childInfo1, "Category 1", "A commonly used word or phrase in the xkcd comic", false); Assert.AreEqual(desc1, desc5); Assert.AreEqual(desc1.GetHashCode(), desc5.GetHashCode()); // test that the hash code hasn't changed after using the AttributeInfo var attrInfo2 = new AttributeInfo("xkcd", attrType1); domNodeType.Define(attrInfo2); Assert.AreEqual(desc1.GetHashCode(), originalHashCode); // test that the hash code hasn't changed after creating a derived DomNodeType var derivedDomNodeType = new DomNodeType("ScientificWebComic", domNodeType); var derivedAttrInfo = new AttributeInfo("xkcd", attrType1); var derivedChildInfo = new ChildInfo("xkcd", derivedDomNodeType); derivedDomNodeType.Define(derivedAttrInfo); Assert.AreEqual(desc1.GetHashCode(), originalHashCode); // test that an AttributeInfo used in a derived DomNodeType doesn't change equality or hash code var desc6 = new ChildAttributePropertyDescriptor( "xkcd", derivedAttrInfo, derivedChildInfo, "Category 1", "A commonly used word or phrase in the xkcd comic", true); Assert.AreEqual(desc1, desc6); Assert.AreEqual(desc1.GetHashCode(), desc6.GetHashCode()); }
public void TestEqualsDomNodeAdapter() { DomNodeType type = new DomNodeType("type"); type.Define(new ExtensionInfo <SimpleAdapter>()); DomNode node = new DomNode(type); SimpleAdapter test = node.GetAdapter(typeof(SimpleAdapter)) as SimpleAdapter; Assert.True(test.Equals(node)); }
public void TestGetNonDomNodeAdapter() { DomNodeType type = new DomNodeType("type"); type.Define(new ExtensionInfo <NonDomNodeAdapter>()); DomNode node = new DomNode(type); NonDomNodeAdapter test = node.GetAdapter(typeof(NonDomNodeAdapter)) as NonDomNodeAdapter; Assert.NotNull(test); }
public void TestEqualityNonDomNodeAdapter() { DomNodeType type = new DomNodeType("type"); type.Define(new ExtensionInfo <NonDomNodeAdapter>()); DomNode node = new DomNode(type); NonDomNodeAdapter test = node.GetAdapter(typeof(NonDomNodeAdapter)) as NonDomNodeAdapter; Assert.True(node.Equals(test)); }
public void TestChildListReadonly() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); IList <DomNode> list = parent.GetChildList(childInfo); Assert.False(list.IsReadOnly); }
public void TestChildParent() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode child = new DomNode(type); DomNode parent = new DomNode(type); parent.GetChildList(childInfo).Add(child); Assert.AreSame(child.Parent, parent); }
protected DomNodeType RootType;//derives from ChildType public TestValidator() { // define a tree of validation contexts ChildType = new DomNodeType("test"); StringAttrInfo = GetStringAttribute("string"); ChildType.Define(StringAttrInfo); RefAttrInfo = GetRefAttribute("ref"); ChildType.Define(RefAttrInfo); ChildInfo = new ChildInfo("child", ChildType); ChildType.Define(ChildInfo); ChildType.Define(new ExtensionInfo<ValidationContext>()); // define a distinct root type with the validator RootType = new DomNodeType("root"); RootType.BaseType = ChildType; RootType.Define(new ExtensionInfo<Validator>()); AttributeInfo overriddenInfo = GetStringAttribute("string"); RootType.Define(overriddenInfo); IEnumerable<AttributeInfo> attributes = RootType.Attributes; // freezes the types }
public TestDataValidator() { m_childType = new DomNodeType("child"); m_parentType = new DomNodeType("parent"); m_parentType.Define(new ExtensionInfo <ValidationContext>()); m_parentType.Define(new ExtensionInfo <DataValidator>()); m_childCountRule = new ChildCountRule(2, 3); m_childInfo = new ChildInfo("child", m_childType, true); m_parentType.Define(m_childInfo); m_childInfo.AddRule(m_childCountRule); m_parent = new DomNode(m_parentType); m_parent.InitializeExtensions(); m_validationContext = m_parent.As <ValidationContext>(); m_child1 = new DomNode(m_childType); m_child2 = new DomNode(m_childType); m_child3 = new DomNode(m_childType); m_child4 = new DomNode(m_childType); }
protected DomNodeType RootType; //derives from ChildType public TestValidator() { // define a tree of validation contexts ChildType = new DomNodeType("test"); StringAttrInfo = GetStringAttribute("string"); ChildType.Define(StringAttrInfo); RefAttrInfo = GetRefAttribute("ref"); ChildType.Define(RefAttrInfo); ChildInfo = new ChildInfo("child", ChildType); ChildType.Define(ChildInfo); ChildType.Define(new ExtensionInfo <ValidationContext>()); // define a distinct root type with the validator RootType = new DomNodeType("root"); RootType.BaseType = ChildType; RootType.Define(new ExtensionInfo <Validator>()); AttributeInfo overriddenInfo = GetStringAttribute("string"); RootType.Define(overriddenInfo); IEnumerable <AttributeInfo> attributes = RootType.Attributes; // freezes the types }
public void TestDescendantGetRoot() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode child = new DomNode(type); DomNode parent = new DomNode(type); DomNode grandparent = new DomNode(type); parent.GetChildList(childInfo).Add(child); grandparent.GetChildList(childInfo).Add(parent); Assert.AreSame(child.GetRoot(), grandparent); }
public void TestCopy_SingleNode() { DomNodeType type = new DomNodeType("type"); AttributeInfo info = GetStringAttribute("string"); type.Define(info); DomNode test = new DomNode(type); test.SetAttribute(info, "foo"); DomNode[] result = DomNode.Copy(new DomNode[] { test }); Assert.True(Equals(result[0], test)); }
public TestDataValidator() { m_childType = new DomNodeType("child"); m_parentType = new DomNodeType("parent"); m_parentType.Define(new ExtensionInfo<ValidationContext>()); m_parentType.Define(new ExtensionInfo<DataValidator>()); m_childCountRule = new ChildCountRule(2, 3); m_childInfo = new ChildInfo("child", m_childType, true); m_parentType.Define(m_childInfo); m_childInfo.AddRule(m_childCountRule); m_parent = new DomNode(m_parentType); m_parent.InitializeExtensions(); m_validationContext = m_parent.As<ValidationContext>(); m_child1 = new DomNode(m_childType); m_child2 = new DomNode(m_childType); m_child3 = new DomNode(m_childType); m_child4 = new DomNode(m_childType); }
public void TestGetChild() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type); type.Define(childInfo); DomNode parent = new DomNode(type); DomNode child = new DomNode(type); parent.SetChild(childInfo, child); Assert.AreSame(parent.GetChild(childInfo), child); Assert.Throws <InvalidOperationException>(delegate { parent.GetChildList(childInfo); }); }
public void TestRemoveFromParentList() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); DomNode child = new DomNode(type); parent.GetChildList(childInfo).Add(child); child.RemoveFromParent(); CollectionAssert.IsEmpty(parent.Children); Assert.Null(child.Parent); }
public void TestGetChildList() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); IList <DomNode> list = parent.GetChildList(childInfo); Assert.NotNull(list); Assert.Throws <InvalidOperationException>(delegate { parent.GetChild(childInfo); }); CollectionAssert.IsEmpty(list); }
public void TestGetPath() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode child = new DomNode(type); DomNode parent = new DomNode(type); DomNode grandparent = new DomNode(type); parent.GetChildList(childInfo).Add(child); grandparent.GetChildList(childInfo).Add(parent); Utilities.TestSequenceEqual(child.GetPath(), grandparent, parent, child); Utilities.TestSequenceEqual(parent.GetPath(), grandparent, parent); Utilities.TestSequenceEqual(grandparent.GetPath(), grandparent); }
public void TestChildListRemove() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); IList<DomNode> list = parent.GetChildList(childInfo); DomNode child1 = new DomNode(type); Assert.False(list.Remove(child1)); list.Add(child1); DomNode child2 = new DomNode(type); list.Add(child2); Assert.True(list.Remove(child1)); Utilities.TestSequenceEqual(list, child2); Assert.True(list.Remove(child2)); CollectionAssert.IsEmpty(list); }
public void TestChildListReadonly() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); IList<DomNode> list = parent.GetChildList(childInfo); Assert.False(list.IsReadOnly); }
public void TestChildListContains() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); IList<DomNode> list = parent.GetChildList(childInfo); DomNode child1 = new DomNode(type); Assert.False(list.Contains(child1)); list.Add(child1); DomNode child2 = new DomNode(type); list.Add(child2); Assert.True(list.Contains(child2)); }
public void TestChildListCopyTo() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); IList<DomNode> list = parent.GetChildList(childInfo); DomNode child1 = new DomNode(type); list.Add(child1); DomNode child2 = new DomNode(type); list.Add(child2); DomNode[] array = new DomNode[list.Count + 1]; list.CopyTo(array, 1); Utilities.TestSequenceEqual(array, null, child1, child2); }
public void TestChildListIndexer() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); IList<DomNode> list = parent.GetChildList(childInfo); DomNode child1 = new DomNode(type); Assert.Throws<IndexOutOfRangeException>(delegate { list[0] = child1; }); list.Add(child1); Assert.AreSame(list[0], child1); DomNode child2 = new DomNode(type); list.Add(child2); Assert.AreSame(list[1], child2); DomNode child3 = new DomNode(type); list[0] = child3; Utilities.TestSequenceEqual(list, child3, child2); // child1 gets removed by set }
public void TestCopy_SingleNode() { DomNodeType type = new DomNodeType("type"); AttributeInfo info = GetStringAttribute("string"); type.Define(info); DomNode test = new DomNode(type); test.SetAttribute(info, "foo"); DomNode[] result = DomNode.Copy(new DomNode[] { test }); Assert.True(Equals(result[0], test)); DomNode singleResult = DomNode.Copy(test); Assert.True(Equals(singleResult, test)); }
public void TestChildRemoveEvents() { DomNodeType type = new DomNodeType("type"); ChildInfo info = new ChildInfo("child", type); ChildInfo infoList = new ChildInfo("childList", type, true); type.Define(info); type.Define(infoList); DomNode test = new DomNode(type); test.ChildRemoving += new EventHandler<ChildEventArgs>(test_ChildRemoving); test.ChildRemoved += new EventHandler<ChildEventArgs>(test_ChildRemoved); // test child DomNode child = new DomNode(type); test.SetChild(info, child); ChildRemovingArgs = null; ChildRemovedArgs = null; test.SetChild(info, null); ChildEventArgs expected = new ChildEventArgs(test, info, child, 0); Assert.True(Equals(ChildRemovingArgs, expected)); Assert.True(Equals(ChildRemovedArgs, expected)); // test inserting a child when there is one there already test.SetChild(info, child); DomNode newChild = new DomNode(type); ChildRemovingArgs = null; ChildRemovedArgs = null; test.SetChild(info, newChild); expected = new ChildEventArgs(test, info, child, 0); Assert.True(Equals(ChildRemovingArgs, expected)); Assert.True(Equals(ChildRemovedArgs, expected)); // test child list IList<DomNode> list = test.GetChildList(infoList); DomNode child2 = new DomNode(type); list.Add(child2); DomNode child3 = new DomNode(type); list.Add(child3); ChildRemovingArgs = null; ChildRemovedArgs = null; list.Remove(child3); expected = new ChildEventArgs(test, infoList, child3, 1); Assert.True(Equals(ChildRemovingArgs, expected)); Assert.True(Equals(ChildRemovedArgs, expected)); ChildRemovingArgs = null; ChildRemovedArgs = null; list.Remove(child2); expected = new ChildEventArgs(test, infoList, child2, 0); Assert.True(Equals(ChildRemovingArgs, expected)); Assert.True(Equals(ChildRemovedArgs, expected)); }
public void TestAttributeChangedEvents() { DomNodeType type = new DomNodeType("type"); AttributeInfo stringTypeInfo = GetStringAttribute("string"); AttributeInfo intTypeInfo = GetIntAttribute("int"); type.Define(stringTypeInfo); type.Define(intTypeInfo); DomNode test = new DomNode(type); test.AttributeChanging += new EventHandler<AttributeEventArgs>(test_AttributeChanging); test.AttributeChanged += new EventHandler<AttributeEventArgs>(test_AttributeChanged); AttributeEventArgs expected; // test for no value change if setting to the default value and attribute is already the default AttributeChangingArgs = null; AttributeChangedArgs = null; test.SetAttribute(stringTypeInfo, stringTypeInfo.DefaultValue); Assert.Null(AttributeChangingArgs); Assert.Null(AttributeChangedArgs); test.SetAttribute(intTypeInfo, intTypeInfo.DefaultValue); Assert.Null(AttributeChangingArgs); Assert.Null(AttributeChangedArgs); // test for value change, string type test = new DomNode(type); test.AttributeChanging += new EventHandler<AttributeEventArgs>(test_AttributeChanging); test.AttributeChanged += new EventHandler<AttributeEventArgs>(test_AttributeChanged); AttributeChangingArgs = null; AttributeChangedArgs = null; object oldValue = test.GetAttribute(stringTypeInfo); test.SetAttribute(stringTypeInfo, "foo"); expected = new AttributeEventArgs(test, stringTypeInfo, oldValue, "foo"); Assert.True(Equals(AttributeChangingArgs, expected)); Assert.True(Equals(AttributeChangedArgs, expected)); oldValue = test.GetAttribute(stringTypeInfo); test.SetAttribute(stringTypeInfo, "foobar"); expected = new AttributeEventArgs(test, stringTypeInfo, oldValue, "foobar"); Assert.True(Equals(AttributeChangingArgs, expected)); Assert.True(Equals(AttributeChangedArgs, expected)); // test for value change, int type AttributeChangingArgs = null; AttributeChangedArgs = null; oldValue = test.GetAttribute(intTypeInfo); test.SetAttribute(intTypeInfo, 5); expected = new AttributeEventArgs(test, intTypeInfo, oldValue, 5); Assert.True(Equals(AttributeChangingArgs, expected)); Assert.True(Equals(AttributeChangedArgs, expected)); oldValue = test.GetAttribute(intTypeInfo); test.SetAttribute(intTypeInfo, 7); expected = new AttributeEventArgs(test, intTypeInfo, oldValue, 7); Assert.True(Equals(AttributeChangingArgs, expected)); Assert.True(Equals(AttributeChangedArgs, expected)); // test for no value change test.SetAttribute(stringTypeInfo, "foo"); AttributeChangingArgs = null; AttributeChangedArgs = null; test.SetAttribute(stringTypeInfo, "foo"); Assert.Null(AttributeChangingArgs); Assert.Null(AttributeChangedArgs); test.SetAttribute(intTypeInfo, 9); AttributeChangingArgs = null; AttributeChangedArgs = null; test.SetAttribute(intTypeInfo, 9); Assert.Null(AttributeChangingArgs); Assert.Null(AttributeChangedArgs); }
public void TestRemoveFromParent() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type); type.Define(childInfo); DomNode parent = new DomNode(type); DomNode child = new DomNode(type); parent.SetChild(childInfo, child); child.RemoveFromParent(); Assert.Null(parent.GetChild(childInfo)); Assert.Null(child.Parent); // Make sure the removed child has a null Parent. http://tracker.ship.scea.com/jira/browse/WWSATF-1336 parent.SetChild(childInfo, child); DomNode newChild = new DomNode(type); parent.SetChild(childInfo, newChild); Assert.Null(child.Parent); Assert.True(newChild.Parent == parent); }
public void TestChildListAdd() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); IList<DomNode> list = parent.GetChildList(childInfo); DomNode child1 = new DomNode(type); list.Add(child1); Utilities.TestSequenceEqual(list, child1); DomNode child2 = new DomNode(type); list.Add(child2); Utilities.TestSequenceEqual(list, child1, child2); // add node that's already in the list; should remove it from old location list.Add(child1); Utilities.TestSequenceEqual(list, child2, child1); }
public void TestChildListInsert() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); IList<DomNode> list = parent.GetChildList(childInfo); DomNode child1 = new DomNode(type); list.Insert(0, child1); Utilities.TestSequenceEqual(list, child1); // insertion again will cause removal, then insertion list.Insert(0, child1); Utilities.TestSequenceEqual(list, child1); DomNode child2 = new DomNode(type); list.Insert(0, child2); Utilities.TestSequenceEqual(list, child2, child1); }
public void TestCustomAttributeInfo() { AttributeInfo info = new AttributeInfo("foo", new AttributeType("foo", typeof(string))); DomNodeType test = new DomNodeType( "test", null, new AttributeInfo[] { info }, EmptyEnumerable<ChildInfo>.Instance, EmptyEnumerable<ExtensionInfo>.Instance); Utilities.TestSequenceEqual(test.Attributes, info); Assert.True(test.IsValid(info)); Assert.AreSame(test.GetAttributeInfo("foo"), info); // check that type is now frozen Assert.Throws<InvalidOperationException>(delegate { test.Define(GetStringAttribute("notFoo")); }); Assert.AreEqual(info.OwningType, test); Assert.AreEqual(info.DefiningType, test); Assert.Null(test.GetAttributeInfo("bar")); }
public void TestGetChild() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type); type.Define(childInfo); DomNode parent = new DomNode(type); DomNode child = new DomNode(type); parent.SetChild(childInfo, child); Assert.AreSame(parent.GetChild(childInfo), child); Assert.Throws<InvalidOperationException>(delegate { parent.GetChildList(childInfo); }); }
public void TestChildListIndexOf() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); IList<DomNode> list = parent.GetChildList(childInfo); DomNode child1 = new DomNode(type); Assert.AreEqual(list.IndexOf(child1), -1); list.Insert(0, child1); Assert.AreEqual(list.IndexOf(child1), 0); DomNode child2 = new DomNode(type); list.Insert(0, child2); Assert.AreEqual(list.IndexOf(child2), 0); Assert.AreEqual(list.IndexOf(child1), 1); }
public void TestGetId() { DomNodeType testId = new DomNodeType("test"); AttributeInfo info = GetStringAttribute("string"); testId.Define(info); testId.SetIdAttribute(info.Name); DomNode test = new DomNode(testId); Assert.Null(test.GetId()); test.SetAttribute(info, "foo"); Assert.AreEqual(test.GetId(), "foo"); }
public void TestCopy_MultipleNodes() { DomNodeType type = new DomNodeType("type"); ChildInfo info = new ChildInfo("child", type); ChildInfo infoList = new ChildInfo("childList", type, true); type.Define(info); type.Define(infoList); ChildInfo rootInfo = new ChildInfo("root", type, true); DomNode test = new DomNode(type, rootInfo); DomNode child1 = new DomNode(type); test.SetChild(info, child1); DomNode child2 = new DomNode(type); DomNode child3 = new DomNode(type); IList<DomNode> list = test.GetChildList(infoList); list.Add(child2); list.Add(child3); DomNode[] result = DomNode.Copy(new DomNode[] { test }); Assert.AreEqual(result.Length, 1); Assert.True(Equals(result[0], test)); DomNode singleResult = DomNode.Copy(test); Assert.True(Equals(singleResult, test)); }
public void TestChildListClear() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); IList<DomNode> list = parent.GetChildList(childInfo); DomNode child1 = new DomNode(type); list.Add(child1); DomNode child2 = new DomNode(type); list.Add(child2); list.Clear(); CollectionAssert.IsEmpty(list); }
public void TestGetDescendantInfo() { DomNodeType grandchildType = new DomNodeType("grandchild"); ChildInfo grandChildInfo = new ChildInfo("grandChild", grandchildType); DomNodeType childType = new DomNodeType("child"); childType.Define(grandChildInfo); Assert.Null(childType.GetDescendantInfo(string.Empty)); Assert.Null(childType.GetDescendantInfo("foo")); Assert.AreSame(childType.GetDescendantInfo("grandChild"), grandChildInfo); ChildInfo childInfo = new ChildInfo("child", childType); DomNodeType parentType = new DomNodeType("parent"); parentType.Define(childInfo); Assert.AreSame(parentType.GetDescendantInfo("child"), childInfo); Assert.AreSame(parentType.GetDescendantInfo("child:grandChild"), grandChildInfo); }
public void TestGetChildList() { DomNodeType type = new DomNodeType("type"); ChildInfo childInfo = new ChildInfo("child", type, true); type.Define(childInfo); DomNode parent = new DomNode(type); IList<DomNode> list = parent.GetChildList(childInfo); Assert.NotNull(list); Assert.Throws<InvalidOperationException>(delegate { parent.GetChild(childInfo); }); CollectionAssert.IsEmpty(list); }