public void AssertSanitize() { const string namespacePrefix = "{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2}"; const int expectedTrackpointCount = 168; const int failedTrackpointCount = 0; const string trackpoint = "Trackpoint"; var doc = XDocument.Parse(GarminXml, LoadOptions.None); Assert.IsNotNull(doc.Descendants()); var trackPoints = doc.Descendants(trackpoint); Assert.AreEqual(failedTrackpointCount, trackPoints.Count()); trackPoints = doc.Descendants(namespacePrefix + trackpoint); Assert.AreEqual(expectedTrackpointCount, trackPoints.Count()); trackPoints = doc.Descendants().Where(x => x.Name.LocalName == trackpoint); Assert.AreEqual(expectedTrackpointCount, trackPoints.Count()); var sanitizer = new XmlSanitizer(); var saneXml = sanitizer.Sanitize(GarminXml); doc = XDocument.Parse(saneXml); trackPoints = doc.Descendants(trackpoint); Assert.AreEqual(expectedTrackpointCount, trackPoints.Count()); }
private static XDocument BuildXDocument(string xml) { var sanitizer = new XmlSanitizer(); var saneXml = sanitizer.Sanitize(xml); return XDocument.Parse(saneXml); }