当前位置: 首页>>代码示例>>C#>>正文


C# XLinq.EventsHelper类代码示例

本文整理汇总了C#中CoreXml.Test.XLinq.EventsHelper的典型用法代码示例。如果您正苦于以下问题:C# EventsHelper类的具体用法?C# EventsHelper怎么用?C# EventsHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EventsHelper类属于CoreXml.Test.XLinq命名空间,在下文中一共展示了EventsHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的CoreXml.Test.XLinq.EventsHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。