Beispiel #1
0
 //[Variation(Priority = 0, Desc = "XProcessingInstruction - Name")]
 public void PIVariation()
 {
     XProcessingInstruction toChange = new XProcessingInstruction("target", "data");
     XProcessingInstruction original = new XProcessingInstruction(toChange);
     using (UndoManager undo = new UndoManager(toChange))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(toChange))
         {
             toChange.Target = "newTarget";
             TestLog.Compare(toChange.Target.Equals("newTarget"), "Name did not change");
             eHelper.Verify(XObjectChange.Name, toChange);
         }
         undo.Undo();
         TestLog.Compare(XNode.DeepEquals(toChange, original), "Undo did not work");
     }
 }
Beispiel #2
0
 public void ExecuteXDocumentVariation()
 {
     XNode toReplace = Variation.Params[0] as XNode;
     XNode newValue = Variation.Params[1] as XNode;
     XDocument xDoc = new XDocument(toReplace);
     XDocument xDocOriginal = new XDocument(xDoc);
     using (UndoManager undo = new UndoManager(xDoc))
     {
         undo.Group();
         using (EventsHelper docHelper = new EventsHelper(xDoc))
         {
             toReplace.ReplaceWith(newValue);
             docHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Add }, new XObject[] { toReplace, newValue });
         }
         undo.Undo();
         TestLog.Compare(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
     }
 }
Beispiel #3
0
 public void ExecuteXElementVariation()
 {
     XElement toChange = Variation.Params[0] as XElement;
     XName newName = (XName)Variation.Params[1];
     XElement original = new XElement(toChange);
     using (UndoManager undo = new UndoManager(toChange))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(toChange))
         {
             toChange.Name = newName;
             TestLog.Compare(newName.Namespace == toChange.Name.Namespace, "Namespace did not change");
             TestLog.Compare(newName.LocalName == toChange.Name.LocalName, "LocalName did not change");
             eHelper.Verify(XObjectChange.Name, toChange);
         }
         undo.Undo();
         TestLog.Compare(XNode.DeepEquals(toChange, original), "Undo did not work");
     }
 }
Beispiel #4
0
 public void ExecuteXDocumentVariation()
 {
     XNode[] content = Variation.Params[0] as XNode[];
     int index = (int)Variation.Params[1];
     XDocument xDoc = new XDocument(content);
     XDocument xDocOriginal = new XDocument(xDoc);
     XNode toRemove = xDoc.Nodes().ElementAt(index);
     using (UndoManager undo = new UndoManager(xDoc))
     {
         undo.Group();
         using (EventsHelper docHelper = new EventsHelper(xDoc))
         {
             toRemove.Remove();
             docHelper.Verify(XObjectChange.Remove, toRemove);
         }
         undo.Undo();
         TestLog.Compare(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
     }
 }
Beispiel #5
0
 public void ExecuteXElementVariation()
 {
     XNode toReplace = Variation.Params[0] as XNode;
     XNode newValue = Variation.Params[1] as XNode;
     XElement xElem = new XElement("root", toReplace);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             toReplace.ReplaceWith(newValue);
             xElem.Verify();
             eHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Add }, new XObject[] { toReplace, newValue });
         }
         undo.Undo();
         TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Beispiel #6
0
                public void ExecuteXElementVariation()
                {
                    XElement toChange = Variation.Params[0] as XElement;
                    XName    newName  = (XName)Variation.Params[1];
                    XElement original = new XElement(toChange);

                    using (UndoManager undo = new UndoManager(toChange))
                    {
                        undo.Group();
                        using (EventsHelper eHelper = new EventsHelper(toChange))
                        {
                            toChange.Name = newName;
                            TestLog.Compare(newName.Namespace == toChange.Name.Namespace, "Namespace did not change");
                            TestLog.Compare(newName.LocalName == toChange.Name.LocalName, "LocalName did not change");
                            eHelper.Verify(XObjectChange.Name, toChange);
                        }
                        undo.Undo();
                        TestLog.Compare(XNode.DeepEquals(toChange, original), "Undo did not work");
                    }
                }
