示例#1
0
        public void TestCreation()
        {
            Element element = KmlFactory.CreateElement(new XmlComponent(null, "test", string.Empty));

            Assert.That(element, Is.Not.Null);
            Assert.That(element, Is.InstanceOf <TestElementClass1>());
        }
示例#2
0
            public void ShouldCreateAnInstanceOfTheSpecifiedType()
            {
                Element element = KmlFactory.CreateElement(new XmlComponent(null, "test", ""));

                Assert.That(element, Is.Not.Null);
                Assert.That(element, Is.InstanceOf <ManuallyRegisteredElement>());
            }
示例#3
0
            public void ShouldRegisterExtensionsAsChildren()
            {
                KmlFactory.RegisterExtension <NoChildrenElement, NotRegisteredElement>();

                IEnumerable <TypeInfo> children = GetChildrenFor <NoChildrenElement>();

                Assert.That(children, Is.EqualTo(new[] { typeof(NotRegisteredElement).GetTypeInfo() }));
            }
示例#4
0
            public void ShouldReturnTrueIfTheExtensionHasBeenRegisteredOnABaseClass()
            {
                KmlFactory.RegisterExtension <BaseElement, ManuallyRegisteredElement>();

                bool result = KmlFactory.IsKnownExtensionType(typeof(DerivedElement), typeof(ManuallyRegisteredElement));

                Assert.That(result, Is.True);
            }
示例#5
0
            public void ShouldNotAllowATypeToBeRegisteredTwice()
            {
                var component = new XmlComponent(null, "alias", "");

                Assert.That(
                    () => KmlFactory.Register <ManuallyRegisteredElement>(component),
                    Throws.TypeOf <ArgumentException>());
            }
示例#6
0
            public void ShouldBeAbleToRegisterTypesInDifferentNamespaces()
            {
                var component = new XmlComponent(null, "test", "another namespace");

                Assert.That(
                    () => KmlFactory.Register <SeparateNamespaceElement>(component),
                    Throws.Nothing);
            }
示例#7
0
            public void ShouldAddToTheKnownExtensionsForType()
            {
                KmlFactory.RegisterExtension <TargetElement, NotRegisteredElement>();

                IEnumerable <Type> children = KmlFactory.GetKnownExtensionTypes(typeof(TargetElement));

                Assert.That(children, Is.EqualTo(new[] { typeof(NotRegisteredElement) }));
            }
示例#8
0
            public void ShouldNotAllowDuplicateElementNames()
            {
                // This was registered to TestElementClass1 in the static
                // constructor
                var component = new XmlComponent(null, "test", "");

                Assert.That(
                    () => KmlFactory.Register <NotRegisteredElement>(component),
                    Throws.TypeOf <ArgumentException>());
            }
示例#9
0
        /// <summary>
        /// Adds the specified element to this instance.
        /// </summary>
        /// <param name="child">The child to add.</param>
        /// <exception cref="ArgumentNullException">child is null.</exception>
        public void AddChild(Element child)
        {
            Check.IsNotNull(child, nameof(child));

            if (!KmlFactory.IsKnownExtensionType(this.GetType(), child.GetType()))
            {
                throw new ArgumentException("Element has not been registered as a valid child type.");
            }

            this.AddAsChild(this.orphans, child);
        }
示例#10
0
            public void ShouldReplaceTheSpecifiedType()
            {
                var component = new XmlComponent(null, "existing", "");

                KmlFactory.Register <ExistingElement>(component);

                KmlFactory.Replace <ExistingElement, ReplacedElement>();
                Element result = KmlFactory.CreateElement(component);

                Assert.That(result, Is.InstanceOf <ReplacedElement>());
            }
示例#11
0
            public void ShouldBeAbleToAddAnExtensionToADerivedClass()
            {
                KmlFactory.Register <BaseElement>(new XmlComponent(null, nameof(BaseElement), nameof(ElementTest)));
                KmlFactory.Register <DerivedElement>(new XmlComponent(null, nameof(DerivedElement), nameof(ElementTest)));
                KmlFactory.RegisterExtension <BaseElement, ExtensionElement>();

                var parent = new DerivedElement();
                var child  = new ExtensionElement();

                parent.AddChild(child);

                Assert.That(parent.Children, Has.Member(child));
            }
