本文整理汇总了C#中CoreXml.Test.XLinq.EventsHelper类的典型用法代码示例。如果您正苦于以下问题:C# EventsHelper类的具体用法?C# EventsHelper怎么用?C# EventsHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventsHelper类属于CoreXml.Test.XLinq命名空间,在下文中一共展示了EventsHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: NodeWithNoParent
public void NodeWithNoParent()
{
_runWithEvents = (bool)Params[0];
XNode[] nodes = { new XElement("a"), new XElement("b", new XAttribute("id", "a0")), new XElement("c", new XAttribute("id", "a0"), new XElement("cc")), new XComment("comm"), new XProcessingInstruction("PI", ""), new XText(""), new XText(" "), new XText("normal"), new XCData("cdata"), new XDocument(), new XDocument(new XDeclaration("1.0", "UTF8", "true"), new XElement("c", new XAttribute("id", "a0"), new XElement("cc"))) };
foreach (XNode n in nodes)
{
try
{
if (_runWithEvents)
{
_eHelper = new EventsHelper(n);
}
n.Remove();
if (_runWithEvents)
{
_eHelper.Verify(XObjectChange.Remove, n);
}
TestLog.Compare(false, "Exception expected [" + n.NodeType + "] " + n);
}
catch (InvalidOperationException)
{
}
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:25,代码来源:XNodeRemove.cs
示例2: SingeNodeAddIntoElement
/// <summary>
/// XElement:
/// - with content, empty
/// - adding valid nodes
/// - adding invalid nodes
/// - adding text, text concatenation, node identity
/// - adding nulls
/// - adding IEnumerable (order)
/// </summary>
public void SingeNodeAddIntoElement()
{
EventsHelper eHelper;
bool runWithEvents;
runWithEvents = (bool)Params[0];
var xml = Variation.Params[0] as string;
var variationLength = (int)Variation.Params[1];
var isConnected = (bool)Variation.Params[2];
string stringOnlyContent = Variation.Params.Length > 3 ? Variation.Params[3] as string : null;
object[] nodes = { new XElement("B"), new XElement(XNamespace.Get("ns1") + "B"), new XElement("B", new XElement("C"), new XAttribute("a", "aa")), new XProcessingInstruction("PI", "data"), new XComment("comment"), "text plain", " ", "", null, new XText("xtext"), new XText(""), new XCData("xcdata") };
if (isConnected)
{
new XElement("dummy", nodes);
} // connect the nodes to force cloning
foreach (var toInsert in nodes.NonRecursiveVariations(variationLength))
{
XElement e = XElement.Parse(xml);
string stringOnlyContentCopy = stringOnlyContent == null ? null : new string(stringOnlyContent.ToCharArray());
List<ExpectedValue> expectedNodes = CalculateExpectedValuesAddFirst(e, toInsert, stringOnlyContentCopy).ProcessNodes().ToList();
if (runWithEvents)
{
eHelper = new EventsHelper(e);
}
e.AddFirst(toInsert);
TestLog.Compare(expectedNodes.EqualAll(e.Nodes(), XNode.EqualityComparer), "AddFirst");
e.RemoveAll();
}
}
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:42,代码来源:AddFirstSingeNodeAddIntoElement.cs
示例3: OnDocument
public void OnDocument()
{
_runWithEvents = (bool)Params[0];
var itemCount = (int)Variation.Params[0];
var addDecl = (bool)Variation.Params[1];
object[] data = { new XDocumentType("root", null, null, null), new XElement("A"), new XElement("B", new XElement("x"), "string", new XAttribute("at", "home")), new XProcessingInstruction("PI1", ""), new XProcessingInstruction("PI2", ""), new XText(" "), new XText(" "), new XText(" "), new XComment("comment1"), new XComment("comment2") };
foreach (var nodes in data.NonRecursiveVariations(itemCount))
{
if (nodes.Count(x => x is XElement) > 1 || nodes.CheckDTDAfterElement())
{
continue; // double root elem check and dtd after elem check
}
int length = (new XDocument(nodes)).Nodes().Count();
for (int i = 0; i < length; i++)
{
XDocument doc = addDecl ? new XDocument(new XDeclaration("1.0", "UTF8", "true"), nodes) : new XDocument(nodes);
XNode o = doc.Nodes().ElementAt(i);
if (_runWithEvents)
{
_eHelper = new EventsHelper(doc);
}
DoRemoveTest(doc, i);
if (_runWithEvents)
{
_eHelper.Verify(XObjectChange.Remove, o);
}
}
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:35,代码来源:XNodeRemove.cs
示例4: OnXElement
//[Variation(Priority = 1, Desc = "Add attribute (empty elem I., no attrs)", Params = new object[] { "<A></A>", "a1", "a1" })]
//[Variation(Priority = 0, Desc = "Add attribute (empty elem II., no attrs)", Params = new object[] { "<A/>", "a1", "a1" })]
//[Variation(Priority = 0, Desc = "Add attribute (empty elem)", Params = new object[] { "<A a='a' b='b'/>", "a1", "a1" })]
//[Variation(Priority = 0, Desc = "Add attribute (empty elem, namespaces)", Params = new object[] { "<A a1='a1' b='b'/>", "{ns}a1", "ns_a1" })]
//[Variation(Priority = 1, Desc = "Add attribute", Params = new object[] { "<A a1='a1' b='b'>text<B/></A>", "{ns}a1", "ns_a1" })]
//[Variation(Priority = 2, Desc = "Add attribute (content text only)", Params = new object[] { "<A a1='a1' b='b'>text</A>", "{ns}a1", "ns_a1" })]
//[Variation(Priority = 0, Desc = "Replace attribute (empty elem, only one attr.)", Params = new object[] { "<A a1='original' />", "a1", "a1" })]
//[Variation(Priority = 0, Desc = "Replace attribute (empty elem, multiple attr., namespaces)", Params = new object[] { "<A p:a1='x' a1='original' xmlns:p='ns'/>", "{ns}a1", "ns_a1" })]
//[Variation(Priority = 1, Desc = "Replace attribute (multiple attr. (first))", Params = new object[] { "<A a1='original' x='x' y='y'>text</A>", "a1", "a1" })]
//[Variation(Priority = 1, Desc = "Replace attribute (multiple attr. (mIddle))", Params = new object[] { "<A x='x' a1='original' y='y'>text</A>", "a1", "a1" })]
//[Variation(Priority = 1, Desc = "Replace attribute (multiple attr. (last))", Params = new object[] { "<A x='x' y='y' a1='original'>text</A>", "a1", "a1" })]
//[Variation(Priority = 0, Desc = "Remove attribute (only attribute)", Params = new object[] { "<A a1='original'></A>", "a1", null })]
//[Variation(Priority = 0, Desc = "Remove attribute (from multiple attribs)", Params = new object[] { "<A y='y' a1='original' x='x'></A>", "a1", null })]
//[Variation(Priority = 1, Desc = "Remove attribute (from multiple attribs, namespace)", Params = new object[] { "<A a1='original' p:a1='o' xmlns:p='A' ></A>", "{A}a1", null })]
//[Variation(Priority = 1, Desc = "Remove attribute (from multiple attribs, content)", Params = new object[] { "<A x='t' a1='original' y='r'>trt</A>", "a1", null })]
//[Variation(Priority = 1, Desc = "Remove attribute (nonexisting)", Params = new object[] { "<A x='t' a1='original' y='r'>trt</A>", "nonex", null })]
public void OnXElement()
{
_runWithEvents = (bool)Params[0];
var xml = Variation.Params[0] as string;
var newName = Variation.Params[1] as string;
var newValue = Variation.Params[2] as string;
XElement e = XElement.Parse(xml);
XAttribute origAttrib = e.Attribute(newName);
IEnumerable<XAttribute> origAttrs = e.Attributes().ToList();
IEnumerable<ExpectedValue> refComparison = getExpectedAttributes(e, newName, newValue, true).ToList();
IEnumerable<ExpectedValue> valueComparison = getExpectedAttributes(e, newName, newValue, false).ToList();
IEnumerable<XNode> nodes = e.Nodes().ToList();
if (_runWithEvents)
{
_eHelper = new EventsHelper(e);
}
e.SetAttributeValue(newName, newValue);
// Not sure how to verify this yet( what possible events and in what order)
if (_runWithEvents)
{
if (newValue == null)
{
if (origAttrib != null)
{
_eHelper.Verify(XObjectChange.Remove);
}
}
else
{
if (origAttrib != null)
{
_eHelper.Verify(XObjectChange.Value);
}
else
{
_eHelper.Verify(XObjectChange.Add);
}
}
}
if (newValue != null)
{
TestLog.Compare(origAttrib == null || ReferenceEquals(origAttrib, e.Attribute(newName)), "origAttrib == null || Object.ReferenceEquals (origAttrib, e.Attribute(newName))");
TestLog.Compare(e.Attribute(newName).Value, newValue, "e.Attribute(newName), newValue");
}
else
{
TestLog.Compare(origAttrib == null || (origAttrib.Parent == null && origAttrib.Document == null), "origAttrib == null || (origAttrib.Parent==null && origAttrib.Document==null)");
TestLog.Compare(e.Attribute(newName), null, "e.Attribute(newName), null");
}
TestLog.Compare(refComparison.EqualAllAttributes(e.Attributes(), Helpers.MyAttributeComparer), "refComparison.EqualAllAttributes(e.Attributes(), Helpers.MyAttributeComparer))");
TestLog.Compare(valueComparison.EqualAllAttributes(e.Attributes(), Helpers.MyAttributeComparer), "valueComparison.EqualAllAttributes(e.Attributes(), Helpers.MyAttributeComparer))");
TestLog.Compare(nodes.SequenceEqual(e.Nodes()), "nodes.EqualAll(e.Nodes())");
e.Verify();
}
开发者ID:noahfalk,项目名称:corefx,代码行数:79,代码来源:XElement_SetAttributeValue.cs
示例5: ValidPIVariation
//[Variation(Priority = 0, Desc = "XProcessingInstruction - Valid Name")]
public void ValidPIVariation()
{
_runWithEvents = (bool)Params[0];
XProcessingInstruction toChange = new XProcessingInstruction("target", "data");
if (_runWithEvents) _eHelper = new EventsHelper(toChange);
toChange.Target = "newTarget";
if (_runWithEvents) _eHelper.Verify(XObjectChange.Name);
TestLog.Compare(toChange.Target.Equals("newTarget"), "Name did not change");
}
开发者ID:noahfalk,项目名称:corefx,代码行数:10,代码来源:XElement_Value.cs
示例6: DocTypeVariation
//[Variation(Priority = 0, Desc = "XDocumentType - Name")]
public void DocTypeVariation()
{
XDocumentType toChange = new XDocumentType("root", "", "", "");
XDocumentType original = new XDocumentType(toChange);
using (EventsHelper eHelper = new EventsHelper(toChange))
{
toChange.Name = "newName";
TestLog.Compare(toChange.Name.Equals("newName"), "Name did not change");
eHelper.Verify(XObjectChange.Name, toChange);
}
}
开发者ID:johnhhm,项目名称:corefx,代码行数:12,代码来源:EventsName.cs
示例7: ValidVariation
//[Variation(Priority = 0, Desc = "XElement - same name", Params = new object[] { "<element>value</element>", "element" })]
//[Variation(Priority = 0, Desc = "XElement - different name", Params = new object[] { "<element>value</element>", "newElement" })]
//[Variation(Priority = 0, Desc = "XElement - name with namespace", Params = new object[] { "<element>value</element>", "{a}newElement" })]
//[Variation(Priority = 0, Desc = "XElement - name with xml namespace", Params = new object[] { "<element>value</element>", "{http://www.w3.org/XML/1998/namespace}newElement" })]
//[Variation(Priority = 0, Desc = "XElement - element with namespace", Params = new object[] { "<p:element xmlns:p='mynamespace'><p:child>value</p:child></p:element>", "{a}newElement" })]
public void ValidVariation()
{
_runWithEvents = (bool)Params[0];
string xml = Variation.Params[0] as string;
XElement toChange = XElement.Parse(xml);
XName newName = Variation.Params[1] as string;
if (_runWithEvents) _eHelper = new EventsHelper(toChange);
toChange.Name = newName;
if (_runWithEvents) _eHelper.Verify(XObjectChange.Name);
TestLog.Compare(newName.Namespace == toChange.Name.Namespace, "Namespace did not change");
TestLog.Compare(newName.LocalName == toChange.Name.LocalName, "LocalName did not change");
}
开发者ID:noahfalk,项目名称:corefx,代码行数:17,代码来源:XElement_Value.cs
示例8: PIVariation
//[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");
}
}
开发者ID:johnhhm,项目名称:corefx,代码行数:18,代码来源:EventsName.cs
示例9: OnXDocument1
/// <summary>
/// On XDocument
/// ~ Empty
/// ~ Not empty
/// With XDecl
/// With DTD
/// Just root elem
/// Root elem + PI + whitespace + comment
/// </summary>
public void OnXDocument1()
{
int count = 0;
_runWithEvents = (bool)Params[0];
var xml = Variation.Param as string;
XDocument e = xml == "" ? new XDocument() : XDocument.Parse(xml);
if (_runWithEvents)
{
_eHelper = new EventsHelper(e);
count = e.Nodes().Count();
}
VerifyRemoveNodes(e);
if (_runWithEvents)
{
_eHelper.Verify(XObjectChange.Remove, count);
}
}
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:26,代码来源:XContainerRemoveNodesOnXDocument.cs
示例10: OnXElement1
/// <summary>
/// On XElement
/// ~ With and Without attributes
/// ~ Empty
/// ~ Not Empty
/// text node only
/// mixed content
/// children but not mixed content
/// </summary>
public void OnXElement1()
{
int count = 0;
_runWithEvents = (bool)Params[0];
var xml = Variation.Param as string;
XElement e = XElement.Parse(xml);
if (_runWithEvents)
{
_eHelper = new EventsHelper(e);
count = e.Nodes().Count();
}
VerifyRemoveNodes(e);
if (_runWithEvents && !xml.Equals(@"<A></A>"))
{
_eHelper.Verify(XObjectChange.Remove, count);
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:26,代码来源:XContainerRemoveNodesOnXElement.cs
示例11: AddingMultipleNodesIntoElement
public void AddingMultipleNodesIntoElement(TestedFunction testedFunction, CalculateExpectedValues calculateExpectedValues)
{
runWithEvents = (bool)Params[0];
var isConnected = (bool)Variation.Params[0];
var lengthOfVariations = (int)Variation.Params[1];
object[] toAdd = { new XElement("ToAddEmpty"), new XElement("ToAddWithAttr", new XAttribute("id", "a1")), new XElement("ToAddWithContent", new XAttribute("id", "a1"), new XElement("inner", "innerContent"), "content"), new XProcessingInstruction("PiWithData", "data"), "", new XProcessingInstruction("PiNOData", ""), new XComment("comment"), new XCData("xtextCdata"), new XText("xtext"), "plaintext1", "plaintext2", null };
if (isConnected)
{
var dummy = new XElement("dummy", toAdd);
}
var referenceElement = new XElement("testElement", "text0", new XElement("tin"), new XElement("tin2", new XAttribute("id", "a2")), //
"text1", new XAttribute("hu", "ha"), new XProcessingInstruction("PI", "data"), new XText("heleho"), new XComment("M&M"), "textEnd");
for (int startPos = 0; startPos < referenceElement.Nodes().Count(); startPos++)
{
// iterate over all nodes in the original element
foreach (var newNodes in toAdd.NonRecursiveVariations(lengthOfVariations))
{
var orig = new XElement(referenceElement);
IEnumerable<ExpectedValue> expectedNodes = Helpers.ProcessNodes(calculateExpectedValues(orig, startPos, newNodes)).ToList();
// Add node on the expected place
XNode n = orig.FirstNode;
for (int position = 0; position < startPos; position++)
{
n = n.NextNode;
}
if (runWithEvents)
{
eHelper = new EventsHelper(orig);
}
testedFunction(n, newNodes);
// Node Equals check
TestLog.Compare(expectedNodes.EqualAll(orig.Nodes(), XNode.EqualityComparer), "constructed != added :: nodes Deep equals");
// release nodes
orig.RemoveAll();
}
}
}
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:46,代码来源:AddNodeBeforeAfterBase.cs
示例12: InValidVariation
//[Variation(Priority = 0, Desc = "XElement - space character name", Params = new object[] { "<element>value</element>", " " })]
//[Variation(Priority = 0, Desc = "XElement - empty string name", Params = new object[] { "<element>value</element>", "" })]
//[Variation(Priority = 0, Desc = "XElement - null name", Params = new object[] { "<element>value</element>", null })]
public void InValidVariation()
{
_runWithEvents = (bool)Params[0];
string xml = Variation.Params[0] as string;
XElement toChange = XElement.Parse(xml);
try
{
if (_runWithEvents) _eHelper = new EventsHelper(toChange);
toChange.Name = Variation.Params[1] as string;
}
catch (Exception)
{
if (_runWithEvents) _eHelper.Verify(0);
return;
}
throw new TestException(TestResult.Failed, "");
}
开发者ID:noahfalk,项目名称:corefx,代码行数:20,代码来源:XElement_Value.cs
示例13: OnXElement2
public void OnXElement2()
{
int count = 0;
_runWithEvents = (bool)Params[0];
var e = new XElement("A", new XText(""));
TestLog.Compare(e.Nodes().Any(), "Test failed:: e.Nodes().Any()");
if (_runWithEvents)
{
_eHelper = new EventsHelper(e);
count = e.Nodes().Count();
}
VerifyRemoveNodes(e);
if (_runWithEvents)
{
_eHelper.Verify(XObjectChange.Remove, count);
}
}
开发者ID:noahfalk,项目名称:corefx,代码行数:17,代码来源:XContainerRemoveNodesOnXElement.cs
示例14: ExecuteXDocumentVariation
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!");
}
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:18,代码来源:EventsReplace.cs
示例15: ExecuteXDocumentVariation
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!");
}
}
开发者ID:johnhhm,项目名称:corefx,代码行数:19,代码来源:EventsRemove.cs
示例16: ExecuteXElementVariation
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");
}
}
开发者ID:johnhhm,项目名称:corefx,代码行数:19,代码来源:EventsName.cs
示例17: RemoveAttribute
// Remove standalone attribute
// Remove the only attribute
// Remove from multiple attributes - first, middle, last
// Remove namespace decl {http://www.w3.org/2000/xmlns/}
//[Variation(Priority = 1, Desc = "The only attribute, in Document", Params = new object[] { @"<A attr='1'/>", "attr", true })]
//[Variation(Priority = 2, Desc = "The only attribute", Params = new object[] { @"<A attr='1'/>", "attr", false })]
//[Variation(Priority = 0, Desc = "First attribute, in Document", Params = new object[] { @"<A attr='1' a2='a2' a3='a3'/>", "attr", true })]
//[Variation(Priority = 2, Desc = "First attribute", Params = new object[] { @"<A attr='1' a2='a2' a3='a3'/>", "attr", false })]
//[Variation(Priority = 0, Desc = "MIddle attribute, in Document", Params = new object[] { @"<A attr='1' a2='a2' a3='a3' xmlns:p='ns' p:a3='pa3'/>", "a2", true })]
//[Variation(Priority = 2, Desc = "MIddle attribute", Params = new object[] { @"<A attr='1' a2='a2' a3='a3' xmlns:p='ns' p:a3='pa3'/>", "a2", false })]
//[Variation(Priority = 1, Desc = "Last attribute, in Document", Params = new object[] { @"<A attr='1' a2='a2' a3='a3' xmlns:p='ns' p:a3='pa3'/>", "{ns}a3", true })]
//[Variation(Priority = 2, Desc = "Last attribute", Params = new object[] { @"<A attr='1' a2='a2' a3='a3' xmlns:p='ns' p:a3='pa3'/>", "{ns}a3", false })]
//[Variation(Priority = 1, Desc = "Remove namespace, in Document", Params = new object[] { @"<A attr='1' a2='a2' a3='a3' xmlns:p='ns' p:a3='pa3'/>", "{http://www.w3.org/2000/xmlns/}p", true })]
//[Variation(Priority = 2, Desc = "Remove namespace", Params = new object[] { @"<A attr='1' a2='a2' a3='a3' xmlns:p='ns' p:a3='pa3'/>", "{http://www.w3.org/2000/xmlns/}p", false })]
//[Variation(Priority = 1, Desc = "Remove default namespace, in Document", Params = new object[] { @"<A attr='1' a2='a2' a3='a3' xmlns='def' xmlns:p='ns' p:a3='pa3'/>", "xmlns", true })]
//[Variation(Priority = 2, Desc = "Remove default namespace", Params = new object[] { @"<A attr='1' a2='a2' a3='a3' xmlns:p='ns' xmlns='def' p:a3='pa3'/>", "xmlns", false })]
public void RemoveAttribute()
{
_runWithEvents = (bool)Params[0];
var xml = (string)Variation.Params[0];
var attrName = (string)Variation.Params[1];
var useDoc = (bool)Variation.Params[2];
XElement elem = useDoc ? XDocument.Parse(xml).Root : XElement.Parse(xml);
XAttribute a = elem.Attribute(attrName);
a.Verify();
List<ExpectedValue> expValues = GetExpectedResults(elem, a).ToList();
if (_runWithEvents)
{
_eHelper = new EventsHelper(elem);
}
a.Remove();
if (_runWithEvents)
{
_eHelper.Verify(XObjectChange.Remove, a);
}
a.Verify();
TestLog.Compare(a.Parent, null, "Parent after");
TestLog.Compare(a.NextAttribute, null, "NextAttribute after");
TestLog.Compare(a.PreviousAttribute, null, "PrevAttribute after");
try
{
a.Remove();
TestLog.Compare(false, "Exception was expected here");
}
catch (InvalidOperationException)
{
// Expected exception
}
TestLog.Compare(expValues.EqualAllAttributes(elem.Attributes(), Helpers.MyAttributeComparer), "The rest of the attributes");
elem.Verify();
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:59,代码来源:XAttributeRemove.cs
示例18: ExecuteXElementVariation
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!");
}
}
开发者ID:nnyamhon,项目名称:corefx,代码行数:20,代码来源:EventsReplace.cs
示例19: DeleteAttributes
// no attributes
// single attribute/namespace
// multiple attributes/namespaces
// default attributes ... @"<!DOCTYPE square [<!ELEMENT square EMPTY><!ATTLIST square width CDATA "10">]><square/>"
//[Variation(Priority = 1, Desc = "No attributes")]
//[Variation(Priority = 2, Desc = "Default attribute from DTD", Params = new object[] { @"<!DOCTYPE square [<!ELEMENT square (B*)><!ATTLIST square wIdth CDATA '10'>]><square>text<B/><!--commnet--></square>", new string[] { "wIdth" } })]
//[Variation(Priority = 2, Desc = "Single attribute", Params = new object[] { @"<square wIdth='1'>text<B/><!--commnet--></square>", new string[] { "wIdth" } })]
//[Variation(Priority = 2, Desc = "Single namespace (default)", Params = new object[] { @"<square xmlns='x'>text<B/><!--commnet--></square>", new string[] { "xmlns" } })]
//[Variation(Priority = 2, Desc = "Single namespace", Params = new object[] { @"<p:square xmlns:p='x'>text<B/><!--commnet--></p:square>", new string[] { "{http://www.w3.org/2000/xmlns/}p" } })]
//[Variation(Priority = 2, Desc = "Multiple attributes", Params = new object[] { @"<square wIdth='1' depth='11'><sub1/>text</square>", new string[] { "wIdth", "depth" } })]
//[Variation(Priority = 2, Desc = "Multiple namespaces", Params = new object[] { @"<p:square xmlns:p='x' xmlns='x1'><p:A/><B/></p:square>", new string[] { "{http://www.w3.org/2000/xmlns/}p", "{http://www.w3.org/2000/xmlns/}p" } })]
//[Variation(Priority = 2, Desc = "Multiple namespaces + attributes", Params = new object[] { @"<p:square xmlns:p='x' xmlns='x1' a1='xxx' p:a1='yyy'><p:A/><B p:x='ayay'/></p:square>", new string[] { "{http://www.w3.org/2000/xmlns/}p", "{http://www.w3.org/2000/xmlns/}p", "a1", "{x}a1" } })]
public void DeleteAttributes()
{
int count = 0;
_runWithEvents = (bool)Params[0];
var xml = Variation.Params[0] as string;
var attNames = Variation.Params[1] as string[];
XDocument doc = XDocument.Parse(xml);
TestLog.Compare(doc.Root.HasAttributes, "HasAttributes");
TestLog.Compare(doc.Root.Attributes().Count(), attNames.Count(), "default attribute - Attributes()");
foreach (string name in attNames)
{
TestLog.Compare(doc.Root.Attribute(name) != null, "Attribute (XName) before");
}
IEnumerable<XNode> origNodes = doc.Root.Nodes().ToList();
IEnumerable<XAttribute> origAttributes = doc.Root.Attributes().ToList();
if (_runWithEvents)
{
_eHelper = new EventsHelper(doc.Root);
count = origAttributes.IsEmpty() ? 0 : origAttributes.Count();
}
doc.Root.RemoveAttributes();
if (_runWithEvents)
{
_eHelper.Verify(XObjectChange.Remove, count);
}
TestLog.Compare(!doc.Root.HasAttributes, "default attribute not deleted");
TestLog.Compare(doc.Root.Attributes().IsEmpty(), "default attribute - Attributes()");
TestLog.Compare(doc.Root.FirstAttribute == null, "FirstAttribute");
TestLog.Compare(doc.Root.LastAttribute == null, "LastAttribute");
TestLog.Compare(doc.Root.Nodes().SequenceEqual(origNodes), "Content");
TestLog.Compare(origAttributes.Where(a => a.Parent != null).IsEmpty(), "Deleted attributes property");
foreach (string name in attNames)
{
TestLog.Compare(doc.Root.Attribute(name) == null, "Attribute (XName) after: " + name);
}
}
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:56,代码来源:RemoveAttributes.cs
示例20: OnXElement
//[Variation(Priority = 0, Desc = "Add Element (empty)", Params = new object[] { "<A/>", "X", "text" })]
//[Variation(Priority = 0, Desc = "Add Element (text only)", Params = new object[] { "<A>t1</A>", "X", "text" })]
//[Variation(Priority = 0, Desc = "Add Element (Empty, full)", Params = new object[] { "<A></A>", "X", "text" })]
//[Variation(Priority = 0, Desc = "Add Element (mixed content)", Params = new object[] { "<A><B/>t2<!--comm-->t3</A>", "X", "text" })]
//[Variation(Priority = 0, Desc = "Replace Element (the only child)", Params = new object[] { "<A><X xmlns='' Id='Id'/></A>", "X", "text" })]
//[Variation(Priority = 1, Desc = "Replace Element (mixed content, empty)", Params = new object[] { "<A><X/>tn<X xmlns='a'/></A>", "{a}X", "text" })]
//[Variation(Priority = 0, Desc = "Replace Element (mixed content)", Params = new object[] { "<A><X/>tn<X xmlns='a'><Y/>hum<?PI?></X></A>", "{a}X", "text" })]
//[Variation(Priority = 1, Desc = "Delete Element (only element, empty)", Params = new object[] { "<A><X xmlns='a'>tralala</X></A>", "{a}X", null })]
//[Variation(Priority = 0, Desc = "Delete Element (only element)", Params = new object[] { "<A><X xmlns='a'>tralala</X></A>", "{a}X", null })]
//[Variation(Priority = 0, Desc = "Delete Element (mixed content, empty)", Params = new object[] { "<A>t1<X xmlns='a'/>t2</A>", "{a}X", null })]
//[Variation(Priority = 1, Desc = "Delete Element (mixed content)", Params = new object[] { "<A>t1<X xmlns='a'><m/></X>t2</A>", "{a}X", null })]
//[Variation(Priority = 1, Desc = "Delete Element (non existing)", Params = new object[] { "<A>t1<X xmlns='a'><m/></X>t2</A>", "X", null })]
//[Variation(Priority = 1, Desc = "Delete Element (non existing, text only)", Params = new object[] { "<A>t1</A>", "X", null })]
//[Variation(Priority = 1, Desc = "Delete Element (non existing, text only, full)", Params = new object[] { "<A></A>", "X", null })]
public void OnXElement()
{
_runWithEvents = (bool)Params[0];
var xml = Variation.Params[0] as string;
var newName = Variation.Params[1] as string;
var newValue = Variation.Params[2] as string;
XElement e = XElement.Parse(xml);
XElement changed = e.Element(newName);
IEnumerable<ExpectedValue> nodeIdentityExpValues = getExpectedValues(e, newName, newValue, true).ProcessNodes().ToList();
IEnumerable<ExpectedValue> valueExpectedValues = getExpectedValues(e, newName, newValue, false).ProcessNodes().ToList();
IEnumerable<XAttribute> attr = changed == null ? null : changed.Attributes().ToArray();
if (_runWithEvents)
{
_eHelper = new EventsHelper(e);
}
e.SetElementValue(newName, newValue);
if (newValue == null)
{
TestLog.Compare(changed == null || changed.Parent == null, "delete: changed.Parent == null");
TestLog.Compare(e.Element(newName) == null, "e.Element(newName)==null");
}
else
{
TestLog.Compare(changed == null || ReferenceEquals(changed, e.Element(newName)), "changed==null || Object.ReferenceEquals(changed, e.Element(newName))");
TestLog.Compare(e.Element(newName).Value, newValue, "e.Element(newName).Value, newValue");
TestLog.Compare(!e.Element(newName).HasElements, "!e.Element(newName).HasElements");
TestLog.Compare(attr == null || attr.SequenceEqual(changed.Attrib
|
请发表评论