Beispiel #7
0
                public void ExecuteRemoveVariation()
                {
                    XElement content       = Variation.Params[0] as XElement;
                    XElement xElem         = new XElement("root", content);
                    XElement xElemOriginal = new XElement(xElem);

                    using (UndoManager undo = new UndoManager(xElem))
                    {
                        undo.Group();
                        using (EventsHelper eHelper = new EventsHelper(xElem))
                        {
                            xElem.SetElementValue(content.Name, null);
                            xElem.Verify();
                            eHelper.Verify(XObjectChange.Remove, content);
                        }
                        undo.Undo();
                        TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                        TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
                    }
                }
Beispiel #8
0
                public void ExecuteXDocumentVariation()
                {
                    XNode     toReplace    = Variation.Params[0] as XNode;
                    XNode     newValue     = new XText(" ");
                    XDocument xDoc         = new XDocument(toReplace);
                    XDocument xDocOriginal = new XDocument(xDoc);

                    using (UndoManager undo = new UndoManager(xDoc))
                    {
                        undo.Group();
                        using (EventsHelper docHelper = new EventsHelper(xDoc))
                        {
                            xDoc.ReplaceNodes(newValue);
                            TestLog.Compare(xDoc.Nodes().Count() == 1, "Not all content were removed");
                            TestLog.Compare(Object.ReferenceEquals(xDoc.FirstNode, newValue), "Did not replace correctly");
                            docHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Add }, new XObject[] { toReplace, newValue });
                        }
                        undo.Undo();
                        TestLog.Compare(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
                    }
                }
Beispiel #9
0
                public void ExecuteXAttributeVariation()
                {
                    XAttribute[] content       = Variation.Params as XAttribute[];
                    XElement     xElem         = new XElement("root", content);
                    XElement     xElemOriginal = new XElement(xElem);

                    using (UndoManager undo = new UndoManager(xElem))
                    {
                        undo.Group();
                        using (EventsHelper eHelper = new EventsHelper(xElem))
                        {
                            xElem.ReplaceAttributes(new XAttribute("a", "aa"));
                            TestLog.Compare(XObject.ReferenceEquals(xElem.FirstAttribute, xElem.LastAttribute), "Did not replace attributes correctly");
                            xElem.Verify();
                            eHelper.Verify(content.Length + 1);
                        }
                        undo.Undo();
                        TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                        TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
                    }
                }
Beispiel #10
0
                public void ExecuteXElementVariation()
                {
                    XNode    toReplace     = Variation.Params[0] as XNode;
                    XNode    newValue      = Variation.Params[1] as XNode;
                    XElement xElem         = new XElement("root", toReplace);
                    XElement xElemOriginal = new XElement(xElem);

                    using (UndoManager undo = new UndoManager(xElem))
                    {
                        undo.Group();
                        using (EventsHelper eHelper = new EventsHelper(xElem))
                        {
                            toReplace.ReplaceWith(newValue);
                            xElem.Verify();
                            eHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Add }, new XObject[] { toReplace, newValue });
                        }
                        undo.Undo();
                        TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                        TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
                    }
                }
Beispiel #11
0
                public void ExecuteXElementVariation()
                {
                    XElement toChange      = Variation.Params[0] as XElement;
                    int      count         = toChange.Nodes().Count();
                    Object   newValue      = Variation.Params[1];
                    XElement xElemOriginal = new XElement(toChange);

                    using (UndoManager undo = new UndoManager(toChange))
                    {
                        undo.Group();
                        using (EventsHelper eHelper = new EventsHelper(toChange))
                        {
                            toChange.SetValue(newValue);
                            TestLog.Compare(newValue.Equals(toChange.Value), "Value change was not correct");
                            toChange.Verify();
                            eHelper.Verify(count + 1);
                        }
                        undo.Undo();
                        TestLog.Compare(toChange.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                        TestLog.Compare(toChange.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
                    }
                }
Beispiel #12
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!");
                    }
                }
Beispiel #13
0
                public void ExecuteXElementVariation()
                {
                    XObject[] content       = Variation.Params as XObject[];
                    XElement  xElem         = new XElement("root", content);
                    XElement  xElemOriginal = new XElement(xElem);

                    using (UndoManager undo = new UndoManager(xElem))
                    {
                        undo.Group();
                        using (EventsHelper elemHelper = new EventsHelper(xElem))
                        {
                            xElem.RemoveAll();
                            TestLog.Compare(xElem.IsEmpty, "Not all content were removed");
                            TestLog.Compare(!xElem.HasAttributes, "RemoveAll did not remove attributes");
                            xElem.Verify();
                            elemHelper.Verify(XObjectChange.Remove, content);
                        }
                        undo.Undo();
                        TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                        TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
                    }
                }
