Esempio n. 1
0
                /// <summary>
                /// Tests the ContentAfterSelf method on Node.
                /// </summary>
                /// <param name="context"></param>
                /// <returns></returns>
                //[Variation(Desc = "NodeContentAfterSelf")]
                public void NodeContentAfterSelf()
                {
                    XElement parent = new XElement("parent");

                    XComment child = new XComment("Self is a comment");

                    XComment   comment1  = new XComment("Another comment");
                    XComment   comment2  = new XComment("Yet another comment");
                    XElement   element1  = new XElement("childelement", new XElement("nested"), new XAttribute("foo", "bar"));
                    XElement   element2  = new XElement("childelement2", new XElement("nested"), new XAttribute("foo", "bar"));
                    XAttribute attribute = new XAttribute("attribute", "value");

                    // If no parent, should not be any content after it.
                    Validate.Enumerator(child.NodesAfterSelf(), new XNode[0]);

                    // Add some content, including the child, and validate.
                    parent.Add(attribute);
                    parent.Add(comment1);
                    parent.Add(element1);

                    parent.Add(child);

                    parent.Add(comment2);
                    parent.Add(element2);

                    Validate.Enumerator(child.NodesAfterSelf(), new XNode[] { comment2, element2 });
                }
Esempio n. 2
0
                /// <summary>
                /// Tests the ElementsAfterSelf methods on Node.
                /// </summary>
                /// <param name="context"></param>
                /// <returns></returns>
                //[Variation(Desc = "NodeElementsAfterSelf")]
                public void NodeElementsAfterSelf()
                {
                    XElement parent = new XElement("parent");

                    XElement child1a = new XElement("child1", new XElement("nested"));
                    XElement child1b = new XElement("child1", new XElement("nested"));
                    XElement child2a = new XElement("child2", new XElement("nested"));
                    XElement child2b = new XElement("child2", new XElement("nested"));

                    XComment comment = new XComment("this is a comment");

                    // If no parent, should not be any elements before it.
                    Validate.Enumerator(comment.ElementsAfterSelf(), new XElement[0]);

                    parent.Add(child1a);
                    parent.Add(comment);
                    parent.Add(child1b);
                    parent.Add(child2a);
                    parent.Add(child2b);

                    Validate.Enumerator(
                        comment.ElementsAfterSelf(),
                        new XElement[] { child1b, child2a, child2b });

                    Validate.Enumerator(
                        comment.ElementsAfterSelf("child1"),
                        new XElement[] { child1b });

                    Validate.Enumerator(
                        child1a.ElementsAfterSelf("child1"),
                        new XElement[] { child1b });

                    Validate.Enumerator(child2b.ElementsAfterSelf(), new XElement[0]);
                }
Esempio n. 3
0
                /// <summary>
                /// Tests the AllContentAfterSelf method on Node.
                /// </summary>
                /// <param name="context"></param>
                /// <returns></returns>
                //[Variation(Desc = "NodeAllContentAfterSelf")]
                public void NodeAllContentAfterSelf()
                {
                    XElement parent = new XElement("parent");

                    XComment child = new XComment("Self is a comment");

                    XComment   comment1  = new XComment("Another comment");
                    XComment   comment2  = new XComment("Yet another comment");
                    XElement   element1  = new XElement("childelement", new XElement("nested"), new XAttribute("foo", "bar"));
                    XElement   element2  = new XElement("childelement2", new XElement("nested"), new XAttribute("foo", "bar"));
                    XAttribute attribute = new XAttribute("attribute", "value");

                    // If no parent, should not be any content after it.
                    Validate.Enumerator <XNode>(child.NodesAfterSelf(), new XNode[0]);

                    // Add child to parent. Should still be no content after it.
                    // Attributes are not content.
                    parent.Add(child);
                    parent.Add(attribute);
                    Validate.Enumerator <XNode>(child.NodesAfterSelf(), new XNode[0]);

                    // Add more children and validate.
                    parent.AddFirst(comment1);
                    parent.AddFirst(element1);

                    Validate.Enumerator <XNode>(child.NodesAfterSelf(), new XNode[0]);

                    parent.Add(element2);
                    parent.Add(comment2);

                    Validate.Enumerator <XNode>(child.NodesAfterSelf(), new XNode[] { element2, comment2 });
                }
Esempio n. 4
0
                /// <summary>
                /// Validate behavior of the default XDocument constructor.
                /// </summary>
                /// <returns>true if pass, false if fail</returns>
                //[Variation(Desc = "CreateEmptyDocument")]
                public void CreateEmptyDocument()
                {
                    XDocument doc = new XDocument();

                    Validate.IsNull(doc.Parent);
                    Validate.IsNull(doc.Root);
                    Validate.IsNull(doc.Declaration);
                    Validate.Enumerator(doc.Nodes(), new XNode[0]);
                }
