Esempio n. 1
0
                public void AttributeConstructor()
                {
                    string value = "bar";

                    // Name/value constructor.
                    try
                    {
                        XAttribute a = new XAttribute(null, value);
                        Validate.ExpectedThrow(typeof(ArgumentNullException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(ArgumentNullException));
                    }

                    try
                    {
                        XAttribute a = new XAttribute("foo", null);
                        Validate.ExpectedThrow(typeof(ArgumentNullException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(ArgumentNullException));
                    }

                    // Codepaths for special-casing xmlns namespace

                    XName      name = XName.Get("xmlns", string.Empty);
                    XAttribute att1 = new XAttribute(name, value);

                    Validate.AttributeNameAndValue(att1, "xmlns", value);

                    name = XName.Get("xmlns", "namespacename");
                    att1 = new XAttribute(name, value);
                    Validate.AttributeNameAndValue(att1, "{namespacename}xmlns", value);

                    name = XName.Get("foo", string.Empty);
                    att1 = new XAttribute(name, value);
                    Validate.AttributeNameAndValue(att1, "foo", value);

                    name = XName.Get("foo", "namespacename");
                    att1 = new XAttribute(name, value);
                    Validate.AttributeNameAndValue(att1, "{namespacename}foo", value);

                    // Copy constructor.

                    try
                    {
                        XAttribute a = new XAttribute((XAttribute)null);
                        Validate.ExpectedThrow(typeof(ArgumentNullException));
                    }
                    catch (Exception ex)
                    {
                        Validate.Catch(ex, typeof(ArgumentNullException));
                    }

                    XAttribute att2 = new XAttribute(att1);

                    Validate.AttributeNameAndValue(att2, att1.Name.ToString(), att1.Value);
                }
Esempio n. 2
0
                /// <summary>
                /// Validate ReplaceNodes on container.
                /// </summary>
                /// <param name="contextValue"></param>
                /// <returns></returns>
                //[Variation(Desc = "ContainerReplaceNodes")]
                public void ContainerReplaceNodes()
                {
                    XElement element =
                        new XElement("foo",
                                     new XAttribute("att", "bar"),
                                     "abc",
                                     new XElement("nested", new XText("abcd")));

                    // Replace with a node, attribute, string, some other value, and an IEnumerable.
                    // ReplaceNodes does not remove attributes.
                    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("att2", "att-value");
                    string     str       = "this is a string";

                    TimeSpan other1 = new TimeSpan(1, 2, 3);

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

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

                    Validate.Count(element.Attributes(), 2);
                    Validate.AttributeNameAndValue(element.Attribute("att"), "att", "bar");
                    Validate.AttributeNameAndValue(element.Attribute("att2"), "att2", "att-value");
                }