Exemplo n.º 1
0
        public void Constructor_PathSettings_CreatesGpxFileWithRootElement()
        {
            string path = "TestFiles\\gpx-writer-constructor-test.gpx";
            File.Delete(path);
            string generatorName = "SpatialLite";

            using (GpxWriter target = new GpxWriter(path, new GpxWriterSettings() { WriteMetadata = false, GeneratorName = generatorName })) {
            }

            XDocument written = XDocument.Load(path);
            XDocument expected = XDocument.Load(new MemoryStream(GpxTestData.gpx_empty_file));

            Assert.True(XDocumentExtensions.DeepEqualsWithNormalization(written, expected, null));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Saves content of the GpxDocument to file.
 /// </summary>
 /// <param name="path">Path to the file.</param>
 public void Save(string path)
 {
     using (GpxWriter writer = new GpxWriter(path, new GpxWriterSettings() {WriteMetadata = true})) {
         this.Save(writer);
     }
 }
Exemplo n.º 3
0
        public void Write_WritesWaypointWithoutMetadataIfWriteMetadataIsFalse()
        {
            MemoryStream stream = new MemoryStream();

            using (GpxWriter target = new GpxWriter(stream, new GpxWriterSettings() { WriteMetadata = false })) {
                target.Write(_waypointWithMetadata);
            }

            XDocument written = XDocument.Load(new MemoryStream(stream.ToArray()));
            XDocument expected = XDocument.Load(new MemoryStream(GpxTestData.gpx_waypoint_simple));

            Assert.True(XDocumentExtensions.DeepEqualsWithNormalization(written, expected, null));
        }
Exemplo n.º 4
0
        public void Write_WritesWaypointWithoutUnnecessaryElements()
        {
            _waypointWithMetadata.Metadata.SatellitesCount = null;
            _waypointWithMetadata.Metadata.Name = null;
            MemoryStream stream = new MemoryStream();

            using (GpxWriter target = new GpxWriter(stream, new GpxWriterSettings() { WriteMetadata = true })) {
                target.Write(_waypointWithMetadata);
            }

            XDocument written = XDocument.Load(new MemoryStream(stream.ToArray()));
            XDocument expected = XDocument.Load(new MemoryStream(GpxTestData.gpx_waypoint_with_metadata_selection));

            Assert.True(XDocumentExtensions.DeepEqualsWithNormalization(written, expected, null));
        }
Exemplo n.º 5
0
        public void Write_WritesRouteWith3Points()
        {
            MemoryStream stream = new MemoryStream();

            using (GpxWriter target = new GpxWriter(stream, new GpxWriterSettings() { WriteMetadata = false })) {
                target.Write(_route);
            }

            XDocument written = XDocument.Load(new MemoryStream(stream.ToArray()));
            XDocument expected = XDocument.Load(new MemoryStream(GpxTestData.gpx_route_single_route));

            Assert.True(XDocumentExtensions.DeepEqualsWithNormalization(written, expected, null));
        }
Exemplo n.º 6
0
        public void Write_WritesTrackWithMetadata()
        {
            MemoryStream stream = new MemoryStream();

            using (GpxWriter target = new GpxWriter(stream, new GpxWriterSettings() { WriteMetadata = true })) {
                target.Write(_trackWithMetadata);
            }

            XDocument written = XDocument.Load(new MemoryStream(stream.ToArray()));
            XDocument expected = XDocument.Load(new MemoryStream(GpxTestData.gpx_track_with_metadata));

            Assert.True(XDocumentExtensions.DeepEqualsWithNormalization(written, expected, null));
        }
Exemplo n.º 7
0
        public void Dispose_ClosesOutputStreamIfWritingToStream()
        {
            MemoryStream stream = new MemoryStream();

            var target = new GpxWriter(stream, new GpxWriterSettings());
            target.Dispose();

            Assert.False(stream.CanRead);
        }
Exemplo n.º 8
0
        public void Write_TrackWithEntityDetailsButNullValues_WritesTrackWithoutUnnecessaryElements()
        {
            MemoryStream stream = new MemoryStream();
            _trackWithMetadata.Metadata.Source = null;

            using (GpxWriter target = new GpxWriter(stream, new GpxWriterSettings() { WriteMetadata = true })) {
                target.Write(_trackWithMetadata);
            }

            XDocument written = XDocument.Load(new MemoryStream(stream.ToArray()));
            XDocument expected = XDocument.Load(new MemoryStream(GpxTestData.gpx_track_with_metadata_selection));

            Assert.True(XDocumentExtensions.DeepEqualsWithNormalization(written, expected, null));
        }
Exemplo n.º 9
0
        public void Dispose_ClosesOutputStreamIfWritingToFiles()
        {
            string path = "TestFiles\\gpxwriter-closes-output-filestream-test.osm";
            File.Delete(path);

            var target = new GpxWriter(path, new GpxWriterSettings());
            target.Dispose();

            FileStream testStream = null;
            Assert.DoesNotThrow(() => testStream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite));
            testStream.Dispose();
        }
Exemplo n.º 10
0
 public void Constructor_StreamSettings_SetsSettingsAndMarkSettingsAsReadOnly()
 {
     var stream = new MemoryStream();
     var settings = new GpxWriterSettings();
     using (var target = new GpxWriter(stream, settings)) {
         Assert.Same(settings, target.Settings);
         Assert.True(target.Settings.IsReadOnly);
     }
 }
Exemplo n.º 11
0
        public void Constructor_StreamSettings_CreatesGpxFileWithRootElement()
        {
            string generatorName = "SpatialLite";
            var stream = new MemoryStream();

            using (GpxWriter target = new GpxWriter(stream, new GpxWriterSettings() { WriteMetadata = false, GeneratorName = generatorName })) {
            }

            XDocument written = XDocument.Load(new MemoryStream(stream.ToArray()));
            XDocument expected = XDocument.Load(new MemoryStream(GpxTestData.gpx_empty_file));

            Assert.True(XDocumentExtensions.DeepEqualsWithNormalization(written, expected, null));
        }
Exemplo n.º 12
0
 public void Constructor_PathSettings_SetsSettingsAndMakesThemReadOnly()
 {
     string path = "TestFiles\\gpxwriter-constructor-test.gpx";
     var settings = new GpxWriterSettings();
     using (var target = new GpxWriter(path, settings)) {
         Assert.Same(settings, target.Settings);
         Assert.True(target.Settings.IsReadOnly);
     }
 }
Exemplo n.º 13
0
        public void Constructor_PathSettings_CreatesOutputFile()
        {
            string filename = "TestFiles\\gpxwriter-constructor-creates-output-test.gpx";
            File.Delete(filename);

            var settings = new GpxWriterSettings();
            using (var target = new GpxWriter(filename, settings)) {
                ;
            }

            Assert.True(File.Exists(filename));
        }