Beispiel #14
0
                public void ExecuteXElementVariation()
                {
                    XNode[]  content       = Variation.Params[0] as XNode[];
                    int      index         = (int)Variation.Params[1];
                    XElement xElem         = new XElement("root", content);
                    XNode    toRemove      = xElem.Nodes().ElementAt(index);
                    XElement xElemOriginal = new XElement(xElem);

                    using (UndoManager undo = new UndoManager(xElem))
                    {
                        undo.Group();
                        using (EventsHelper elemHelper = new EventsHelper(xElem))
                        {
                            toRemove.Remove();
                            xElem.Verify();
                            elemHelper.Verify(XObjectChange.Remove, toRemove);
                        }
                        undo.Undo();
                        TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                        TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
                    }
                }
Beispiel #15
0
                public void ExecuteXAttributeVariation()
                {
                    XAttribute toChange      = Variation.Params[0] as XAttribute;
                    Object     newValue      = Variation.Params[1];
                    XElement   xElem         = new XElement("root", toChange);
                    XElement   xElemOriginal = new XElement(xElem);

                    using (UndoManager undo = new UndoManager(xElem))
                    {
                        undo.Group();
                        using (EventsHelper eHelper = new EventsHelper(toChange))
                        {
                            xElem.SetAttributeValue(toChange.Name, newValue);
                            TestLog.Compare(newValue.Equals(toChange.Value), "Value did not change");
                            xElem.Verify();
                            eHelper.Verify(XObjectChange.Value, toChange);
                        }
                        undo.Undo();
                        TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                        TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
                    }
                }
Beispiel #16
0
                public void ExecuteXDocumentVariation()
                {
                    XNode[]             toAdd = Variation.Params[0] as XNode[];
                    XNode               contextNode = Variation.Params[1] as XNode;
                    IEnumerable <XNode> allNodes, toAddList = toAdd.OfType <XNode>();
                    XDocument           xDoc         = contextNode == null ? new XDocument() : new XDocument(contextNode);
                    XDocument           xDocOriginal = new XDocument(xDoc);

                    using (UndoManager undo = new UndoManager(xDoc))
                    {
                        undo.Group();
                        using (EventsHelper docHelper = new EventsHelper(xDoc))
                        {
                            xDoc.Add(toAdd);
                            allNodes = contextNode == null?xDoc.Nodes() : contextNode.NodesAfterSelf();

                            TestLog.Compare(toAddList.SequenceEqual(allNodes, XNode.EqualityComparer), "Nodes not added correctly!");
                            docHelper.Verify(XObjectChange.Add, toAdd);
                        }
                        undo.Undo();
                        TestLog.Compare(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
                    }
                }
Beispiel #17
0
                public void ExecuteValueVariation()
                {
                    XElement content       = Variation.Params[0] as XElement;
                    int      count         = content.Nodes().Count();
                    Object   newValue      = Variation.Params[1];
                    XElement xElem         = new XElement("root", content);
                    XElement xElemOriginal = new XElement(xElem);

                    using (UndoManager undo = new UndoManager(xElem))
                    {
                        undo.Group();
                        using (EventsHelper eHelper = new EventsHelper(xElem))
                        {
                            xElem.SetElementValue(content.Name, newValue);
                            // First all contents are removed and then new element with the value is added.
                            xElem.Verify();
                            eHelper.Verify(count + 1);
                        }
                        undo.Undo();
                        TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                        TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
                    }
                }
Beispiel #18
0
                public void ExecuteXAttributeVariation()
                {
                    XAttribute[]             toAdd = Variation.Params[0] as XAttribute[];
                    XAttribute               contextNode = Variation.Params[1] as XAttribute;
                    IEnumerable <XAttribute> allNodes, toAddList = toAdd.OfType <XAttribute>();
                    XElement xElem = contextNode == null ? new XElement("root") : new XElement("root", contextNode);
                    XElement xElemOriginal = new XElement(xElem);

                    using (UndoManager undo = new UndoManager(xElem))
                    {
                        undo.Group();
                        using (EventsHelper elemHelper = new EventsHelper(xElem))
                        {
                            xElem.Add(toAdd);
                            allNodes = contextNode == null?xElem.Attributes() : xElem.Attributes().Skip(1);

                            TestLog.Compare(toAddList.SequenceEqual(allNodes, Helpers.MyAttributeComparer), "Attributes not added correctly!");
                            elemHelper.Verify(XObjectChange.Add, toAdd);
                        }
                        undo.Undo();
                        TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                        TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
                    }
                }
Beispiel #19
0
 //[Variation(Priority = 0, Desc = "XComment - change value")]
 public void XCommentValue()
 {
     XComment toChange = new XComment("Original Value");
     String newValue = "New Value";
     XElement xElem = new XElement("root", toChange);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             using (EventsHelper comHelper = new EventsHelper(toChange))
             {
                 toChange.Value = newValue;
                 TestLog.Compare(toChange.Value.Equals(newValue), "Value did not change");
                 xElem.Verify();
                 comHelper.Verify(XObjectChange.Value, toChange);
             }
             eHelper.Verify(XObjectChange.Value, toChange);
         }
         undo.Undo();
         TestLog.Compare(XNode.DeepEquals(xElem, xElemOriginal), "Undo did not work!");
     }
 }
