//[Variation(Priority = 0, Desc = "Annotation on document - Omit", Params = new object[] { typeof(XDocument), "Simple.xml", SaveOptions.OmitDuplicateNamespaces })] //[Variation(Priority = 1, Desc = "Annotation on document - Omit + Disable", Params = new object[] { typeof(XDocument), "Simple.xml", SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting })] //[Variation(Priority = 0, Desc = "Annotation on element - Omit", Params = new object[] { typeof(XElement), "Simple.xml", SaveOptions.OmitDuplicateNamespaces })] //[Variation(Priority = 1, Desc = "Annotation on element - Omit + Disable", Params = new object[] { typeof(XElement), "Simple.xml", SaveOptions.OmitDuplicateNamespaces | SaveOptions.DisableFormatting })] public void XDocAnnotation() { Type t = CurrentChild.Params[0] as Type; string fileName = Path.Combine(s_MyPath, CurrentChild.Params[1] as string); SaveOptions so = (SaveOptions)CurrentChild.Params[2]; using (MemoryStream ms = new MemoryStream()) { XDocument toClean = XDocument.Load(FilePathUtil.getStream(fileName)); using (XmlWriter w = XmlWriter.Create(ms, new XmlWriterSettings() { OmitXmlDeclaration = true, NamespaceHandling = NamespaceHandling.OmitDuplicates })) { toClean.Save(w); } ms.Position = 0; using (XmlReader r1 = XmlReader.Create(ms, new XmlReaderSettings() { IgnoreWhitespace = true, DtdProcessing = DtdProcessing.Ignore })) { XContainer doc = GetContainer(fileName, t); doc.AddAnnotation(so); using (XmlReader r2 = doc.CreateReader()) { ReaderDiff.Compare(r1, r2); } } } }
//[Variation(Priority = 2, Desc = "Annotation on document without omit - None", Params = new object[] { typeof(XDocument), "Simple.xml", SaveOptions.None })] //[Variation(Priority = 2, Desc = "Annotation on document without omit - DisableFormating", Params = new object[] { typeof(XDocument), "Simple.xml", SaveOptions.DisableFormatting })] //[Variation(Priority = 2, Desc = "Annotation on element without omit - None", Params = new object[] { typeof(XElement), "Simple.xml", SaveOptions.None })] //[Variation(Priority = 2, Desc = "Annotation on element without omit - DisableFormating", Params = new object[] { typeof(XElement), "Simple.xml", SaveOptions.DisableFormatting })] public void AnnotationWithoutTheOmitDuplicates() { Type t = CurrentChild.Params[0] as Type; string fileName = Path.Combine(s_MyPath, CurrentChild.Params[1] as string); SaveOptions so = (SaveOptions)CurrentChild.Params[2]; using (XmlReader r1 = XmlReader.Create(FilePathUtil.getStream(fileName), new XmlReaderSettings() { IgnoreWhitespace = true, DtdProcessing = DtdProcessing.Ignore })) { XContainer doc = GetContainer(fileName, t); doc.AddAnnotation(so); using (XmlReader r2 = doc.CreateReader()) { ReaderDiff.Compare(r1, r2); } } }
//[Variation(Priority = 0, Desc = "Multiple annotations on node - XDocument", Param = typeof(XDocument))] //[Variation(Priority = 0, Desc = "Multiple annotations on node - XElement", Param = typeof(XElement))] public void MultipleAnnotationsOnElement() { Type t = CurrentChild.Param as Type; string xml = @"<A xmlns:p='a1'><B xmlns:q='a2'><C xmlns:p='a1'><D xmlns:q='a2' ><E xmlns:p='a1' /></D></C></B></A>"; XContainer reF = (t == typeof(XElement) ? XElement.Parse(xml) as XContainer : XDocument.Parse(xml) as XContainer); // I want dynamics!!! SaveOptions[] options = new SaveOptions[] { SaveOptions.None, SaveOptions.DisableFormatting, SaveOptions.OmitDuplicateNamespaces, SaveOptions.DisableFormatting | SaveOptions.OmitDuplicateNamespaces }; foreach (SaveOptions[] opts in Tuples2(options)) { XContainer gp = (t == typeof(XElement) ? XElement.Parse(xml) as XContainer : XDocument.Parse(xml) as XContainer); foreach (SaveOptions o in opts) { gp.AddAnnotation(o); } TestLog.Compare(reF.ToString(opts[0]), gp.ToString(), "On root - ToString()"); ReaderDiffNSAware.CompareNamespaceAware(opts[0], reF.CreateReader(), gp.CreateReader()); } }