Пример #1
0
            public void ShouldAddToTheKnownExtensionsForType()
            {
                KmlFactory.RegisterExtension <TargetElement, NotRegisteredElement>();

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

                Assert.That(children, Is.EqualTo(new[] { typeof(NotRegisteredElement) }));
            }
Пример #2
0
            public void ShouldReturnTrueIfTheExtensionHasBeenRegisteredOnABaseClass()
            {
                KmlFactory.RegisterExtension <BaseElement, ManuallyRegisteredElement>();

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

                Assert.That(result, Is.True);
            }
Пример #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 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));
            }
Пример #5
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);
            }
Пример #6
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>();
 }