Beispiel #20
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!");
                    }
                }
Beispiel #21
0
                public void ExecuteXElementVariation()
                {
                    XNode    toReplace     = Variation.Params[0] as XNode;
                    XNode    newValue      = new XText("text");
                    XElement xElem         = new XElement("root", InputSpace.GetAttributeElement(10, 1000).Elements().Attributes(), toReplace);
                    XElement xElemOriginal = new XElement(xElem);

                    using (UndoManager undo = new UndoManager(xElem))
                    {
                        undo.Group();
                        using (EventsHelper eHelper = new EventsHelper(xElem))
                        {
                            xElem.ReplaceNodes(newValue);
                            TestLog.Compare(xElem.Nodes().Count() == 1, "Did not replace correctly");
                            TestLog.Compare(Object.ReferenceEquals(xElem.FirstNode, newValue), "Did not replace correctly");
                            TestLog.Compare(xElem.HasAttributes, "ReplaceNodes removed attributes");
                            xElem.Verify();
                            eHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Add }, new XObject[] { toReplace, newValue });
                        }
                        undo.Undo();
                        TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                        TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
                    }
                }
Beispiel #22
0
 public void ExecuteXDocumentVariation()
 {
     XNode[] toAdd = Variation.Params[0] as XNode[];
     XNode contextNode = Variation.Params[1] as XNode;
     IEnumerable<XNode> toAddList = toAdd.OfType<XNode>();
     XDocument xDoc = new XDocument(contextNode);
     XDocument xDocOriginal = new XDocument(xDoc);
     using (UndoManager undo = new UndoManager(xDoc))
     {
         undo.Group();
         using (EventsHelper docHelper = new EventsHelper(xDoc))
         {
             using (EventsHelper nodeHelper = new EventsHelper(contextNode))
             {
                 contextNode.AddBeforeSelf(toAdd);
                 TestLog.Compare(toAddList.SequenceEqual(contextNode.NodesBeforeSelf(), XNode.EqualityComparer), "Nodes not added correctly!");
                 nodeHelper.Verify(0);
             }
             docHelper.Verify(XObjectChange.Add, toAdd);
         }
         undo.Undo();
         TestLog.Compare(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
     }
 }
Beispiel #23
0
                public void ExecuteXElementVariation()
                {
                    XObject[] toReplace     = Variation.Params as XObject[];
                    XNode     newValue      = new XText("text");
                    XElement  xElem         = new XElement("root", toReplace);
                    XElement  xElemOriginal = new XElement(xElem);

                    using (UndoManager undo = new UndoManager(xElem))
                    {
                        undo.Group();
                        using (EventsHelper eHelper = new EventsHelper(xElem))
                        {
                            xElem.ReplaceAll(newValue);
                            TestLog.Compare(xElem.Nodes().Count() == 1, "Did not replace correctly");
                            TestLog.Compare(Object.ReferenceEquals(xElem.FirstNode, newValue), "Did not replace correctly");
                            TestLog.Compare(!xElem.HasAttributes, "ReplaceAll did not remove attributes");
                            xElem.Verify();
                            eHelper.Verify(toReplace.Length + 1);
                        }
                        undo.Undo();
                        TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                        TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
                    }
                }
Beispiel #24
0
 //[Variation(Priority = 1, Desc = "XAttribute - Remove one attribute at a time")]
 public void XAttributeRemoveOneByOne()
 {
     XDocument xDoc = new XDocument(InputSpace.GetAttributeElement(1, 100));
     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<XAttribute> list = xDoc.Root.Attributes().ToList();
                 foreach (XAttribute x in list)
                 {
                     x.Remove();
                     eHelper.Verify(XObjectChange.Remove, x);
                 }
                 docHelper.Verify(XObjectChange.Remove, list.Count);
             }
         }
         undo.Undo();
         TestLog.Compare(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
     }
 }
