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 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 TestGetAdapterAsDomNode() { DomNodeType type = new DomNodeType("type"); DomNode node = new DomNode(type); Assert.AreSame(node.GetAdapter(typeof(DomNode)), node); }
public void TestGetDecoratorsInherited() { DomNodeType baseType = new DomNodeType("baseType"); baseType.Define(new ExtensionInfo <DerivedAdapter>()); // derived adapter on base type! DomNodeType derivedType = new DomNodeType("derivedType"); derivedType.BaseType = baseType; derivedType.Define(new ExtensionInfo <SimpleAdapter>()); DomNode node = new DomNode(derivedType); object simple = node.GetAdapter(typeof(SimpleAdapter)); object derived = node.GetAdapter(typeof(DerivedAdapter)); // test that they're returned in order of inheritance Utilities.TestSequenceEqual(node.GetDecorators(typeof(SimpleAdapter)), simple, derived); }
public void TestGetAdapterInherited() { DomNodeType baseType = new DomNodeType("baseType"); baseType.Define(new ExtensionInfo <DerivedAdapter>()); // derived adapter on base type! DomNodeType derivedType = new DomNodeType("derivedType"); derivedType.BaseType = baseType; derivedType.Define(new ExtensionInfo <SimpleAdapter>()); DomNode node = new DomNode(derivedType); object adapter = node.GetAdapter(typeof(SimpleAdapter)); Assert.True( (adapter is SimpleAdapter) && !(adapter is DerivedAdapter)); adapter = node.GetAdapter(typeof(DerivedAdapter)); Assert.True(adapter is DerivedAdapter); }
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 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 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); }
/// <summary> /// Gets an enumeration of properties for a specific DomNode</summary> /// <param name="node">DomNode on which to obtain properties</param> /// <returns>Enumeration of properties</returns> static internal PropertyDescriptorCollection GetDomNodeProperties(DomNode node) { if (node == null) return null; ICustomTypeDescriptor iCustomTypeDescriptor = node.GetAdapter(typeof(CustomTypeDescriptorNodeAdapter)) as ICustomTypeDescriptor; if (iCustomTypeDescriptor == null) return null; PropertyDescriptorCollection properties = iCustomTypeDescriptor.GetProperties(); return properties; }
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 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 TestOnNodeSet() { DomNodeType type = new DomNodeType("type"); type.Define(new ExtensionInfo <VisibleAdapter>()); DomNode node = new DomNode(type); VisibleAdapter test = node.GetAdapter(typeof(VisibleAdapter)) as VisibleAdapter; Assert.NotNull(test); Assert.AreSame(test.DomNode, node); Assert.AreSame(((IAdapter)test).Adaptee, node); Assert.True(test.OnNodeSetCalled); Assert.Null(test.GetAdapterType); Assert.Null(test.GetDecoratorsType); }
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); }
/// <summary> /// Gets the collection of PropertyDescriptors that make up a DomNode instance</summary> /// <param name="node">The DomNode whose properties are retrieved</param> /// <returns>The collection of PropertyDescriptors owned by the specified DomNode</returns> static internal PropertyDescriptorCollection GetDomNodeProperties(DomNode node) { if (node == null) { return(null); } ICustomTypeDescriptor iCustomTypeDescriptor = node.GetAdapter(typeof(CustomTypeDescriptorNodeAdapter)) as ICustomTypeDescriptor; if (iCustomTypeDescriptor == null) { return(null); } PropertyDescriptorCollection properties = iCustomTypeDescriptor.GetProperties(); return(properties); }
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 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"); }
/// <summary> /// Produces an object that, given the specified object, can enumerate over queryable elements owned by that object. /// For this implementation, the specified object must be a DomNode.</summary> /// <param name="item">The object containing the queryable elements</param> /// <returns>An object that implements IQueryable on elements of the specified object</returns> protected override IQueryable GetQueryableElements(object item) { IQueryable returnValue = null; DomNode domNode = item as DomNode; if (domNode != null) { // see summary of "DomNode" property for an explanation on why we don't simply use local variable domNode m_domNode = domNode; // Get dom node properties, encapsulate into PropertyDescriptorQueryable ICustomTypeDescriptor iCustomTypeDescriptor = m_domNode.GetAdapter(typeof(ICustomTypeDescriptor)) as ICustomTypeDescriptor; if (iCustomTypeDescriptor != null) { PropertyDescriptorCollection domNodeProperties = iCustomTypeDescriptor.GetProperties(); returnValue = new PropertyDescriptorQueryable(domNodeProperties, m_domNode).AsQueryable(); } } return(returnValue); }
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 TestGetDecoratorsInherited() { DomNodeType baseType = new DomNodeType("baseType"); baseType.Define(new ExtensionInfo<DerivedAdapter>()); // derived adapter on base type! DomNodeType derivedType = new DomNodeType("derivedType"); derivedType.BaseType = baseType; derivedType.Define(new ExtensionInfo<SimpleAdapter>()); DomNode node = new DomNode(derivedType); object simple = node.GetAdapter(typeof(SimpleAdapter)); object derived = node.GetAdapter(typeof(DerivedAdapter)); // test that they're returned in order of inheritance Utilities.TestSequenceEqual(node.GetDecorators(typeof(SimpleAdapter)), simple, derived); }
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 TestGetAdapterInherited() { DomNodeType baseType = new DomNodeType("baseType"); baseType.Define(new ExtensionInfo<DerivedAdapter>()); // derived adapter on base type! DomNodeType derivedType = new DomNodeType("derivedType"); derivedType.BaseType = baseType; derivedType.Define(new ExtensionInfo<SimpleAdapter>()); DomNode node = new DomNode(derivedType); object adapter = node.GetAdapter(typeof(SimpleAdapter)); Assert.True( (adapter is SimpleAdapter) && !(adapter is DerivedAdapter)); adapter = node.GetAdapter(typeof(DerivedAdapter)); Assert.True(adapter is DerivedAdapter); }
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); }