Exemplo n.º 1
0
        public void XElementRemoveOneByOne()
        {
            XDocument xDoc         = new XDocument(InputSpace.GetElement(100, 10));
            XDocument xDocOriginal = new XDocument(xDoc);

            using (UndoManager undo = new UndoManager(xDoc))
            {
                undo.Group();
                using (EventsHelper docHelper = new EventsHelper(xDoc))
                {
                    using (EventsHelper eHelper = new EventsHelper(xDoc.Root))
                    {
                        List <XElement> list = xDoc.Root.Elements().ToList();
                        foreach (XElement x in list)
                        {
                            x.Remove();
                            eHelper.Verify(XObjectChange.Remove, x);
                        }
                        docHelper.Verify(XObjectChange.Remove, list.Count);
                    }
                }
                undo.Undo();
                Assert.True(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
            }
        }
Exemplo n.º 2
0
                //[Variation(Priority = 2, Desc = "Exception in POST Event Handler")]
                public void XElementPostException()
                {
                    XDocument xDoc     = new XDocument(InputSpace.GetElement(10, 10));
                    XElement  toChange = xDoc.Descendants().ElementAt(5);

                    xDoc.Changing += new EventHandler <XObjectChangeEventArgs>(
                        delegate(object sender, XObjectChangeEventArgs e)
                    {
                        // Do nothing
                    });

                    xDoc.Changed += new EventHandler <XObjectChangeEventArgs>(
                        delegate(object sender, XObjectChangeEventArgs e)
                    {
                        throw new InvalidOperationException("This should be propagated and operation should perform");
                    });

                    try
                    {
                        toChange.Add(new XElement("Add", "Me"));
                    }
                    catch (InvalidOperationException)
                    {
                        xDoc.Root.Verify();
                        TestLog.Compare(toChange.Element("Add") != null, "Did not add the element, operation should have completed");
                        return;
                    }
                    throw new TestException(TestResult.Failed, "");
                }
        public void AddingRemovingNullListenersXElementRemoveNullEventListner()
        {
            XDocument xDoc = new XDocument(InputSpace.GetElement(10, 10));
            EventHandler <XObjectChangeEventArgs> d1 = ChangingDelegate;
            EventHandler <XObjectChangeEventArgs> d2 = ChangedDelegate;

            //Add null first, this should add nothing
            xDoc.Changing += null;
            xDoc.Changed  += null;
            //Add the actual delegate
            xDoc.Changing += new EventHandler <XObjectChangeEventArgs>(d1);
            xDoc.Changed  += new EventHandler <XObjectChangeEventArgs>(d2);
            //Now set it to null
            d1 = null;
            d2 = null;
            xDoc.Root.Add(new XComment("This is a comment"));
            //Remove nulls
            xDoc.Changing -= null;
            xDoc.Changed  -= null;
            //Try removing the originally added delegates
            d1             = ChangingDelegate;
            d2             = ChangedDelegate;
            xDoc.Changing -= new EventHandler <XObjectChangeEventArgs>(d1);
            xDoc.Changed  -= new EventHandler <XObjectChangeEventArgs>(d2);
        }
Exemplo n.º 4
0
                //[Variation(Priority = 1, Desc = "XElement - Replace Nodes")]
                public void ReplaceNodes()
                {
                    XElement xElem         = new XElement(InputSpace.GetElement(1000, 2));
                    int      count         = xElem.Nodes().Count();
                    XElement xElemOriginal = new XElement(xElem);

                    using (UndoManager undo = new UndoManager(xElem))
                    {
                        undo.Group();
                        using (EventsHelper eHelper = new EventsHelper(xElem))
                        {
                            foreach (XElement x in xElem.Nodes())
                            {
                                using (EventsHelper xHelper = new EventsHelper(x))
                                {
                                    x.ReplaceNodes("text");
                                    xHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Remove, XObjectChange.Remove, XObjectChange.Add });
                                }
                                eHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Remove, XObjectChange.Remove, XObjectChange.Add });
                            }
                            undo.Undo();
                            TestLog.Compare(XNode.DeepEquals(xElem, xElemOriginal), "Undo did not work!");
                        }
                    }
                }
Exemplo n.º 5
0
 void VariationsForXElement(TestFunc func)
 {
     AddChild(func, 0, "Empty element, String", new XElement("element"), "newValue");
     AddChild(func, 0, "String, String", new XElement("element", "value"), "newValue");
     AddChild(func, 0, "Element with attributes, String", new XElement("element", new XAttribute("a", "aa")), "newValue");
     AddChild(func, 0, "Element with child, String", new XElement("parent", new XElement("child", "child text")), "newValue");
     AddChild(func, 1, "Element with nodes", new XElement("root", InputSpace.GetElement(100, 10).DescendantNodes()), "newValue");
 }