Beispiel #25
0
 //[Variation(Priority = 1, Desc = "XElement - Working on the text nodes 4.")]
 public void WorkOnTextNodes4()
 {
     XElement elem = new XElement("A", "text2");
     elem.FirstNode.AddAfterSelf("text0");
     elem.FirstNode.AddAfterSelf("text1");
     using (UndoManager undo = new UndoManager(elem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(elem))
         {
             elem.FirstNode.Remove();
             eHelper.Verify(XObjectChange.Remove);
             TestLog.Compare(elem.IsEmpty, "Did not remove correctly");
         }
         undo.Undo();
         TestLog.Compare(elem.Value, "text2text0text1", "Undo did not work");
     }
 }
Beispiel #26
0
 public void ExecuteXElementVariation()
 {
     XNode toReplace = Variation.Params[0] as XNode;
     XNode newValue = new XText("text");
     XElement xElem = new XElement("root", InputSpace.GetAttributeElement(10, 1000).Elements().Attributes(), toReplace);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             xElem.ReplaceNodes(newValue);
             TestLog.Compare(xElem.Nodes().Count() == 1, "Did not replace correctly");
             TestLog.Compare(Object.ReferenceEquals(xElem.FirstNode, newValue), "Did not replace correctly");
             TestLog.Compare(xElem.HasAttributes, "ReplaceNodes removed attributes");
             xElem.Verify();
             eHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Add }, new XObject[] { toReplace, newValue });
         }
         undo.Undo();
         TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Beispiel #27
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!");
         }
     }
 }
Beispiel #28
0
                //[Variation(Priority = 1, Desc = "Element with attributes, with Element with attributes")]
                public void ElementWithAttributes()
                {
                    XElement toReplace = new XElement("Automobile",
                        new XAttribute("axles", 2),
                        new XElement("Make", "Ford"),
                        new XElement("Model", "Mustang"),
                        new XElement("Year", "2004"));
                    XElement xElemOriginal = new XElement(toReplace);

                    using (UndoManager undo = new UndoManager(toReplace))
                    {
                        undo.Group();
                        using (EventsHelper eHelper = new EventsHelper(toReplace))
                        {
                            toReplace.ReplaceAll(new XAttribute("axles", 2),
                                new XElement("Make", "Chevrolet"),
                                new XElement("Model", "Impala"),
                                new XElement("Year", "2006"));
                            toReplace.Verify();
                        }
                        undo.Undo();
                        TestLog.Compare(toReplace.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                        TestLog.Compare(toReplace.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
                    }
                }
Beispiel #29
0
 public void ExecuteXDocumentVariation()
 {
     XNode toReplace = Variation.Params[0] as XNode;
     XNode newValue = new XText(" ");
     XDocument xDoc = new XDocument(toReplace);
     XDocument xDocOriginal = new XDocument(xDoc);
     using (UndoManager undo = new UndoManager(xDoc))
     {
         undo.Group();
         using (EventsHelper docHelper = new EventsHelper(xDoc))
         {
             xDoc.ReplaceNodes(newValue);
             TestLog.Compare(xDoc.Nodes().Count() == 1, "Not all content were removed");
             TestLog.Compare(Object.ReferenceEquals(xDoc.FirstNode, newValue), "Did not replace correctly");
             docHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Add }, new XObject[] { toReplace, newValue });
         }
         undo.Undo();
         TestLog.Compare(XNode.DeepEquals(xDoc, xDocOriginal), "Undo did not work!");
     }
 }
