Example #1
0
 public void ExecuteXElementVariation(XNode toReplace, XNode newValue)
 {
     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();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #2
0
 public void ExecuteXElementVariation(XNode[] content, int index)
 {
     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();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #3
0
 public void XCommentChangeValue()
 {
     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;
                 Assert.True(toChange.Value.Equals(newValue), "Value did not change");
                 xElem.Verify();
                 comHelper.Verify(XObjectChange.Value, toChange);
             }
             eHelper.Verify(XObjectChange.Value, toChange);
         }
         undo.Undo();
         Assert.True(XNode.DeepEquals(xElem, xElemOriginal), "Undo did not work!");
     }
 }
Example #4
0
 public void ExecuteXAttributeVariation(XAttribute toChange, object newValue)
 {
     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);
             Assert.True(newValue.Equals(toChange.Value), "Value did not change");
             xElem.Verify();
             eHelper.Verify(XObjectChange.Value, toChange);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #5
0
 public void ExecuteXElementVariation(XElement toChange, object newValue)
 {
     int count = toChange.Nodes().Count();
     XElement xElemOriginal = new XElement(toChange);
     using (UndoManager undo = new UndoManager(toChange))
     {
         undo.Group();
         using (EventsHelper eHelper = new EventsHelper(toChange))
         {
             toChange.SetValue(newValue);
             Assert.True(newValue.Equals(toChange.Value), "Value change was not correct");
             toChange.Verify();
             eHelper.Verify(count + 1);
         }
         undo.Undo();
         Assert.True(toChange.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(toChange.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #6
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!");
     }
 }
Example #7
0
 public void ExecuteXAttributeVariation()
 {
     XAttribute[] content = Variation.Params[0] as XAttribute[];
     int index = (int)Variation.Params[1];
     XElement xElem = new XElement("root", content);
     XAttribute toRemove = xElem.Attributes().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!");
     }
 }
Example #8
0
 public void ExecuteAddVariation()
 {
     XObject content = Variation.Params[0] as XObject;
     XElement toAdd = Variation.Params[1] 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(toAdd.Name, toAdd.Value);
             xElem.Verify();
             eHelper.Verify(XObjectChange.Add, xElem.Element(toAdd.Name));
         }
         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!");
     }
 }