Exemplo n.º 6
0
 void VariationsForXElement(TestFunc func)
 {
     AddChild(func, 0, "XElement - empty element before text", new XNode[] { new XElement("element") }, new XText("some text"));
     AddChild(func, 0, "XElement - element before PI", new XNode[] { new XElement("parent", new XElement("child", "child text")) }, new XProcessingInstruction("PI", "Data"));
     AddChild(func, 0, "XElement - CData before element", new XNode[] { new XCData("x+y >= z-m") }, new XElement("child"));
     AddChild(func, 0, "XElement - PI before text", new XNode[] { new XProcessingInstruction("PI", "Data") }, new XText(" "));
     AddChild(func, 0, "XElement - comment before CData", new XNode[] { new XComment("Comment") }, new XCData("x+y >= z-m"));
     AddChild(func, 1, "XElement - text before empty text", new XNode[] { new XText(""), new XText(" "), new XText("\t") }, new XText(" "));
     AddChild(func, 1, "XElement - IEnumerable of XNodes", InputSpace.GetElement(100, 10).DescendantNodes().ToArray(), new XText(".."));
 }
Exemplo n.º 7
0
        public void AddIEnumerableOfXNodes()
        {
            XElement          x             = InputSpace.GetElement(100, 3);
            XElement          element       = new XElement("root", x.Nodes());
            XStreamingElement streamElement = new XStreamingElement("root");

            streamElement.Add(x.Nodes());
            GetFreshStream();
            streamElement.Save(_sourceStream);
            element.Save(_targetStream);
            ResetStreamPos();
            Assert.True(Diff.Compare(_sourceStream, _targetStream));
        }
Exemplo n.º 8
0
 void VariationsForXElement(TestFunc func)
 {
     AddChild(func, 1, "XElement - empty element", new XNode[] { new XElement("element") }, 0);
     AddChild(func, 0, "XElement - first element", new XNode[] { new XElement("parent", new XElement("child", "child text")) }, 0);
     AddChild(func, 0, "XElement - last element", new XNode[] { new XElement("parent", "parent text"), new XElement("child", "child text") }, 1);
     AddChild(func, 0, "XElement - middle node", new XNode[] { new XElement("parent", "parent text"), new XText("text"), new XElement("child", "child text") }, 1);
     AddChild(func, 0, "XElement - CData", new XNode[] { new XCData("x+y >= z-m") }, 0);
     AddChild(func, 0, "XElement - PI", new XNode[] { new XProcessingInstruction("PI", "Data") }, 0);
     AddChild(func, 0, "XElement - comment", new XNode[] { new XComment("Comment") }, 0);
     AddChild(func, 0, "XElement - first text nodes", new XNode[] { new XText(""), new XText(" "), new XText("\t") }, 0);
     AddChild(func, 1, "XElement - second text nodes", new XNode[] { new XText(""), new XText(" "), new XText("\t") }, 1);
     AddChild(func, 1, "XElement - third text nodes", new XNode[] { new XText(""), new XText(" "), new XText("\t") }, 2);
     AddChild(func, 1, "XElement - IEnumerable of XNodes", InputSpace.GetElement(100, 10).DescendantNodes().ToArray(), 50);
 }
        public void AddAndRemoveEventListnersXElementAddRemoveEventListners()
        {
            XDocument    xDoc      = new XDocument(InputSpace.GetElement(10, 10));
            EventsHelper docHelper = new EventsHelper(xDoc);
            EventsHelper eHelper   = new EventsHelper(xDoc.Root);

            xDoc.Root.Add(new XElement("Add", "Me"));
            docHelper.Verify(XObjectChange.Add);
            eHelper.Verify(XObjectChange.Add);
            eHelper.RemoveListners();
            xDoc.Root.Add(new XComment("Comment"));
            eHelper.Verify(0);
            docHelper.Verify(XObjectChange.Add);
        }
Exemplo n.º 10
0
                //[Variation(Priority = 0, Desc = "Add(IEnumerable of XNodes)")]
                public void AddIEnumerableOfXNodes()
                {
                    XElement          x             = InputSpace.GetElement(100, 3);
                    XElement          element       = new XElement("root", x.Nodes());
                    XStreamingElement streamElement = new XStreamingElement("root");

                    streamElement.Add(x.Nodes());
                    getFreshStream();
                    streamElement.Save(_sourceStream); element.Save(_targetStream);
                    resetStreamPos();
                    if (!_diff.Compare(_sourceStream, _targetStream))
                    {
                        throw new TestFailedException("");
                    }
                }
