public void ShouldAddToTheKnownExtensionsForType() { KmlFactory.RegisterExtension <TargetElement, NotRegisteredElement>(); IEnumerable <Type> children = KmlFactory.GetKnownExtensionTypes(typeof(TargetElement)); Assert.That(children, Is.EqualTo(new[] { typeof(NotRegisteredElement) })); }
public void ShouldReturnTrueIfTheExtensionHasBeenRegisteredOnABaseClass() { KmlFactory.RegisterExtension <BaseElement, ManuallyRegisteredElement>(); bool result = KmlFactory.IsKnownExtensionType(typeof(DerivedElement), typeof(ManuallyRegisteredElement)); Assert.That(result, Is.True); }
public void ShouldRegisterExtensionsAsChildren() { KmlFactory.RegisterExtension <NoChildrenElement, NotRegisteredElement>(); IEnumerable <TypeInfo> children = GetChildrenFor <NoChildrenElement>(); Assert.That(children, Is.EqualTo(new[] { typeof(NotRegisteredElement).GetTypeInfo() })); }
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)); }
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); }
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>(); }