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)); }
/// <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); } }
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)); }
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)); }
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)); }
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)); }
public void Dispose_ClosesOutputStreamIfWritingToStream() { MemoryStream stream = new MemoryStream(); var target = new GpxWriter(stream, new GpxWriterSettings()); target.Dispose(); Assert.False(stream.CanRead); }
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)); }
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(); }
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); } }
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)); }
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); } }
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)); }