本文整理匯總了C#中System.Xml.Linq.XElement.Verify方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.Verify方法的具體用法?C# XElement.Verify怎麽用?C# XElement.Verify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.Verify方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ExecuteXElementVariation
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!");
}
}
示例2: ExecuteXElementVariation
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!");
}
}
示例3: XCommentChangeValue
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!");
}
}
示例4: ExecuteXAttributeVariation
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!");
}
}
示例5: ExecuteXElementVariation
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!");
}
}
示例6: ExecuteXElementVariation
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!");
}
}
示例7: ExecuteXAttributeVariation
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!");
}
}
示例8: ExecuteAddVariation
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!");
}
}
示例9: ExecuteXAttributeVariation
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!");
}
}
示例10: CreateXElement8
//[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");
}
示例11: CreateXElement7
//[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();
}
示例12: CreateXElement5
//[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();
}
示例13: ExecuteRemoveVariation
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!");
}
}
示例14: ExecuteValueVariation
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!");
}
}
示例15: ElementWithAttributes
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!");
}
}