Example #9
0
 public void ExecuteXAttributeVariation(XAttribute[] content)
 {
     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"));
             Assert.True(XObject.ReferenceEquals(xElem.FirstAttribute, xElem.LastAttribute), "Did not replace attributes correctly");
             xElem.Verify();
             eHelper.Verify(content.Length + 1);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #10
0
 public void ExecuteXElementVariation(XNode toReplace)
 {
     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);
             Assert.True(xElem.Nodes().Count() == 1, "Did not replace correctly");
             Assert.True(Object.ReferenceEquals(xElem.FirstNode, newValue), "Did not replace correctly");
             Assert.True(xElem.HasAttributes, "ReplaceNodes removed attributes");
             xElem.Verify();
             eHelper.Verify(new XObjectChange[] { XObjectChange.Remove, XObjectChange.Add }, new XObject[] { toReplace, newValue });
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
        //[Variation(Priority = 0, Desc = "XElement - copy: connected, in XDocument", Params = new object[] { true, true })]
        //[Variation(Priority = 0, Desc = "XElement - copy: connected, not in XDocument", Params = new object[] { true, false })]
        //[Variation(Priority = 0, Desc = "XElement - copy: not connected, in XDocument", Params = new object[] { false, true })]
        //[Variation(Priority = 0, Desc = "XElement - copy: not connected, not in XDocument", Params = new object[] { false, false })]
        public void CreateXElement8()
        {
            var isConnected = (bool)Variation.Params[0];
            var isInDocument = (bool)Variation.Params[1];

            XNamespace ns1 = XNamespace.Get("http://myNS");
            XName xname = ns1 + "elem1";
            var elem1 = new XElement(xname, "text", new XElement("inner"), new XAttribute("id", "a1"));

            if (isConnected)
            {
                var parent = new XElement("parent", elem1);
                if (isInDocument)
                {
                    var doc = new XDocument(parent);
                }
            }
            else
            {
                if (isInDocument)
                {
                    var doc = new XDocument(elem1);
                }
            }

            var elem = new XElement(elem1);

            TestLog.Compare(elem1 != null, "elem1!=null");
            TestLog.Compare(elem1 != elem, "(object)elem1!=(object)elem");
            TestLog.Compare(XNode.DeepEquals(elem1, elem), "XNode.DeepEquals(elem1,elem)");
            TestLog.Compare(elem.Document == null, "elem.Document");
            elem.Verify();

            // compare attributes           
            TestLog.Compare(elem.Attribute("id") != null, "attributes null");
            TestLog.Compare(elem.Attribute("id") != elem1.Attribute("id"), "attribute ==");
            TestLog.Compare(elem.Attribute("id").Value.Equals(elem1.Attribute("id").Value), "attribute Equals");

            // compare children
            TestLog.Compare(elem.Element("inner") != null, "element null");
            TestLog.Compare(elem.Element("inner") != elem1.Element("inner"), "element ==");
            TestLog.Compare(XNode.DeepEquals(elem.Element("inner"), elem1.Element("inner")), "element Equals");

            TestLog.Compare(elem.NodeType, XmlNodeType.Element, "NodeType");
            TestLog.Compare(elem.Parent == null, "Parent");
            TestLog.Compare(elem.Value, elem1.Value, "Value");

            TestLog.Compare(elem1.Name, elem.Name, "Name");
            TestLog.Compare(elem1.Name.LocalName, elem.Name.LocalName, "LocalName");
            TestLog.Compare(elem1.Name.Namespace, elem.Name.Namespace, "Namespace");
        }
        //[Variation(Priority = 0, Desc = "XElement - copy empty")]
        public void CreateXElement7()
        {
            XNamespace ns1 = XNamespace.Get("http://myNS");
            XName xname = ns1 + "elem1";
            var elem = new XElement(xname);
            var elem1 = new XElement(elem);

            TestLog.Compare(elem1 != null, "elem1!=null");
            TestLog.Compare(elem1 != elem, "(object)elem1!=(object)elem");
            TestLog.Compare(XNode.DeepEquals(elem1, elem), "XNode.DeepEquals(elem1,elem)");
            TestLog.Compare(elem1.Document == null, "elem1.Document");
            TestLog.Compare(!elem1.HasAttributes, "HasAttributes");
            TestLog.Compare(!elem1.HasElements, "HasElements");
            TestLog.Compare(elem1.IsEmpty, "IsEmpty");
            TestLog.Compare(elem1.FirstNode == null, "query for content");
            TestLog.Compare(elem1.NodeType, XmlNodeType.Element, "NodeType");
            TestLog.Compare(elem1.Parent == null, "Parent");
            TestLog.Compare(elem1.Value, "", "Value");
            TestLog.Compare(elem1.Name, xname, "Name");
            TestLog.Compare(elem1.Name.LocalName, "elem1", "LocalName");
            TestLog.Compare(elem1.Name.Namespace, ns1, "Namespace");
            elem1.Verify();
        }
 //[Variation(Priority = 2, Desc = "Empty XElement - string - noNS")]
 public void CreateXElement5()
 {
     XName xname = "elem1";
     XNamespace ns = XNamespace.Get("");
     var elem = new XElement("elem1");
     TestLog.Compare(elem.Document == null, "elem.Document");
     TestLog.Compare(!elem.HasAttributes, "HasAttributes");
     TestLog.Compare(!elem.HasElements, "HasElements");
     TestLog.Compare(elem.IsEmpty, "IsEmpty");
     TestLog.Compare(elem.FirstNode == null, "query for content");
     TestLog.Compare(elem.NodeType, XmlNodeType.Element, "NodeType");
     TestLog.Compare(elem.Parent == null, "Parent");
     TestLog.Compare(elem.Value, "", "Value");
     TestLog.Compare(elem.Name, xname, "Name");
     TestLog.Compare(elem.Name.LocalName, "elem1", "LocalName");
     TestLog.Compare(elem.Name.Namespace, ns, "namespace");
     elem.Verify();
 }
Example #14
0
 public void ExecuteXElementVariation(XNode[] content)
 {
     XElement xElem = new XElement("root", InputSpace.GetAttributeElement(10, 1000).Elements().Attributes(), content);
     XElement xElemOriginal = new XElement(xElem);
     using (UndoManager undo = new UndoManager(xElem))
     {
         undo.Group();
         using (EventsHelper elemHelper = new EventsHelper(xElem))
         {
             xElem.RemoveNodes();
             Assert.True(xElem.IsEmpty, "Not all content were removed");
             Assert.True(xElem.HasAttributes, "RemoveNodes removed the attributes");
             xElem.Verify();
             elemHelper.Verify(XObjectChange.Remove, content);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #15
0
 public void ExecuteRemoveVariation(XElement content)
 {
     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();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #16
0
 public void ExecuteXElementVariation(XObject[] toReplace)
 {
     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);
             Assert.True(xElem.Nodes().Count() == 1, "Did not replace correctly");
             Assert.True(Object.ReferenceEquals(xElem.FirstNode, newValue), "Did not replace correctly");
             Assert.True(!xElem.HasAttributes, "ReplaceAll did not remove attributes");
             xElem.Verify();
             eHelper.Verify(toReplace.Length + 1);
         }
         undo.Undo();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #17
0
 public void ExecuteValueVariation(XElement content, object newValue)
 {
     int count = content.Nodes().Count();
     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();
         Assert.True(xElem.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
         Assert.True(xElem.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
     }
 }
Example #18
0
        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();
                Assert.True(toReplace.Nodes().SequenceEqual(xElemOriginal.Nodes(), XNode.EqualityComparer), "Undo did not work!");
                Assert.True(toReplace.Attributes().EqualsAllAttributes(xElemOriginal.Attributes(), Helpers.MyAttributeComparer), "Undo did not work!");
            }
        }
Example #19
0
 public void XProcessingInstructionChangeValue()
 {
     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;
                 Assert.True(toChange.Data.Equals(newValue), "Value did not change");
                 xElem.Verify();
                 piHelper.Verify(XObjectChange.Value, toChange);
             }
             eHelper.Verify(XObjectChange.Value, toChange);
         }
         undo.Undo();
         Assert.True(XNode.DeepEquals(xElem, xElemOriginal), "Undo did not work!");
     }
 }
Example #20
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))
         {
             toChange.SetValue(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!");
     }
 }