Example #1
0
        public void Constructor_IEnumerablePoints_CreatesRouteWithPoints()
        {
            List<GpxPoint> points = new List<GpxPoint> {
            new GpxPoint(16.5, 45.9, 100, new DateTime(2011, 2, 24, 20, 00, 00)),
            new GpxPoint(16.6, 46.0, 110, new DateTime(2011, 2, 24, 20, 00, 10)),
            new GpxPoint(16.5, 46.1, 200, new DateTime(2011, 2, 24, 20, 00, 20))};

            GpxRoute target = new GpxRoute(points);

            Assert.Equal(points.Count, target.Points.Count);
            for (int i = 0; i < target.Points.Count; i++) {
                Assert.Same(points[i], target.Points[i]);
            }
        }
Example #2
0
        public void GeometryType_ReturnsRoute()
        {
            GpxRoute target = new GpxRoute();

            Assert.Equal(GpxGeometryType.Route, target.GeometryType);
        }
Example #3
0
        public void Constructor_Parameterless_CreatesEmptyRoute()
        {
            GpxRoute target = new GpxRoute();

            Assert.Empty(target.Points);
        }
        public void Save_IGpxWriter_WritesDataToWriter()
        {
            var waypoint = new GpxPoint();
            var route = new GpxRoute();
            var track = new GpxTrack();

            Mock<IGpxWriter> writerM = new Mock<IGpxWriter>();
            writerM.Setup(w => w.Write(waypoint)).Verifiable();
            writerM.Setup(w => w.Write(route)).Verifiable();
            writerM.Setup(w => w.Write(track)).Verifiable();

            var target = new GpxDocument(new[] { waypoint }, new[] { route }, new[] { track });
            target.Save(writerM.Object);

            writerM.Verify(w => w.Write(waypoint), Times.Once());
            writerM.Verify(w => w.Write(route), Times.Once());
            writerM.Verify(w => w.Write(track), Times.Once());
        }
Example #5
0
        /// <summary>
        /// Writes the given route to the output stream
        /// </summary>
        /// <param name="route">The route to write</param>
        public void Write(GpxRoute route)
        {
            _xmlWriter.WriteStartElement("rte");

            for (int i = 0; i < route.Points.Count; i++) {
                WritePoint(route.Points[i], "rtept");
            }
            if (this.Settings.WriteMetadata) {
                this.WriteTrackMetadata(route.Metadata);
            }

            _xmlWriter.WriteEndElement();
        }
Example #6
0
        /// <summary>
        /// Reads a GPX route from the internal XmlReader
        /// </summary>
        /// <returns>the route parsed from the XmlReader</returns>
        private GpxRoute ReadRoute()
        {
            GpxRoute result = new GpxRoute();

            if (_xmlReader.IsEmptyElement == false) {
                _xmlReader.Read();

                GpxTrackMetadata metadata = null;
                if (this.Settings.ReadMetadata) {
                    metadata = new GpxTrackMetadata();
                }

                while ((_xmlReader.NodeType == XmlNodeType.EndElement && _xmlReader.Name == "rte") == false) {
                    bool elementParsed = false;

                    if (_xmlReader.Name == "rtept") {
                        result.Points.Add(ReadPoint("rtept"));
                        elementParsed = true;
                    }

                    if (this.Settings.ReadMetadata) {
                        elementParsed = elementParsed || this.TryReadTrackMetadata(metadata);
                    }

                    if (!elementParsed) {
                        _xmlReader.Skip();
                    }
                }

                result.Metadata = metadata;
            }
            _xmlReader.Skip();

            return result;
        }