Esempio n. 1
0
        public void TestSerialize()
        {
            ItemIcon item = new ItemIcon();
            Serializer serializer = new Serializer();

            // This shouldn't not produce a "state" element
            item.State = ItemIconStates.None;
            serializer.SerializeRaw(item);

            string xml = @"<ItemIcon xmlns=""http://www.opengis.net/kml/2.2"" />";
            Assert.That(serializer.Xml, Is.EqualTo(xml));

            // Try with more than one value
            item.State = ItemIconStates.Open | ItemIconStates.Error;
            serializer.SerializeRaw(item);

            xml = @"<ItemIcon xmlns=""http://www.opengis.net/kml/2.2""><state>open error</state></ItemIcon>";
            Assert.That(serializer.Xml, Is.EqualTo(xml));

            // Try with an invalid value
            item.State = (ItemIconStates)0x80;
            serializer.SerializeRaw(item);

            xml = @"<ItemIcon xmlns=""http://www.opengis.net/kml/2.2""><state /></ItemIcon>";
            Assert.That(serializer.Xml, Is.EqualTo(xml));
        }
        public void SerializeShouldNotOutputAltitudeIfItIsNotSpecified()
        {
            var coords = new CoordinateCollection(new[] { new Vector(1, 2) });

            var serializer = new Serializer();
            serializer.SerializeRaw(coords);

            var expected = string.Format(CultureInfo.InvariantCulture, XmlFormat, "2,1");
            Assert.That(serializer.Xml, Is.EqualTo(expected));
        }
Esempio n. 3
0
        public void TestSerialize()
        {
            TestClass element = new TestClass();
            element.Att = "value";
            element.Text = "<root><><x:child /></root>";

            Serializer serializer = new Serializer();
            serializer.SerializeRaw(element);

            const string xml = "<file att=\"value\" xmlns=\"http://example.com\"><![CDATA[<root><><x:child /></root>]]></file>";
            Assert.That(serializer.Xml, Is.EqualTo(xml));
        }
Esempio n. 4
0
        public void TestCData()
        {
            var balloon = new BalloonStyle();
            balloon.Text = "<![CDATA[$[description]]]>";

            var serializer = new Serializer();
            serializer.SerializeRaw(balloon);

            string expected =
                "<BalloonStyle xmlns=\"http://www.opengis.net/kml/2.2\">" +
                "<text>" + balloon.Text + "</text>" +
                "</BalloonStyle>";

            Assert.That(serializer.Xml, Is.EqualTo(expected));
        }
        public void SerializeShouldUseTheDelimiterToSeparatePoints()
        {
            var coords = new CoordinateCollection(new []
                {
                    new Vector(1, 2, 3),
                    new Vector(2, 1, 3)
                });

            var serializer = new Serializer();

            CoordinateCollection.Delimiter = " ";
            serializer.SerializeRaw(coords);
            CoordinateCollection.Delimiter = "\n"; // Reset to prove it worked during the call to serialize

            var expected = string.Format(CultureInfo.InvariantCulture, XmlFormat, "2,1,3 1,2,3");
            Assert.That(serializer.Xml, Is.EqualTo(expected));
        }
Esempio n. 6
0
        public void TestSerialize()
        {
            const string Expected =
                "<kml xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns=\"http://www.opengis.net/kml/2.2\">" +
                "<Document>" +
                "<atom:author>" +
                "<atom:name>Name</atom:name>" +
                "</atom:author>" +
                "<atom:link href=\"http://www.example.com/\" />" +
                "</Document>" +
                "</kml>";

            Document document = new Document();
            document.AtomAuthor = new Author { Name = "Name" };
            document.AtomLink = new SharpKml.Dom.Atom.Link { Href = new Uri("http://www.example.com") };

            Kml root = new Kml();
            root.AddNamespacePrefix(KmlNamespaces.AtomPrefix, KmlNamespaces.AtomNamespace);
            root.Feature = document;

            Serializer serializer = new Serializer();
            serializer.SerializeRaw(root);

            Assert.That(serializer.Xml, Is.EqualTo(Expected));
        }
        public void TestSerialize()
        {
            var serializer = new Serializer();
            var coords = new CoordinateCollection();

            // First test empty.
            serializer.SerializeRaw(coords);
            Assert.That(serializer.Xml, Is.EqualTo("<coordinates xmlns=\"http://www.opengis.net/kml/2.2\" />"));

            // Now with a value.
            coords.Add(new Vector(1, 2, 3));
            serializer.SerializeRaw(coords);

            string expected = string.Format(CultureInfo.InvariantCulture, XmlFormat, "2,1,3");
            Assert.That(serializer.Xml, Is.EqualTo(expected));
        }
Esempio n. 8
0
        public void TestSerialize()
        {
            // This needs to be in this order
            const string TestKml =
                "<LatLonAltBox xmlns=\"http://www.opengis.net/kml/2.2\">" +
                "<north>2.5</north>" +
                "<west>0</west>" +
                "<minAltitude>101.101</minAltitude>" +
                "<altitudeMode>absolute</altitudeMode>" +
                "</LatLonAltBox>";

            Parser parser = new Parser();
            parser.ParseString(TestKml, true);
            Assert.That(parser.Root, Is.Not.Null);

            LatLonAltBox box = parser.Root as LatLonAltBox;
            Assert.That(box, Is.Not.Null);

            // Check it was parsed ok
            Assert.That(box.North, Is.EqualTo(2.5));
            Assert.That(box.South, Is.Null);
            Assert.That(box.East, Is.Null);
            Assert.That(box.West, Is.EqualTo(0));
            Assert.That(box.MinimumAltitude, Is.EqualTo(101.101));
            Assert.That(box.MaximumAltitude, Is.Null);
            Assert.That(box.GXAltitudeMode, Is.Null);
            Assert.That(box.AltitudeMode, Is.EqualTo(AltitudeMode.Absolute));

            Serializer serializer = new Serializer();
            serializer.SerializeRaw(box);
            Assert.That(serializer.Xml, Is.EqualTo(TestKml));
        }