Esempio n. 5
0
                /// <summary>
                /// Validate behavior of the XDocument constructor that takes content.
                /// </summary>
                /// <returns>true if pass, false if fail</returns>
                //[Variation(Desc = "CreateDocumentWithContent")]
                public void CreateDocumentWithContent()
                {
                    XDeclaration           declaration = new XDeclaration("1.0", "utf-8", "yes");
                    XComment               comment     = new XComment("This is a document");
                    XProcessingInstruction instruction = new XProcessingInstruction("doc-target", "doc-data");
                    XElement               element     = new XElement("RootElement");

                    XDocument doc = new XDocument(declaration, comment, instruction, element);

                    Validate.Enumerator(
                        doc.Nodes(),
                        new XNode[] { comment, instruction, element });
                }
Esempio n. 6
0
                /// <summary>
                /// Validate the behavior of annotations on Container.
                /// </summary>
                /// <param name="contextValue"></param>
                /// <returns></returns>
                //[Variation(Desc = "ContainerAnnotations")]
                public void ContainerAnnotations()
                {
                    XElement element1 = new XElement("e1");
                    XElement element2 = new XElement("e2");

                    // Check argument null exception on add.
                    try
                    {
                        element1.AddAnnotation(null);
                        Validate.ExpectedThrow(typeof(ArgumentNullException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(ArgumentNullException));
                    }

                    // Before adding anything, should not be able to get any annotations.
                    Validate.IsNull(element1.Annotation(typeof(object)));
                    element1.RemoveAnnotations(typeof(object));
                    Validate.IsNull(element1.Annotation(typeof(object)));

                    // First annotation: 2 cases, object[] and other.
                    object obj1 = "hello";

                    element1.AddAnnotation(obj1);
                    Validate.IsNull(element1.Annotation(typeof(byte)));
                    Validate.IsReferenceEqual(element1.Annotation(typeof(string)), obj1);
                    element1.RemoveAnnotations(typeof(string));
                    Validate.IsNull(element1.Annotation(typeof(string)));

                    object[] obj2 = new object[] { 10, 20, 30 };

                    element2.AddAnnotation(obj2);
                    Validate.IsReferenceEqual(element2.Annotation(typeof(object[])), obj2);
                    Validate.Enumerator <object>((object[])element2.Annotation(typeof(object[])), new object[] { 10, 20, 30 });
                    element2.RemoveAnnotations(typeof(object[]));
                    Validate.IsNull(element2.Annotation(typeof(object[])));

                    // Single annotation; add a second one. Check that duplicates are allowed.
                    object obj3 = 10;

                    element1.AddAnnotation(obj3);
                    Validate.IsReferenceEqual(element1.Annotation(typeof(int)), obj3);
                    element1.AddAnnotation(1000);
                    element1.RemoveAnnotations(typeof(int[]));
                    Validate.IsNull(element1.Annotation(typeof(object[])));

                    object obj4 = "world";

                    element1.AddAnnotation(obj4);

                    Validate.IsReferenceEqual(element1.Annotation(typeof(int)), obj3);
                    Validate.IsReferenceEqual(element1.Annotation(typeof(string)), obj4);

                    // Multiple annotations already. Add one on the end.
                    object obj5 = 20L;

                    element1.AddAnnotation(obj5);

                    Validate.IsReferenceEqual(element1.Annotation(typeof(int)), obj3);
                    Validate.IsReferenceEqual(element1.Annotation(typeof(string)), obj4);
                    Validate.IsReferenceEqual(element1.Annotation(typeof(long)), obj5);

                    // Remove one from the middle and then add, which should use the
                    // freed slot.
                    element1.RemoveAnnotations(typeof(string));
                    Validate.IsNull(element1.Annotation(typeof(string)));

                    object obj6 = 30m;

                    element1.AddAnnotation(obj6);

                    Validate.IsReferenceEqual(element1.Annotation(typeof(int)), obj3);
                    Validate.IsReferenceEqual(element1.Annotation(typeof(long)), obj5);
                    Validate.IsReferenceEqual(element1.Annotation(typeof(decimal)), obj6);

                    // Ensure that duplicates are allowed.
                    element1.AddAnnotation(40m);
                    Validate.IsNull(element1.Annotation(typeof(sbyte)));

                    // A couple of additional remove cases.
                    element2.AddAnnotation(obj2);
                    element2.AddAnnotation(obj3);
                    element2.AddAnnotation(obj5);
                    element2.AddAnnotation(obj6);

                    element2.RemoveAnnotations(typeof(float));
                    Validate.IsNull(element2.Annotation(typeof(float)));
                }
Esempio n. 7
0
 /// <summary>
 /// Tests EmptySequence on XAttribute.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 //[Variation(Desc = "AttributeEmptySequence")]
 public void AttributeEmptySequence()
 {
     Validate.Enumerator(XAttribute.EmptySequence, new XAttribute[0]);
     Validate.Enumerator(XAttribute.EmptySequence, new XAttribute[0]);
 }