本文整理汇总了C#中DomNodeType.Define方法的典型用法代码示例。如果您正苦于以下问题:C# DomNodeType.Define方法的具体用法?C# DomNodeType.Define怎么用?C# DomNodeType.Define使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomNodeType
的用法示例。
在下文中一共展示了DomNodeType.Define方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestDefaultValue
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 });
}
示例2: TestDuplicateNames
// 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);
}
示例3: TestValidate
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));
}
示例4: TestValidator
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
}
示例5: TestEquality
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());
}
示例6: TestChildParent
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);
}
示例7: TestValidator
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
}
示例8: TestDescendantGetRoot
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);
}
示例9: TestDataValidator
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);
}
示例10: TestGetPath
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);
}
示例11: TestAttributeChangedEvents
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);
}
示例12: TestRemoveFromParent
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);
}
示例13: TestRemoveFromParentList
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);
}
示例14: TestCustomAttributeInfo
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"));
}
示例15: TestChildListInsert
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);
}