Exemplo n.º 11
0
 void VariationsForXElement(TestFunc func)
 {
     AddChild(func, 1, "XElement - empty element", new XObject[] { new XElement("element") });
     AddChild(func, 0, "XElement - element with child", new XObject[] { new XElement("parent", new XElement("child", "child text")) });
     AddChild(func, 0, "XElement - CData", new XObject[] { new XCData("x+y >= z-m") });
     AddChild(func, 0, "XElement - PI", new XObject[] { new XProcessingInstruction("PI", "Data") });
     AddChild(func, 0, "XElement - comment", new XObject[] { new XComment("Comment") });
     AddChild(func, 0, "XElement - text nodes", new XObject[] { new XText(""), new XText(" "), new XText("\t") });
     AddChild(func, 1, "XElement - IEnumerable of XNodes", InputSpace.GetElement(100, 10).DescendantNodes().ToArray());
     AddChild(func, 0, "XAttribute - only attribute", new XObject[] { new XAttribute("xxx", "yyy") });
     AddChild(func, 0, "XAttribute - only attribute with namespace", new XObject[] { new XAttribute("{a}xxx", "a_yyy") });
     AddChild(func, 0, "XAttribute - mulitple attributes", new XObject[] { new XAttribute("xxx", "yyy"), new XAttribute("a", "aa") });
     AddChild(func, 1, "XAttribute - multiple attributes with namespace", new XObject[] { new XAttribute("{b}xxx", "b_yyy"), new XAttribute("{a}xxx", "a_yyy") });
     AddChild(func, 1, "XAttribute - IEnumerable of XAttributes", InputSpace.GetAttributeElement(10, 1000).Elements().Attributes().ToArray());
     AddChild(func, 1, "Mixed - Nodes and attributes", new XObject[] { new XAttribute("{b}xxx", "b_yyy"), new XElement("parent", new XElement("child", "child text")) });
 }
Exemplo n.º 12
0
                //[Variation(Priority = 1, Desc = "XElement - Replace with IEnumerable")]
                public void ReplaceWithIEnum()
                {
                    XElement            xElem         = new XElement("root");
                    IEnumerable <XNode> newValue      = InputSpace.GetElement(1000, 2).DescendantNodes();
                    XElement            xElemOriginal = new XElement(xElem);

                    using (UndoManager undo = new UndoManager(xElem))
                    {
                        undo.Group();
                        using (EventsHelper eHelper = new EventsHelper(xElem))
                        {
                            xElem.ReplaceNodes(newValue);
                            eHelper.Verify(XObjectChange.Add, newValue.ToArray());
                        }
                        undo.Undo();
                        TestLog.Compare(XNode.DeepEquals(xElem, xElemOriginal), "Undo did not work!");
                    }
                }
        public void ExceptionInPOSTEventHandlerXElementPostException()
        {
            XDocument xDoc     = new XDocument(InputSpace.GetElement(10, 10));
            XElement  toChange = xDoc.Descendants().ElementAt(5);

            xDoc.Changing += new EventHandler <XObjectChangeEventArgs>(
                delegate(object sender, XObjectChangeEventArgs e)
            {
                // Do nothing
            });

            xDoc.Changed += new EventHandler <XObjectChangeEventArgs>(
                delegate(object sender, XObjectChangeEventArgs e)
            {
                throw new InvalidOperationException("This should be propagated and operation should perform");
            });

            Assert.Throws <InvalidOperationException>(() => { toChange.Add(new XElement("Add", "Me")); });
            xDoc.Root.Verify();
            Assert.NotNull(toChange.Element("Add"));
        }
