public void RoundTripTest(string path) { var(metadata, features, extensions) = GpxReader.ReadFeatures(XmlReader.Create(path), null, GeometryFactory.Default); using (var ms = new MemoryStream()) { var writerSettings = new XmlWriterSettings { Encoding = Encoding.UTF8, CloseOutput = false }; using (var wr = XmlWriter.Create(ms, writerSettings)) { GpxWriter.Write(wr, null, metadata, features, extensions); } ms.Position = 0; byte[] expected = File.ReadAllBytes(path); var diff = DiffBuilder.Compare(expected) .NormalizeWhitespace() .WithTest(ms) .IgnoreComments() .CheckForSimilar() .Build(); // note that this is not a guarantee in the general case. the inputs here have all been // slightly tweaked such that it should succeed for our purposes. Assert.False(diff.HasDifferences(), string.Join(Environment.NewLine, diff.Differences)); } }
public void MinimalWhitespaceShouldNotCauseFeaturesToGetSkipped() { using (var xmlReader = XmlReader.Create(Path.Join("RoundTripSafeSamples", "github-issue18-regression.gpx"))) { var(_, features, _) = GpxReader.ReadFeatures(xmlReader, null, GeometryFactory.Default); Assert.Equal(3, features.Length); } }
public void CopyrightYearShouldAllowVariousLegalValues(string gpxFileName, int expectedYear) { using (var reader = XmlReader.Create(Path.Combine("CopyrightYearRegressionSamples", gpxFileName))) { var(metadata, _, _) = GpxReader.ReadFeatures(reader, null, GeometryFactory.Default); Assert.True(metadata.Copyright?.Year.HasValue); int value = metadata.Copyright.Year.GetValueOrDefault(); Assert.Equal(expectedYear, value); } }
public void ReadSmokeTest(string gpxPath) { string gpx = File.ReadAllText(gpxPath); var gpxElement = XDocument.Parse(gpx).Root; using (var stringReader = new StringReader(gpx)) using (var reader = XmlReader.Create(stringReader)) { var(metadata, features, extensions) = GpxReader.ReadFeatures(reader, null, GeometryFactory.Default); Assert.Equal(gpxElement.Attribute("creator").Value, metadata.Creator); } }