Beispiel #30
0
 public void ExecuteXAttributeVariation()
 {
     XAttribute[] content = Variation.Params as XAttribute[];
     XElement xElem = new XElement("root", content);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             xElem.ReplaceAttributes(new XAttribute("a", "aa"));
             TestLog.Compare(XObject.ReferenceEquals(xElem.FirstAttribute, xElem.LastAttribute), "Did not replace attributes correctly");
             xElem.Verify();
             eHelper.Verify(content.Length + 1);
         }
         undo.Undo();
         TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Beispiel #31
0
 public void ExecuteXAttributeVariation()
 {
     XAttribute toChange = Variation.Params[0] as XAttribute;
     Object newValue = Variation.Params[1];
     XElement xElem = new XElement("root", toChange);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(toChange))
         {
             xElem.SetAttributeValue(toChange.Name, newValue);
             TestLog.Compare(newValue.Equals(toChange.Value), "Value did not change");
             xElem.Verify();
             eHelper.Verify(XObjectChange.Value, toChange);
         }
         undo.Undo();
         TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Beispiel #32
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!");
     }
 }
Beispiel #33
0
 //[Variation(Priority = 1, Desc = "XElement - Text node incarnation.")]
 public void WorkTextNodes()
 {
     XElement elem = new XElement("A", "text2");
     XElement xElemOriginal = new XElement(elem);
     using (UndoManager undo = new UndoManager(elem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(elem))
         {
             XNode x = elem.LastNode;
             eHelper.Verify(0);
         }
         undo.Undo();
         TestLog.Compare(XNode.DeepEquals(elem, xElemOriginal), "Undo did not work!");
     }
 }
Beispiel #34
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!");
     }
 }
Beispiel #35
0
 public void ExecuteXElementVariation()
 {
     XObject[] content = Variation.Params as XObject[];
     XElement xElem = new XElement("root", content);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper elemHelper = new EventsHelper(xElem))
         {
             xElem.RemoveAll();
             TestLog.Compare(xElem.IsEmpty, "Not all content were removed");
             TestLog.Compare(!xElem.HasAttributes, "RemoveAll did not remove attributes");
             xElem.Verify();
             elemHelper.Verify(XObjectChange.Remove, content);
         }
         undo.Undo();
         TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Beispiel #36
0
 public void ExecuteXElementVariation()
 {
     XNode[] toAdd = Variation.Params[0] as XNode[];
     XNode contextNode = Variation.Params[1] as XNode;
     IEnumerable<XNode> toAddList = toAdd.OfType<XNode>();
     XElement xElem = new XElement("root", contextNode);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper elemHelper = new EventsHelper(xElem))
         {
             using (EventsHelper nodeHelper = new EventsHelper(contextNode))
             {
                 contextNode.AddBeforeSelf(toAdd);
                 TestLog.Compare(toAddList.SequenceEqual(contextNode.NodesBeforeSelf(), XNode.EqualityComparer), "Nodes not added correctly!");
                 nodeHelper.Verify(0);
             }
             elemHelper.Verify(XObjectChange.Add, toAdd);
         }
         undo.Undo();
         TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Beispiel #37
0
 public void ExecuteXElementVariation()
 {
     XNode[] content = Variation.Params[0] as XNode[];
     int index = (int)Variation.Params[1];
     XElement xElem = new XElement("root", content);
     XNode toRemove = xElem.Nodes().ElementAt(index);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper elemHelper = new EventsHelper(xElem))
         {
             toRemove.Remove();
             xElem.Verify();
             elemHelper.Verify(XObjectChange.Remove, toRemove);
         }
         undo.Undo();
         TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Beispiel #38
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!");
     }
 }
Beispiel #39
0
 public void ExecuteXAttributeVariation()
 {
     XAttribute[] toAdd = Variation.Params[0] as XAttribute[];
     XAttribute contextNode = Variation.Params[1] as XAttribute;
     IEnumerable<XAttribute> allNodes, toAddList = toAdd.OfType<XAttribute>();
     XElement xElem = contextNode == null ? new XElement("root") : new XElement("root", contextNode);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper elemHelper = new EventsHelper(xElem))
         {
             xElem.Add(toAdd);
             allNodes = contextNode == null ? xElem.Attributes() : xElem.Attributes().Skip(1);
             TestLog.Compare(toAddList.SequenceEqual(allNodes, Helpers.MyAttributeComparer), "Attributes not added correctly!");
             elemHelper.Verify(XObjectChange.Add, toAdd);
         }
         undo.Undo();
         TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Beispiel #40
