Ejemplo n.º 1
0
        public void CreatingXElementsFromNewDev10Types(object t, Type type)
        {
            XElement e = new XElement("e1", new XElement("e2"), "text1", new XElement("e3"), t);

            e.Add(t);
            e.FirstNode.ReplaceWith(t);

            XNode n = e.FirstNode.NextNode;

            n.AddBeforeSelf(t);
            n.AddAnnotation(t);
            n.ReplaceWith(t);

            e.FirstNode.AddAfterSelf(t);
            e.AddFirst(t);
            e.Annotation(type);
            e.Annotations(type);
            e.RemoveAnnotations(type);
            e.ReplaceAll(t);
            e.ReplaceAttributes(t);
            e.ReplaceNodes(t);
            e.SetAttributeValue("a", t);
            e.SetElementValue("e2", t);
            e.SetValue(t);

            XAttribute        a  = new XAttribute("a", t);
            XStreamingElement se = new XStreamingElement("se", t);

            se.Add(t);

            AssertExtensions.Throws <ArgumentException>(null, () => new XDocument(t));
            AssertExtensions.Throws <ArgumentException>(null, () => new XDocument(t));
        }
Ejemplo n.º 2
0
        }         // proc XCopyAnnotations

        private static void XCopyAnnonation(XElement xSource, XNode xDestination, Type typeAnnotation, bool recursive)
        {
            object baseUri = recursive ? xSource.FindAnnotation(typeAnnotation) : xSource.Annotation(typeAnnotation);

            if (baseUri != null)
            {
                xDestination.RemoveAnnotations(typeAnnotation);
                xDestination.AddAnnotation(baseUri);
            }
        }         // func XCopyAnnonation
Ejemplo n.º 3
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;
                        }
                    }
                }
Ejemplo n.º 4
0
                //[Variation(Desc = "Tuple - New Dev10 Types", Param = 1)]
                //[Variation(Desc = "DynamicObject - New Dev10 Types", Param = 2)]
                //[Variation(Desc = "Guid - old type", Param = 3)]
                //[Variation(Desc = "Dictionary - old type", Param = 4)]
                public void CreatingXElementsFromNewDev10Types()
                {
                    object t     = null;
                    Type   type  = typeof(object);
                    int    param = (int)this.Variation.Param;

                    switch (param)
                    {
                    case 1: t = Tuple.Create(1, "Melitta", 7.5); type = typeof(Tuple); break;

                    case 3: t = new Guid(); type = typeof(Guid); break;

                    case 4: t = new Dictionary <int, string>(); ((Dictionary <int, string>)t).Add(7, "a"); type = typeof(Dictionary <int, string>); break;
                    }

                    XElement e = new XElement("e1",
                                              new XElement("e2"), "text1",
                                              new XElement("e3"), t);

                    e.Add(t);
                    e.FirstNode.ReplaceWith(t);

                    XNode n = e.FirstNode.NextNode;

                    n.AddBeforeSelf(t);
                    n.AddAnnotation(t);
                    n.ReplaceWith(t);

                    e.FirstNode.AddAfterSelf(t);
                    e.AddFirst(t);
                    e.Annotation(type);
                    e.Annotations(type);
                    e.RemoveAnnotations(type);
                    e.ReplaceAll(t);
                    e.ReplaceAttributes(t);
                    e.ReplaceNodes(t);
                    e.SetAttributeValue("a", t);
                    e.SetElementValue("e2", t);
                    e.SetValue(t);

                    XAttribute        a  = new XAttribute("a", t);
                    XStreamingElement se = new XStreamingElement("se", t);

                    se.Add(t);

                    try
                    {
                        new XDocument(t);
                    }
                    catch (ArgumentException)
                    {
                        try
                        {
                            new XDocument(t);
                        }
                        catch (ArgumentException)
                        {
                            return;
                        }
                    }
                    TestLog.Compare(false, "Failed");
                }