public void EqualsShouldReturnFalseIfTheNameDiffersByCase() { var xml1 = new XmlComponent("pre", "name", "uri"); var xml2 = new XmlComponent("pre", "Name", "uri"); Assert.That(xml1.Equals(xml2), Is.False); }
/// <summary> /// Stores unknown attributes found during parsing for later serialization. /// </summary> /// <param name="attribute">Contains serialization information.</param> protected internal virtual void AddAttribute(XmlComponent attribute) { if (attribute != null) { _attributes.Add(attribute); } }
public void EqualsShouldReturnTrueIfTheNamespaceIsTheIgnoreNamespace() { var xml1 = new XmlComponent("x", "name", "uri"); var xml2 = new XmlComponent("y", "name", Parser.IgnoreNamespace); Assert.That(xml1.Equals(xml2), Is.True); }
public void EqualsShouldReturnFalseIfTheNamespaceIsDifferent() { var xml1 = new XmlComponent("pre", "name", "uri"); var xml2 = new XmlComponent("pre", "name", "other"); Assert.That(xml1.Equals(xml2), Is.False); }
public void EqualsShouldReturnTrueIfTheNameAndNamespaceAreEqual() { var xml1 = new XmlComponent("pre", "name", "uri"); var xml2 = new XmlComponent(null, "name", "uri"); Assert.That(xml1.Equals(xml2), Is.True); }
/// <summary> /// Processes the <gx:angles>, <gx:coord> and <when> /// elements. /// </summary> /// <param name="orphan">The <see cref="Element"/> to add.</param> protected internal override void AddOrphan(Element orphan) { UnknownElement unknown = orphan as UnknownElement; if (unknown != null) { XmlComponent data = unknown.UnknownData; if (AnglesComponent.Equals(data)) { this.AddChild(new AnglesElement(unknown.InnerText)); return; } if (CoordComponent.Equals(data)) { this.AddChild(new CoordElement(unknown.InnerText)); return; } if (WhenComponent.Equals(data)) { this.AddChild(new WhenElement(unknown.InnerText)); return; } } base.AddOrphan(orphan); }
public void ShouldNotAllowATypeToBeRegisteredTwice() { var component = new XmlComponent(null, "alias", ""); Assert.That( () => KmlFactory.Register <ManuallyRegisteredElement>(component), Throws.TypeOf <ArgumentException>()); }
/// <summary> /// Initializes a new instance of the UnknownElement class. /// </summary> /// <param name="data">The unrecognized XML data to store.</param> /// <exception cref="ArgumentNullException">data is null.</exception> public UnknownElement(XmlComponent data) { if (data == null) { throw new ArgumentNullException("data"); } _data = data.Clone(); // Don't store the data from the user but store a copy instead. }
public void ShouldBeAbleToRegisterTypesInDifferentNamespaces() { var component = new XmlComponent(null, "test", "another namespace"); Assert.That( () => KmlFactory.Register <SeparateNamespaceElement>(component), Throws.Nothing); }
public void CloneShouldReturnANewInstance() { var original = new XmlComponent("pre", "local", "uri"); XmlComponent clone = original.Clone(); Assert.That(clone, Is.Not.SameAs(original)); Assert.That(clone, Is.EqualTo(original)); }
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>()); }
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 TestClone() { XmlComponent original = new XmlComponent("pre", "local", "uri"); XmlComponent clone = original.Clone(); Assert.That(clone, Is.EqualTo(original)); // Make sure changing a property on the clone does not change the original original.Value = "Hello"; clone.Value = "World"; Assert.That(clone.Value, Is.Not.EqualTo(original.Value)); }
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); }
/// <summary> /// Stores unknown attributes found during parsing for later serialization. /// </summary> /// <param name="attribute">Contains serialization information.</param> protected internal virtual void AddAttribute(XmlComponent attribute) { if (attribute != null) { if (attribute.Prefix == "xmlns") { this.namespaces[attribute.Name] = attribute.Value; } else { this.attributes.Add(attribute); } } }
public void TestEquals() { XmlComponent xml1 = new XmlComponent("pre", "local", "uri"); XmlComponent xml2 = new XmlComponent(null, "local", "uri"); XmlComponent xml3 = new XmlComponent("pre", "local", null); object boxed = xml2; Assert.That(xml1, Is.EqualTo(xml2)); Assert.That(xml1, Is.EqualTo(boxed)); Assert.That(xml1, Is.Not.EqualTo(xml3)); Assert.That(xml2, Is.Not.EqualTo(xml3)); Assert.That(xml2, Is.Not.EqualTo(new XmlComponent(null, "Local", "uri"))); // Check case sensitivity Assert.That(xml1.GetHashCode(), Is.EqualTo(xml2.GetHashCode())); }
public void TestNamespaces() { XmlComponent xml = new XmlComponent("random", "pre:local", "uri"); Assert.That(xml.Name, Is.EqualTo("local")); Assert.That(xml.NamespaceUri, Is.EqualTo("uri")); Assert.That(xml.Prefix, Is.EqualTo("pre")); // Make sure prefix was overloaded // Should ignore anything after the second colon xml = new XmlComponent(null, "too:many:colons", null); Assert.That(xml.Name, Is.EqualTo("many")); Assert.That(xml.Prefix, Is.EqualTo("too")); // Test a known namespace xml = new XmlComponent(null, "gx:known", "ignore me"); Assert.That(xml.Name, Is.EqualTo("known")); Assert.That(xml.NamespaceUri, Is.EqualTo(KmlNamespaces.GX22Namespace)); Assert.That(xml.Prefix, Is.EqualTo(KmlNamespaces.GX22Prefix)); }
public void TestNamespaces() { XmlComponent xml = new XmlComponent("random", "pre:local", "uri"); Assert.That(xml.Name, Is.EqualTo("local")); Assert.That(xml.NamespaceUri, Is.EqualTo("uri")); Assert.That(xml.Prefix, Is.EqualTo("pre")); // Make sure prefix was overloaded // Should ignore anything after the second colon xml = new XmlComponent(null, "too:many:colons", null); Assert.That(xml.Name, Is.EqualTo("many:colons")); Assert.That(xml.Prefix, Is.EqualTo("too")); // Test a known namespace xml = new XmlComponent(null, "gx:known", "ignore me"); Assert.That(xml.Name, Is.EqualTo("known")); Assert.That(xml.NamespaceUri, Is.EqualTo(KmlNamespaces.GX22Namespace)); Assert.That(xml.Prefix, Is.EqualTo(KmlNamespaces.GX22Prefix)); }
private static Element ConvertUnknown(UnknownElement unknown) { XmlComponent data = unknown.UnknownData; if (AnglesComponent.Equals(data)) { return(new AnglesElement(unknown.InnerText)); } else if (CoordComponent.Equals(data)) { return(new CoordElement(unknown.InnerText)); } else if (WhenComponent.Equals(data)) { DateTime value; if (DateTime.TryParse(unknown.InnerText, CultureInfo.InvariantCulture, DateTimeStyles.None, out value)) { return(new WhenElement(value)); } } return(null); }
public void ShouldFindAutomaticallyRegisteredTypes() { XmlComponent result = KmlFactory.FindType(typeof(Description)); Assert.That(result.Name, Is.EqualTo("description")); }
/// <summary> /// Initializes a new instance of the <see cref="UnknownElement"/> class. /// </summary> /// <param name="data">The unrecognized XML data to store.</param> /// <exception cref="ArgumentNullException">data is null.</exception> public UnknownElement(XmlComponent data) { Check.IsNotNull(data, nameof(data)); this.UnknownData = data.Clone(); // Don't store the data from the user but store a copy instead. }
public void ShouldFindManuallyRegisteredTypes() { XmlComponent result = KmlFactory.FindType(typeof(ManuallyRegisteredElement)); Assert.That(result.Name, Is.EqualTo("test")); }