Пример #1
0
                /// <summary>
                /// Tests the Add methods on Container.
                /// </summary>
                /// <param name="context"></param>
                /// <returns></returns>
                //[Variation(Desc = "ContainerAdd")]
                public void ContainerAdd()
                {
                    XElement element = new XElement("foo");

                    // Adding null does nothing.
                    element.Add(null);
                    Validate.Count(element.Nodes(), 0);

                    // Add node, attrbute, string, some other value, and an IEnumerable.
                    XComment   comment   = new XComment("this is a comment");
                    XComment   comment2  = new XComment("this is a comment 2");
                    XComment   comment3  = new XComment("this is a comment 3");
                    XAttribute attribute = new XAttribute("att", "att-value");
                    string     str       = "this is a string";
                    int        other     = 7;

                    element.Add(comment);
                    element.Add(attribute);
                    element.Add(str);
                    element.Add(other);
                    element.Add(new XComment[] { comment2, comment3 });

                    Validate.EnumeratorDeepEquals(
                        element.Nodes(),
                        new XNode[] { comment, new XText(str + other), comment2, comment3 });

                    Validate.EnumeratorAttributes(element.Attributes(), new XAttribute[] { attribute });

                    element.RemoveAll();
                    Validate.Count(element.Nodes(), 0);

                    // Now test params overload.
                    element.Add(comment, attribute, str, other);

                    Validate.EnumeratorDeepEquals(
                        element.Nodes(),
                        new XNode[] { comment, new XText(str + other) });

                    Validate.EnumeratorAttributes(element.Attributes(), new XAttribute[] { attribute });

                    // Not allowed to add a document as a child.
                    XDocument document = new XDocument();

                    try
                    {
                        element.Add(document);
                        Validate.ExpectedThrow(typeof(ArgumentException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(ArgumentException));
                    }
                }