Example #1
0
        //[Variation(Priority = 2, Desc = "Remove standalone attribute - def namespace", Params = new object[] { "xmlns", "value" })]
        //[Variation(Priority = 2, Desc = "Remove standalone attribute - namespace", Params = new object[] { "{http://www.w3.org/2000/xmlns/}p", "value" })]
        //[Variation(Priority = 2, Desc = "Remove standalone attribute I.", Params = new object[] { "{a}aa", "value" })]
        //[Variation(Priority = 2, Desc = "Remove standalone attribute II.", Params = new object[] { "aa", "value" })]
        public void RemoveStandaloneAttribute()
        {
            _runWithEvents = (bool)Params[0];
            var name = (string)Variation.Params[0];
            var value = (string)Variation.Params[1];
            var a = new XAttribute(name, value);

            try
            {
                if (_runWithEvents)
                {
                    _eHelper = new EventsHelper(a);
                }
                a.Remove();
                if (_runWithEvents)
                {
                    _eHelper.Verify(XObjectChange.Remove, a);
                }
                TestLog.Compare(false, "Exception was expected here");
            }
            catch (InvalidOperationException)
            {
                // Expected exception
            }
            a.Verify();
        }
        // 22.	Xml prefix:  Enforce
        //    �	http://www.w3.org/XML/1998/namespace 
        //    �	Must not be bound to any other namespace name.
        //    �	No other prefix may be bound to this namespace name.
        // 23.	Xmlns prefix:  Enforce, but some concern about performance
        //    �	http://www.w3.org/2000/xmlns/ 
        //    �	It must not be declared
        //    �	No other prefix may be bound to this namespace name. 
        //[Variation(Priority = 1, Desc = "XAttribute - xml namespace - prefix redef", Params = new object[] { "xml", "another", true })]
        //[Variation(Priority = 1, Desc = "XAttribute - xml namespace - bound to diff. prefix", Params = new object[] { "p", "http://www.w3.org/XML/1998/namespace", true })]
        //[Variation(Priority = 1, Desc = "XAttribute - xml namespace - redeclared (positive).", Params = new object[] { "xml", "http://www.w3.org/XML/1998/namespace", false })]
        //[Variation(Priority = 1, Desc = "XAttribute - xmlns namespace - bound to diff. prefix", Params = new object[] { "p", "http://www.w3.org/2000/xmlns/", true })]
        public void CreateXAttribute8()
        {
            var prefix = (string)Variation.Params[0];
            var value = (string)Variation.Params[1];
            var shouldFail = (bool)Variation.Params[2];

            try
            {
                var a = new XAttribute(XNamespace.Xmlns + prefix, value);
                TestLog.Compare(!shouldFail, "Should fail");
                a.Verify();
            }
            catch (ArgumentException)
            {
                TestLog.Compare(shouldFail, "NOT EXPECTED EXCEPTION");
            }
        }
        //[Variation(Priority = 1, Desc = "XAttribute - copy - namespace decl - connected", Params = new object[] { true, "p" })]
        //[Variation(Priority = 1, Desc = "XAttribute - copy - namespace decl - not connected", Params = new object[] { false, "p" })]
        public void CreateXAttribute5()
        {
            var isConnected = (bool)Variation.Params[0];
            var prefix = (string)Variation.Params[1];
            XName name = XNamespace.Xmlns + prefix;
            var attr1 = new XAttribute(name, "value");

            if (isConnected)
            {
                var dummmy = new XElement("dummy", attr1);
            }

            var attr = new XAttribute(attr1);
            TestLog.Compare(attr != null, "attr!=null");
            TestLog.Compare(attr1 != attr, "(object)attr1!=(object)attr");
            TestLog.Compare(attr.Value.Equals(attr1.Value), "attr.Value.Equals(attr1.Value)");
            TestLog.Compare(attr.Name, name, "Name");
            TestLog.Compare(attr.Value, "value", "value");
            TestLog.Compare(attr.Parent == null, "Parent");
            TestLog.Compare(attr.IsNamespaceDeclaration, "IsNamespaceDeclaration");
            attr.Verify();
        }
        //[Variation(Priority = 0, Desc = "XAttribute - copy - not namespace decl - connected", Param = true)]
        //[Variation(Priority = 0, Desc = "XAttribute - copy - not namespace decl - not connected", Param = false)]
        public void CreateXAttribute3()
        {
            var isConnected = (bool)Variation.Param;

            XName name = "{ns1}id";
            var attr1 = new XAttribute(name, "value");

            if (isConnected)
            {
                var x = new XElement("parent", attr1);
            }

            var attr = new XAttribute(attr1);

            TestLog.Compare(attr != null, "attr!=null");
            TestLog.Compare(attr1 != attr, "(object)attr1!=(object)attr");
            TestLog.Compare(attr1.Value.Equals(attr.Value), "attr1.Value.Equals(attr.Value)");
            TestLog.Compare(attr.Value.Equals(attr1.Value), "attr.Equals(attr1)");
            TestLog.Compare(attr.Name, name, "Name");
            TestLog.Compare(attr.Value, "value", "value");
            TestLog.Compare(attr.Parent == null, "Parent");
            TestLog.Compare(!attr.IsNamespaceDeclaration, "IsNamespaceDeclaration");
            attr.Verify();
        }
 //[Variation(Priority = 1, Desc = "XAttribute - xname - namespace decl - normal", Param = "p")]
 public void CreateXAttribute2()
 {
     var prefix = (string)Variation.Param;
     XName name = XNamespace.Xmlns + prefix;
     var attr = new XAttribute(name, "value");
     TestLog.Compare(attr != null, "attr!=null");
     TestLog.Compare(attr.Name, name, "Name");
     TestLog.Compare(attr.Value, "value", "value");
     TestLog.Compare(attr.Parent == null, "Parent");
     TestLog.Compare(attr.IsNamespaceDeclaration, "IsNamespaceDeclaration");
     attr.Verify();
 }
        // XDocument constructors
        //[Variation(Priority = 0, Desc = "Empty XDocument")]

        public void CreateXAttribute()
        {
            XName name = "{ns1}id";
            var attr = new XAttribute(name, "value");
            TestLog.Compare(attr != null, "attr!=null");
            TestLog.Compare(attr.Name, name, "Name");
            TestLog.Compare(attr.Value, "value", "value");
            TestLog.Compare(attr.Parent == null, "Parent");
            TestLog.Compare(!attr.IsNamespaceDeclaration, "IsNamespaceDeclaration");
            attr.Verify();
        }