Esempio n. 1
0
        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))));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public void TestDuplicateExtensionInfo()
        {
            var ext1 = new ExtensionInfo <TestAdapter1>("foo");
            var ext2 = new ExtensionInfo <TestAdapter2>("foo");

            var domType = new DomNodeType(
                "test",
                null,
                EmptyEnumerable <AttributeInfo> .Instance,
                EmptyEnumerable <ChildInfo> .Instance,
                new ExtensionInfo[] { ext1, ext2 });

            var domNode = new DomNode(domType);

            object resultExt1 = domNode.GetExtension(ext1);
            object resultExt2 = domNode.GetExtension(ext2);

            Assert.IsTrue(resultExt1 is TestAdapter1);
            Assert.IsTrue(resultExt2 is TestAdapter2);

            object[] decorators = domNode.GetDecorators(typeof(object)).ToArray();
            Assert.IsTrue(
                decorators.Length == 2 &&
                decorators[0] == resultExt1 &&
                decorators[1] == resultExt2);

            DomNodeAdapter[] extensions = domNode.AsAll <DomNodeAdapter>().ToArray();
            Assert.IsTrue(
                extensions.Length == 2 &&
                extensions[0] == resultExt1 &&
                extensions[1] == resultExt2);

            // Searching by name is a problem, though. The search is ambiguous.
            // See tracker item for discussion: http://tracker.ship.scea.com/jira/browse/WWSATF-522
            Assert.Throws <InvalidOperationException>(() => domType.GetExtensionInfo("foo"));
        }
Esempio n. 5
0
        public void TestDuplicateExtensionInfo()
        {
            var ext1 = new ExtensionInfo<TestAdapter1>("foo");
            var ext2 = new ExtensionInfo<TestAdapter2>("foo");

            var domType = new DomNodeType(
                "test",
                null,
                EmptyEnumerable<AttributeInfo>.Instance,
                EmptyEnumerable<ChildInfo>.Instance,
                new ExtensionInfo[] { ext1, ext2 });

            var domNode = new DomNode(domType);

            object resultExt1 = domNode.GetExtension(ext1);
            object resultExt2 = domNode.GetExtension(ext2);

            Assert.IsTrue(resultExt1 is TestAdapter1);
            Assert.IsTrue(resultExt2 is TestAdapter2);

            object[] decorators = domNode.GetDecorators(typeof(object)).ToArray();
            Assert.IsTrue(
                decorators.Length == 2 &&
                decorators[0] == resultExt1 &&
                decorators[1] == resultExt2);

            DomNodeAdapter[] extensions = domNode.AsAll<DomNodeAdapter>().ToArray();
            Assert.IsTrue(
                extensions.Length == 2 &&
                extensions[0] == resultExt1 &&
                extensions[1] == resultExt2);

            // Searching by name is a problem, though. The search is ambiguous.
            // See tracker item for discussion: http://tracker.ship.scea.com/jira/browse/WWSATF-522
            Assert.Throws<InvalidOperationException>(() => domType.GetExtensionInfo("foo"));
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }