예제 #1
0
        public void EqualsShouldReturnFalseIfTheNameDiffersByCase()
        {
            var xml1 = new XmlComponent("pre", "name", "uri");
            var xml2 = new XmlComponent("pre", "Name", "uri");

            Assert.That(xml1.Equals(xml2), Is.False);
        }
예제 #2
0
 /// <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);
     }
 }
예제 #3
0
        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);
        }
예제 #4
0
        public void EqualsShouldReturnFalseIfTheNamespaceIsDifferent()
        {
            var xml1 = new XmlComponent("pre", "name", "uri");
            var xml2 = new XmlComponent("pre", "name", "other");

            Assert.That(xml1.Equals(xml2), Is.False);
        }
예제 #5
0
        public void EqualsShouldReturnTrueIfTheNameAndNamespaceAreEqual()
        {
            var xml1 = new XmlComponent("pre", "name", "uri");
            var xml2 = new XmlComponent(null, "name", "uri");

            Assert.That(xml1.Equals(xml2), Is.True);
        }
예제 #6
0
        /// <summary>
        /// Processes the &lt;gx:angles&gt;, &lt;gx:coord&gt; and &lt;when&gt;
        /// 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);
        }
예제 #7
0
            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.
 }
예제 #9
0
            public void ShouldBeAbleToRegisterTypesInDifferentNamespaces()
            {
                var component = new XmlComponent(null, "test", "another namespace");

                Assert.That(
                    () => KmlFactory.Register <SeparateNamespaceElement>(component),
                    Throws.Nothing);
            }
예제 #10
0
 /// <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.
 }
예제 #11
0
        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));
        }
예제 #12
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>());
            }
예제 #13
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>());
            }
예제 #14
0
        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));
        }
예제 #15
0
        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));
        }
예제 #16
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);
            }
예제 #17
0
 /// <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);
         }
     }
 }
예제 #18
0
        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()));
        }
예제 #19
0
        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()));
        }
예제 #20
0
        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));
        }
예제 #21
0
        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));
        }
예제 #22
0
        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);
        }
예제 #23
0
            public void ShouldFindAutomaticallyRegisteredTypes()
            {
                XmlComponent result = KmlFactory.FindType(typeof(Description));

                Assert.That(result.Name, Is.EqualTo("description"));
            }
예제 #24
0
        /// <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.
        }
예제 #25
0
            public void ShouldFindManuallyRegisteredTypes()
            {
                XmlComponent result = KmlFactory.FindType(typeof(ManuallyRegisteredElement));

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