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>()); }
public void ShouldCreateAnInstanceOfTheSpecifiedType() { Element element = KmlFactory.CreateElement(new XmlComponent(null, "test", "")); Assert.That(element, Is.Not.Null); Assert.That(element, Is.InstanceOf <ManuallyRegisteredElement>()); }
public void ShouldRegisterExtensionsAsChildren() { KmlFactory.RegisterExtension <NoChildrenElement, NotRegisteredElement>(); IEnumerable <TypeInfo> children = GetChildrenFor <NoChildrenElement>(); Assert.That(children, Is.EqualTo(new[] { typeof(NotRegisteredElement).GetTypeInfo() })); }
public void ShouldReturnTrueIfTheExtensionHasBeenRegisteredOnABaseClass() { KmlFactory.RegisterExtension <BaseElement, ManuallyRegisteredElement>(); bool result = KmlFactory.IsKnownExtensionType(typeof(DerivedElement), typeof(ManuallyRegisteredElement)); Assert.That(result, Is.True); }
public void ShouldNotAllowATypeToBeRegisteredTwice() { var component = new XmlComponent(null, "alias", ""); Assert.That( () => KmlFactory.Register <ManuallyRegisteredElement>(component), Throws.TypeOf <ArgumentException>()); }
public void ShouldBeAbleToRegisterTypesInDifferentNamespaces() { var component = new XmlComponent(null, "test", "another namespace"); Assert.That( () => KmlFactory.Register <SeparateNamespaceElement>(component), Throws.Nothing); }
public void ShouldAddToTheKnownExtensionsForType() { KmlFactory.RegisterExtension <TargetElement, NotRegisteredElement>(); IEnumerable <Type> children = KmlFactory.GetKnownExtensionTypes(typeof(TargetElement)); Assert.That(children, Is.EqualTo(new[] { typeof(NotRegisteredElement) })); }
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>()); }
/// <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); }
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>()); }
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); }
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>()); }
static IHtmlContentTest() { KmlFactory.Register <TestClass>(new XmlComponent(null, "file", "http://example.com")); }
static KmlFactoryTest() { // Register our own type only once KmlFactory.Register <ManuallyRegisteredElement>(new XmlComponent(null, "test", "")); }
public void ShouldCheckTheExistingTypeExists() { Assert.That( () => KmlFactory.Replace <NotRegisteredElement, ReplacedElement>(), Throws.TypeOf <ArgumentException>()); }
public void ShouldReturnFalseIfTheExtensionIsNotRegistered() { bool result = KmlFactory.IsKnownExtensionType(typeof(DerivedElement), typeof(NotRegisteredElement)); Assert.That(result, Is.False); }
public void ShouldThrowForNullArguments() { Assert.That( () => KmlFactory.FindType(null), Throws.TypeOf <ArgumentNullException>()); }
public void ShouldFindManuallyRegisteredTypes() { XmlComponent result = KmlFactory.FindType(typeof(ManuallyRegisteredElement)); Assert.That(result.Name, Is.EqualTo("test")); }
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>(); }
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)); }
public void ShouldFindAutomaticallyRegisteredTypes() { XmlComponent result = KmlFactory.FindType(typeof(Description)); Assert.That(result.Name, Is.EqualTo("description")); }
static SerializerTest() { KmlFactory.Register <ChildElement>(new XmlComponent(null, "ChildElementS", string.Empty)); KmlFactory.Register <TestElement>(new XmlComponent(null, "TestElementS", string.Empty)); }
static KmlFactoryTest() { // Register our own type only once KmlFactory.Register <TestElementClass1>(new XmlComponent(null, "test", string.Empty)); }