示例#12
0
            public void ShouldRegisterTheExtensionType()
            {
                Assert.That(KmlFactory.FindType(typeof(ExtensionElement)), Is.Null);

                KmlFactory.RegisterExtension <NotRegisteredElement, ExtensionElement>();
                XmlComponent result = KmlFactory.FindType(typeof(ExtensionElement));

                Assert.That(result.Name, Is.EqualTo("extension_name"));

                // We should be able to register the extension on other types
                Assert.That(
                    () => KmlFactory.RegisterExtension <ManuallyRegisteredElement, ExtensionElement>(),
                    Throws.Nothing);
            }
示例#13
0
        public void TestRegistration()
        {
            // Test that types in the KmlDom namespace are automatically registered.
            Assert.That(KmlFactory.FindType(typeof(Description)).Name, Is.EqualTo("description"));

            // Make sure it knows about our type registered in the static constructor
            Assert.That(KmlFactory.FindType(typeof(TestElementClass1)).Name, Is.EqualTo("test"));

            // This should be ok as the namespace is different
            KmlFactory.Register <TestElementClass2>(new XmlComponent(null, "test", "another namespace"));

            // But this should throw an exception
            Assert.That(
                () => KmlFactory.Register <TestElementClass3>(new XmlComponent(null, "test", string.Empty)),
                Throws.TypeOf <ArgumentException>());
        }
示例#14
0
 static IHtmlContentTest()
 {
     KmlFactory.Register <TestClass>(new XmlComponent(null, "file", "http://example.com"));
 }
示例#15
0
 static KmlFactoryTest()
 {
     // Register our own type only once
     KmlFactory.Register <ManuallyRegisteredElement>(new XmlComponent(null, "test", ""));
 }
示例#16
0
 public void ShouldCheckTheExistingTypeExists()
 {
     Assert.That(
         () => KmlFactory.Replace <NotRegisteredElement, ReplacedElement>(),
         Throws.TypeOf <ArgumentException>());
 }
示例#17
0
            public void ShouldReturnFalseIfTheExtensionIsNotRegistered()
            {
                bool result = KmlFactory.IsKnownExtensionType(typeof(DerivedElement), typeof(NotRegisteredElement));

                Assert.That(result, Is.False);
            }
示例#18
0
 public void ShouldThrowForNullArguments()
 {
     Assert.That(
         () => KmlFactory.FindType(null),
         Throws.TypeOf <ArgumentNullException>());
 }
示例#19
0
            public void ShouldFindManuallyRegisteredTypes()
            {
                XmlComponent result = KmlFactory.FindType(typeof(ManuallyRegisteredElement));

                Assert.That(result.Name, Is.EqualTo("test"));
            }
示例#20
0
 static ElementTest()
 {
     KmlFactory.Register <BaseElement>(new XmlComponent(null, nameof(BaseElement), nameof(ElementTest)));
     KmlFactory.Register <DerivedElement>(new XmlComponent(null, nameof(DerivedElement), nameof(ElementTest)));
     KmlFactory.RegisterExtension <BaseElement, BaseElementExtension>();
 }
示例#21
0
 static ParserTest()
 {
     KmlFactory.Register <ChildElement>(new XmlComponent(null, "ChildElement", string.Empty));
     KmlFactory.Register <TestElement>(new XmlComponent(null, "TestElement", string.Empty));
     KmlFactory.Register <DoubleElement>(new XmlComponent(null, "DoubleElement", string.Empty));
 }
示例#22
0
            public void ShouldFindAutomaticallyRegisteredTypes()
            {
                XmlComponent result = KmlFactory.FindType(typeof(Description));

                Assert.That(result.Name, Is.EqualTo("description"));
            }
示例#23
0
 static SerializerTest()
 {
     KmlFactory.Register <ChildElement>(new XmlComponent(null, "ChildElementS", string.Empty));
     KmlFactory.Register <TestElement>(new XmlComponent(null, "TestElementS", string.Empty));
 }
示例#24
0
 static KmlFactoryTest()
 {
     // Register our own type only once
     KmlFactory.Register <TestElementClass1>(new XmlComponent(null, "test", string.Empty));
 }