Пример #1
0
                //[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());
                    }
                }
Пример #2
0
                //[Variation(Priority = 0, Desc = "Annotation on the parent nodes, XElement", Params = new object[] { typeof(XElement), "simple.xml" })]
                //[Variation(Priority = 0, Desc = "Annotation on the parent nodes, XDocument", Params = new object[] { typeof(XDocument), "simple.xml" })]
                public void AnnotationOnParent1()
                {
                    Type   t        = CurrentChild.Params[0] as Type;
                    string fileName = Path.Combine(s_MyPath, CurrentChild.Params[1] as string);

                    var orig = GetContainer(fileName, t).DescendantNodes().ToArray();
                    var test = GetContainer(fileName, t).DescendantNodes().ToArray();

                    for (int i = 0; i < test.Count(); i++)
                    {
                        XNode n      = test[i];
                        XNode parent = n; // verify parent and self
                        while (parent != null)
                        {                 // for all parents
                            // verify original version
                            TestLog.Compare(n.ToString(), n.ToString(SaveOptions.None), "Initial value");
                            TestLog.Compare(n.ToString(), orig[i].ToString(), "Initial value, via orig");
                            ReaderDiff.Compare(orig[i].CreateReader(), n.CreateReader());
                            // add annotation on parent
                            parent.AddAnnotation(SaveOptions.OmitDuplicateNamespaces);
                            // verify with annotation
                            TestLog.Compare(n.ToString(), n.ToString(SaveOptions.OmitDuplicateNamespaces), "with the annotation, normal");
                            ReaderDiffNSAware.CompareNamespaceAware(orig[i].CreateReader(), n.CreateReader());
                            // removeannotation
                            parent.RemoveAnnotations(typeof(SaveOptions));
                            // verify after removal
                            TestLog.Compare(n.ToString(), n.ToString(SaveOptions.None), "after removed annotation value");
                            TestLog.Compare(n.ToString(), orig[i].ToString(), "after removed annotation, via orig");
                            ReaderDiff.Compare(orig[i].CreateReader(), n.CreateReader());
                            // move parent
                            if (parent is XDocument)
                            {
                                break;
                            }
                            parent = parent.Parent ?? parent.Document as XNode;
                        }
                    }
                }