0
 public void ExecuteXElementVariation()
 {
     XObject[] toReplace = Variation.Params as XObject[];
     XNode newValue = new XText("text");
     XElement xElem = new XElement("root", toReplace);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             xElem.ReplaceAll(newValue);
             TestLog.Compare(xElem.Nodes().Count() == 1, "Did not replace correctly");
             TestLog.Compare(Object.ReferenceEquals(xElem.FirstNode, newValue), "Did not replace correctly");
             TestLog.Compare(!xElem.HasAttributes, "ReplaceAll did not remove attributes");
             xElem.Verify();
             eHelper.Verify(toReplace.Length + 1);
         }
         undo.Undo();
         TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Beispiel #41
0
 public void ExecuteValueVariation()
 {
     XElement content = Variation.Params[0] as XElement;
     int count = content.Nodes().Count();
     Object newValue = Variation.Params[1];
     XElement xElem = new XElement("root", content);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             xElem.SetElementValue(content.Name, newValue);
             // First all contents are removed and then new element with the value is added.
             xElem.Verify();
             eHelper.Verify(count + 1);
         }
         undo.Undo();
         TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Beispiel #42
0
 //[Variation(Priority = 1, Desc = "XElement - Working on the text nodes 2.")]
 public void WorkOnTextNodes2()
 {
     XElement elem = new XElement("A", "text2");
     XNode n = elem.FirstNode;
     using (UndoManager undo = new UndoManager(elem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(elem))
         {
             n.AddAfterSelf("text0", "text1");
             TestLog.Compare(elem.Value, "text2text0text1", "Did not concat text nodes correctly");
             eHelper.Verify(XObjectChange.Value);
         }
         undo.Undo();
         TestLog.Compare(elem.Value, "text2", "Undo did not work");
     }
 }
Beispiel #43
0
 public void ExecuteRemoveVariation()
 {
     XElement content = Variation.Params[0] as XElement;
     XElement xElem = new XElement("root", content);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             xElem.SetElementValue(content.Name, null);
             xElem.Verify();
             eHelper.Verify(XObjectChange.Remove, content);
         }
         undo.Undo();
         TestLog.Compare(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Beispiel #44
0
 //[Variation(Priority = 0, Desc = "XProcessingInstruction - change value")]
 public void XPIValue()
 {
     XProcessingInstruction toChange = new XProcessingInstruction("target", "Original Value");
     String newValue = "New Value";
     XElement xElem = new XElement("root", toChange);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(xElem))
         {
             using (EventsHelper piHelper = new EventsHelper(toChange))
             {
                 toChange.Data = newValue;
                 TestLog.Compare(toChange.Data.Equals(newValue), "Value did not change");
                 xElem.Verify();
                 piHelper.Verify(XObjectChange.Value, toChange);
             }
             eHelper.Verify(XObjectChange.Value, toChange);
         }
         undo.Undo();
         TestLog.Compare(XNode.DeepEquals(xElem, xElemOriginal), "Undo did not work!");
     }
 }
Beispiel #45
0
 public void ExecuteXElementVariation()
 {
     XElement toChange = Variation.Params[0] as XElement;
     int count = toChange.Nodes().Count();
     Object newValue = Variation.Params[1];
     XElement xElemOriginal = new XElement(toChange);
     using (UndoManager undo = new UndoManager(toChange))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(toChange))
         {
             toChange.SetValue(newValue);
             TestLog.Compare(newValue.Equals(toChange.Value), "Value change was not correct");
             toChange.Verify();
             eHelper.Verify(count + 1);
         }
         undo.Undo();
         TestLog.Compare(toChange.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         TestLog.Compare(toChange.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Beispiel #46
0
 //[Variation(Priority = 1, Desc = "XElement - Working on the text nodes 2.")]
 public void WorkOnTextNodes2()
 {
     XElement elem = new XElement("A", "text2");
     XElement xElemOriginal = new XElement(elem);
     using (UndoManager undo = new UndoManager(elem))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(elem))
         {
             elem.Add("text0", "text1");
             TestLog.Compare(elem.Value, "text2text0text1", "Did not concat text nodes correctly");
             eHelper.Verify(new XObjectChange[] { XObjectChange.Value, XObjectChange.Value });
         }
         undo.Undo();
         TestLog.Compare(elem.Value, "text2", "Undo did not work");
     }
 }