Exemplo n.º 14
0
                //[Variation(Priority = 1, Desc = "Remove Sequence - IEnumerable<XElement>")]
                public void XElementRemoveSeq()
                {
                    XDocument xDoc         = new XDocument(InputSpace.GetElement(100, 10));
                    XDocument xDocOriginal = new XDocument(xDoc);

                    using (UndoManager undo = new UndoManager(xDoc))
                    {
                        undo.Group();
                        using (EventsHelper docHelper = new EventsHelper(xDoc))
                        {
                            using (EventsHelper eHelper = new EventsHelper(xDoc.Root))
                            {
                                List <XElement> list = xDoc.Root.Elements().ToList();
                                xDoc.Root.Elements().Remove();
                                eHelper.Verify(XObjectChange.Remove, list.ToArray());
                                docHelper.Verify(XObjectChange.Remove, list.ToArray());
                            }
                        }
                        undo.Undo();
                        TestLog.Compare(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
                    }
                }
        public void RemoveBothEventListenersXElementRemoveBothEventListners()
        {
            XDocument xDoc = new XDocument(InputSpace.GetElement(10, 10));
            EventHandler <XObjectChangeEventArgs> d1 = ChangingDelegate;
            EventHandler <XObjectChangeEventArgs> d2 = ChangedDelegate;

            xDoc.Changing += new EventHandler <XObjectChangeEventArgs>(d1);
            xDoc.Changed  += new EventHandler <XObjectChangeEventArgs>(d2);
            xDoc.Root.Add(new XComment("This is a comment"));
            xDoc.Changing -= new EventHandler <XObjectChangeEventArgs>(d1);
            xDoc.Changed  -= new EventHandler <XObjectChangeEventArgs>(d2);
            //Remove it again
            xDoc.Changing -= new EventHandler <XObjectChangeEventArgs>(d1);
            xDoc.Changed  -= new EventHandler <XObjectChangeEventArgs>(d2);
            //Change the order
            xDoc.Changed  += new EventHandler <XObjectChangeEventArgs>(d2);
            xDoc.Changing += new EventHandler <XObjectChangeEventArgs>(d1);
            xDoc.Root.Add(new XComment("This is a comment"));
            xDoc.Changed  -= new EventHandler <XObjectChangeEventArgs>(d2);
            xDoc.Changing -= new EventHandler <XObjectChangeEventArgs>(d1);
            //Remove it again
            xDoc.Changed  -= new EventHandler <XObjectChangeEventArgs>(d2);
            xDoc.Changing -= new EventHandler <XObjectChangeEventArgs>(d1);
        }
Exemplo n.º 16
0
                //[Variation(Priority = 1, Desc = "XElement - Add at each level, nested elements")]
                public void XElementAddAtDeepLevel()
                {
                    XDocument xDoc         = new XDocument(InputSpace.GetElement(100, 10));
                    XDocument xDocOriginal = new XDocument(xDoc);

                    using (UndoManager undo = new UndoManager(xDoc))
                    {
                        undo.Group();
                        using (EventsHelper docHelper = new EventsHelper(xDoc))
                        {
                            using (EventsHelper eHelper = new EventsHelper(xDoc.Root))
                            {
                                foreach (XElement x in xDoc.Root.Descendants())
                                {
                                    x.Add(new XText("Add Me"));
                                    eHelper.Verify(XObjectChange.Add);
                                }
                                docHelper.Verify(XObjectChange.Add, xDoc.Root.Descendants().Count());
                            }
                        }
                        undo.Undo();
                        TestLog.Compare(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
                    }
                }
Exemplo n.º 17
0
 void VariationsForRemove(TestFunc func)
 {
     AddChild(func, 1, "Remove - Empty element", new XElement("element"));
     AddChild(func, 0, "Remove - Element with value", new XElement("element", "value"));
     AddChild(func, 0, "Remove - Element with attribute", new XElement("element", new XAttribute("a", "aa")));
     AddChild(func, 0, "Remove - Element with child", new XElement("parent", new XElement("child", "child text")));
     AddChild(func, 1, "Remove - Element with nodes", new XElement("nodes", InputSpace.GetElement(100, 10).DescendantNodes()));
 }
Exemplo n.º 18
0
 void VariationsForValue(TestFunc func)
 {
     AddChild(func, 1, "Value - Empty element", new XElement("element"), (double)10);
     AddChild(func, 0, "Value - Element with value", new XElement("element", "value"), "newValue");
     AddChild(func, 0, "Value - Element with attribute", new XElement("element", new XAttribute("a", "aa")), System.DateTime.Now);
     AddChild(func, 0, "Value - Element with child", new XElement("parent", new XElement("child", "child text")), "Windows 8");
     AddChild(func, 1, "Value - Element with nodes", new XElement("nodes", InputSpace.GetElement(100, 10).DescendantNodes()), "StackTrace");//Environment.StackTrace);
 }
Exemplo n.º 19
0
 void VariationsForXAttribute(TestFunc func)
 {
     AddChild(func, 0, "XAttribute - attribute in element with no attributes", new XAttribute[] { new XAttribute("xxx", "yyy") }, null);
     AddChild(func, 0, "XAttribute - attribute with namespace in element with no attributes", new XAttribute[] { new XAttribute("{a}xxx", "a_yyy") }, null);
     AddChild(func, 1, "XAttribute - IEnumerable of XAttributes in element with no attributes", InputSpace.GetElement(100, 10).Attributes().ToArray(), null);
     AddChild(func, 0, "XAttribute - attribute in element with attribute", new XAttribute[] { new XAttribute("xxx", "yyy") }, new XAttribute("a", "aa"));
     AddChild(func, 0, "XAttribute - attribute with namespace in element with attributes", new XAttribute[] { new XAttribute("{b}xxx", "b_yyy") }, new XAttribute("a", "aa"));
     AddChild(func, 1, "XAttribute - IEnumerable of XAttributes in element with no attributes", InputSpace.GetElement(100, 10).Attributes().ToArray(), new XAttribute("a", "aa"));
 }