(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.XML / Test / System.Xml / nist_dom / fundamental / Element / Element.cs
blob517a3a9db31c28ac75236dde120ac458d7ad3c2e
1 //**************************************************************************
2 //
3 //
4 // National Institute Of Standards and Technology
5 // DTS Version 1.0
6 //
7 // Element Interface
8 //
9 // Written by: Carmelo Montanez
10 // Modified by: Mary Brady
12 // Ported to System.Xml by: Mizrahi Rafael rafim@mainsoft.com
13 // Mainsoft Corporation (c) 2003-2004
14 //**************************************************************************
15 using System;
16 using System.Xml;
18 using nist_dom;
19 using NUnit.Framework;
21 namespace nist_dom.fundamental
23 [TestFixture]
24 public class ElementTest : Assertion
26 public static int i = 2;
28 public testResults[] RunTests()
30 testResults[] tests = new testResults[] {core0001E(), core0002E(), core0003E(),core0004E(),
31 core0005E(), core0006E(), core0007E(), core0008E(),
32 core0009E(), core0010E(), core0011E(), core0012E(),
33 core0013E(), core0014E(), core0015E(), core0016E(),
34 core0017E(), core0018E(), core0019E(), core0020E(),
35 core0021E(), core0022E(), core0023E(), core0024E(),
36 core0025E(), core0026E(), core0027E(), core0028E(),
37 core0029E(), core0030E()};
39 return tests;
42 //------------------------ test case core-0001E ------------------------
44 // Testing feature - Elements may have attributes associated with them.
46 // Testing approach - Retrieve the first attribute from the last child of
47 // the first employee and examine its "specified"
48 // attribute. This test is only intended to show
49 // that Elements can actually have attributes.
50 // This test uses the "getNamedItem(name)" method from
51 // the NamedNodeMap interface.
53 // Semantic Requirements: 1
55 //----------------------------------------------------------------------------
57 [Test]
58 public void core0001E()
60 string computedValue = "0";//0
61 string expectedValue = "True";//true
62 System.Xml.XmlNode addressElement = null;
63 System.Xml.XmlAttributeCollection attrList = null;
64 System.Xml.XmlAttribute domesticAttr = null;
66 testResults results = new testResults("Core0001E");
67 try
69 results.description = "Element nodes may have associated attributes.";
71 // Retrieve the "address" element from the first employee.
73 addressElement = util.nodeObject(util.FIRST,util.SIXTH);
75 // Access its "domestic" attribute by creating a list of all attributes
76 // and then retrieving the desired attribute from the list by name.
78 attrList = addressElement.Attributes;//.node.
79 domesticAttr = (System.Xml.XmlAttribute)attrList.GetNamedItem("domestic");
81 // Access its "specified" attribute.
83 computedValue = domesticAttr.Specified.ToString();
85 catch(System.Exception ex)
87 computedValue = "Exception " + ex.Message;
91 // Write out results
93 results.expected = expectedValue;
94 results.actual = computedValue;
96 AssertEquals (results.expected, results.actual);
98 //------------------------ End test case core-0001E --------------------------
100 //------------------------ test case core-0002E ------------------------
102 // Testing feature - The generic Attribute "attributes" (Node interface) may
103 // be used to retrieve the set of all attributes of an
104 // element.
106 // Testing approach - Create a list of all the attributes of the last child of
107 // of the first employee by using the generic "attributes"
108 // attribute from the Node interface. Further the length
109 // of the attribute list is examined. This test makes
110 // use of the "Count" attribute from the NameNodeMap
111 // interface.
113 // Semantic Requirements: 1, 2
115 //----------------------------------------------------------------------------
117 [Test]
118 public void core0002E()
120 string computedValue = "";
121 string expectedValue = "2";
122 System.Xml.XmlNode addressElement = null;
123 System.Xml.XmlAttributeCollection attrList = null;
125 testResults results = new testResults("Core0002E");
128 results.description = "The generic \"attributes\" (from the Node interface) may " +
129 "be used to retrieve the set of all attributes of an element.";
131 // Retrieve the "address" element from the first employee.
133 addressElement = util.nodeObject(util.FIRST,util.SIXTH);
135 // Access its attributes list.
137 attrList = addressElement.Attributes;
139 // Access its "length" attribute.
141 computedValue = attrList.Count.ToString();
143 catch(System.Exception ex)
145 computedValue = "Exception " + ex.Message;
148 // Write out results
150 results.expected = expectedValue;
151 results.actual = computedValue;
153 AssertEquals (results.expected, results.actual);
156 //------------------------ End test case core-0002E --------------------------
158 //-------------------------- test case core-0003E ----------------------------
160 // Testing feature - The "tagName" attribute contains the name of the
161 // element.
163 // Testing approach - Retrieve the third child of the second employee and
164 // examine its "tagName" attribute. It should return a
165 // string containing the name of the element ("position",
166 // in this case).
168 // Semantic Requirements: 3
170 //----------------------------------------------------------------------------
172 [Test]
173 public void core0003E()
175 string computedValue = "";
176 string expectedValue = "position";
177 System.Xml.XmlNode positionElement = null;
179 testResults results = new testResults("Core0003E");
182 results.description = "The \"tagName\" of an Element contains the " +
183 "element's name.";
185 // Access its third child of the second employee.
187 positionElement = util.nodeObject(util.SECOND,util.THIRD);
189 // Access its "tagName" attribute.
191 computedValue = positionElement.Name;//tagName;//.node.
193 catch(System.Exception ex)
195 computedValue = "Exception " + ex.Message;
198 // Write out results
200 results.expected = expectedValue;
201 results.actual = computedValue;
203 AssertEquals (results.expected, results.actual);
206 //------------------------ End test case core-0003E --------------------------
208 //-------------------------- test case core-0004E ----------------------------
210 // Testing feature - The "getAttribute(name)" method returns an attribute value
211 // by name.
213 // Testing approach - Retrieve the the last child of the third employee, then
214 // invoke its "getAttribute(name)" method. It should
215 // return the value of the attribute("No", in this case).
217 // Semantic Requirements: 1, 4
219 //----------------------------------------------------------------------------
221 [Test]
222 public void core0004E()
224 string computedValue = "";
225 string expectedValue = "No";
226 System.Xml.XmlElement addressElement = null;
228 testResults results = new testResults("Core0004E");
231 results.description = "The \"getAttribute(name)\" method of an Element returns " +
232 "the value of an attribute by name.";
234 // Retrieve the targeted data.
236 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
237 computedValue = addressElement.GetAttribute("street");//addressElement.node.GetAttribute("street");
239 catch(System.Exception ex)
241 computedValue = "Exception " + ex.Message;
244 // Write out results
246 results.expected = expectedValue;
247 results.actual = computedValue;
249 AssertEquals (results.expected, results.actual);
252 //------------------------ End test case core-0004E --------------------------
254 //-------------------------- test case core-0005E ----------------------------
256 // Testing feature - The "getAttribute(name)" method returns an empty
257 // string if no value was assigned to an attribute and
258 // no default value was given in the DTD file.
260 // Testing approach - Retrieve the the last child of the last employee, then
261 // invoke its "getAttribute(name)" method, where "name" is an
262 // attribute with no specified or DTD default value. The
263 // "getAttribute(name)" method should return the empty
264 // string. This method makes use of the
265 // "createAttribute(newAttr)" method from the Document
266 // interface.
268 // Semantic Requirements: 1, 4, 5
270 //----------------------------------------------------------------------------
272 [Test]
273 public void core0005E()
275 string computedValue = "";
276 string expectedValue = "";
277 System.Xml.XmlElement addressElement = null;
278 System.Xml.XmlAttribute newAttribute = null;
281 testResults results = new testResults("Core0005E");
284 results.description = "The \"getAttribute(name)\" method of an Element returns " +
285 "the empty string if the attribue does not have a default " +
286 "or specified value.";
288 // Access the sixth child of the last employee.
290 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
291 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);
293 // Invoke its "setAttributeNode(newAttr)" method where
294 // newAttr = "newAttribute". Since no value was specified or given
295 // by default, the value returned by the "getAttribute(name)" method
296 // should be the empty string.
298 addressElement.SetAttributeNode(newAttribute);//.node.
299 computedValue = addressElement.GetAttribute("district");//.node.
301 catch(System.Exception ex)
303 computedValue = "Exception " + ex.Message;
307 // Write out results
309 results.expected = expectedValue;
310 results.actual = computedValue;
312 util.resetData();
314 AssertEquals (results.expected, results.actual);
317 //------------------------ End test case core-0005E --------------------------
319 //-------------------------- test case core-0006E ----------------------------
321 // Testing feature - The "setAttribute(name,value)" method adds a new attribute
322 // to the Element.
324 // Testing approach - Retrieve the last child of the last employee, then
325 // add an attribute to it by invoking its
326 // "setAttribute(name,value)" method. It should create
327 // a "name" attribute with an assigned value equal to
328 // "value".
330 // Semantic Requirements: 1, 4, 6
332 //----------------------------------------------------------------------------
334 [Test]
335 public void core0006E()
337 string computedValue = "";
338 System.Xml.XmlElement addressElement = null;
339 string name = "district";
340 string expectedValue = "dallas";
343 testResults results = new testResults("Core0006E");
346 results.description = "The \"setAttribute(name,value)\" method of an Element " +
347 "creates an new \"name\" attribute whose value is equal to \"value\".";
349 // Access the last child of the last employee.
351 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
353 // Invoke its "setAttribute(name,value)" method and create a new attribute
355 addressElement.SetAttribute(name,expectedValue);//.node.
357 // This Element should now have a new attribute that we can be retrieved
358 // by name.
360 computedValue = addressElement.GetAttribute(name);//.node.
362 catch(System.Exception ex)
364 computedValue = "Exception " + ex.Message;
367 // Write out results
369 results.expected = expectedValue;
370 results.actual = computedValue;
372 util.resetData();
374 AssertEquals (results.expected, results.actual);
377 //------------------------ End test case core-0006E --------------------------
379 //-------------------------- test case core-0007E ----------------------------
381 // Testing feature - The "setAttribute(name,value)" method adds a new attribute
382 // to the Element. If the "name" is already present, then
383 // its value should be changed to the new one of the
384 // "value" parameter.
386 // Testing approach - Retrieve the last child of the fourth employee,
387 // then add an attribute to it by invoking its
388 // "setAttribute(name,value)" method. Since the name
389 // of the used attribute ("street") is already present
390 // in this element, then its value should be
391 // changed to the new one of the "value" parameter.
393 // Semantic Requirements: 1, 4, 7
395 //----------------------------------------------------------------------------
397 [Test]
398 public void core0007E()
400 string computedValue = "";
401 string expectedValue = "Neither";
402 System.Xml.XmlElement addressElement = null;
404 testResults results = new testResults("Core0007E");
407 results.description = "The \"setAttribute(name,value)\" method of an Element " +
408 "where the \"name\" attribute is already present in this Element.";
410 // Access the sixth child of the fourth employee.
412 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);
414 // Invoke its "setAttribute(name,value)" method where name = "street"
415 // and value = "Neither".
417 addressElement.SetAttribute("street","Neither");//.node.
419 // The "street" attribute should now have a value of "Neither"
421 computedValue = addressElement.GetAttribute("street");//.node.
423 catch(System.Exception ex)
425 computedValue = "Exception " + ex.Message;
429 // Write out results
431 results.expected = expectedValue;
432 results.actual = computedValue;
434 util.resetData();
436 AssertEquals (results.expected, results.actual);
439 //------------------------ End test case core-0007E --------------------------
441 //-------------------------- test case core-0008E ----------------------------
443 // Testing feature - The "removeAttribute(name)" removes an attribute
444 // by name. If the removed attribute is known to have a
445 // default value, an attribute immediately appears
446 // containing the default value.
448 // Testing approach - Retrieve the attribute named "street" from the last
449 // child of the fourth employee, then remove the "street"
450 // attribute by invoking its "removeAttribute(name) method.
451 // The "street" attribute has a default value defined in the
452 // DTD file, that value should immediately replace the
453 // old value.
455 // Semantic Requirements: 1, 8
457 //----------------------------------------------------------------------------
459 [Test]
460 public void core0008E()
462 string computedValue = "";
463 string expectedValue = "Yes";
464 System.Xml.XmlElement addressElement = null;
465 string streetAttr = "";
467 testResults results = new testResults("Core0008E");
470 results.description = "The \"removeAttribute(name)\" method of an Element " +
471 "removes the \"name\" attribute and restores any " +
472 "known default values.";
474 // Access the last child of the fourth employee.
476 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FOURTH,util.SIXTH);
478 // Invoke its "removeAttribute(name)" method where name = "street"
480 addressElement.RemoveAttribute("street");//.node.
482 // Now access that attribute.
484 streetAttr = addressElement.GetAttribute("street");//.node.
486 // The "street" attribute should now have a default values
488 computedValue = addressElement.GetAttribute("street");//.node.
490 catch(System.Exception ex)
492 computedValue = "Exception " + ex.Message;
496 // Write out results
498 results.expected = expectedValue;
499 results.actual = computedValue;
501 util.resetData();
503 AssertEquals (results.expected, results.actual);
506 //------------------------ End test case core-0008E --------------------------
508 //-------------------------- test case core-0009E ----------------------------
510 // Testing feature - The "getAttributeNode(name)" retrieves an attribute
511 // node by name.
513 // Testing approach - Retrieve the attribute named "domestic" from the last
514 // child of the first employee. Since the method returns
515 // an Attr object, its name attribute can be examined to
516 // ensure the proper attribute was retrieved.
518 // Semantic Requirements: 1, 9
520 //----------------------------------------------------------------------------
522 [Test]
523 public void core0009E()
525 string computedValue = "";
526 string expectedValue = "domestic";
527 System.Xml.XmlElement addressElement = null;
528 System.Xml.XmlAttribute domesticAttrNode = null;
530 testResults results = new testResults("Core0009E");
533 results.description = "The \"getAttributeNode(name)\" method of an Element " +
534 "returns the \"name\" Attr node.";
536 // Access the last child of the first employee.
538 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
540 // Invoke its "getAttributeNode(name)" method where name = "domestic"
541 // and create an Attr object.
543 domesticAttrNode = addressElement.GetAttributeNode("domestic");//.node.
545 // Now access the "name" attribute of that Attr node. Since the "domestic"
546 // attribute was retrieved, the name of the Attr node should also be
547 // "domestic".
549 computedValue = domesticAttrNode.Name;
551 catch(System.Exception ex)
553 computedValue = "Exception " + ex.Message;
557 // Write out results
559 results.expected = expectedValue;
560 results.actual = computedValue;
562 AssertEquals (results.expected, results.actual);
565 //------------------------ End test case core-0009E --------------------------
567 //-------------------------- test case core-00010E ----------------------------
569 // Testing feature - The "getAttributeNode(name)" retrieves an attribute
570 // node by name. It should return null if the "name"
571 // attribute does not exist.
573 // Testing approach - Retrieve the last child of the first employee and
574 // attempt to retrieve a non-existing attribute.
575 // The method should return null. The non-existing
576 // attribute to be used is "invalidAttribute".
578 // Semantic Requirements: 1, 10
580 //----------------------------------------------------------------------------
582 [Test]
583 public void core0010E()
585 object computedValue = null;
586 object expectedValue = null;
587 System.Xml.XmlElement addressElement = null;
589 testResults results = new testResults("Core0010E");
592 results.description = "The \"getAttributeNode(name)\" method returns null " +
593 "if the \"name\" attribute does not exist.";
595 // Access the last child of the first employee.
597 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
599 // Invoke its "getAttributeNode(name)" method where name = "invalidAttribute"
600 // This should result in a null value being returned by the method.
602 computedValue = addressElement.GetAttributeNode("invalidAttribute");//.node.
604 catch(System.Exception ex)
606 computedValue = "Exception " + ex.Message;
609 // Write out results
611 results.expected = (expectedValue == null).ToString();
612 results.actual = (computedValue == null).ToString();
614 AssertEquals (results.expected, results.actual);
617 //------------------------ End test case core-0010E --------------------------
619 //-------------------------- test case core-0011E ----------------------------
621 // Testing feature - The "setAttributeNode(newAttr)" adds a new attribute
622 // to the Element.
624 // Testing approach - Retrieve the last child of the first employee and
625 // add a new attribute node to it by invoking its
626 // "setAttributeNode(newAttr)" method. This test makes
627 // use of the "createAttribute(name)" method from the
628 // Document interface.
630 // Semantic Requirements: 1, 11
632 //----------------------------------------------------------------------------
634 [Test]
635 public void core0011E()
637 string computedValue = "";
638 string expectedValue = "";
639 System.Xml.XmlElement addressElement = null;
640 System.Xml.XmlAttribute newAttribute = null;
641 string name = "district";
643 testResults results = new testResults("Core0011E");
646 results.description = "The \"setAttributeNode(newAttr)\" method adds a new " +
647 "attribute node to the element.";
649 // Access the last child of the first employee.
651 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,name);
652 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
654 // Invoke its "setAttributeNode(newAttr)" method where
655 // newAttr = "newAttribute". Since no value was specified or given
656 // by default, its value should be the empty string.
658 addressElement.SetAttributeNode(newAttribute);//.node.
659 computedValue = addressElement.GetAttribute(name);//.node.
661 catch(System.Exception ex)
663 computedValue = "Exception " + ex.Message;
666 // Write out results
668 results.expected = expectedValue;
669 results.actual = computedValue;
671 util.resetData();
673 AssertEquals (results.expected, results.actual);
676 //------------------------ End test case core-0011E --------------------------
678 //-------------------------- test case core-00012E ----------------------------
680 // Testing feature - The "setAttributeNode(newAttr)" method adds a new attribute
681 // to the Element. If the "newAttr" Attr node is already
682 // present in this element, it should replace the existing
683 // one.
685 // Testing approach - Retrieve the last child of the third employee and
686 // add a new attribute node to it by invoking its
687 // "setAttributeNode(newAttr)" method. The new attribute
688 // node to be added is "street", which is already
689 // present in this element. The method should replace the
690 // existing Attr node with the new one. This test make use
691 // of the "createAttribute(name)" method from the Document
692 // interface.
694 // Semantic Requirements: 1, 12
696 //----------------------------------------------------------------------------
698 [Test]
699 public void core0012E()
701 string computedValue = "";
702 string expectedValue = "";
703 System.Xml.XmlElement addressElement = null;
704 System.Xml.XmlAttribute newAttribute = null;
706 testResults results = new testResults("Core0012E");
709 results.description = "The \"setAttributeNode(newAttr)\" method when " +
710 "the \"newAttr\" node is already part of this " +
711 "element. The existing attribute node should be "+
712 "replaced with the new one.";
714 // Access the last child of the third employee.
716 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
717 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
719 // Invoke its "setAttributeNode(newAttr)" method where
720 // newAttr = "newAttribute". That attribute is already part of this
721 // element. The existing attribute should be replaced with the new one
722 // (newAttribute).
724 addressElement.SetAttributeNode(newAttribute);//.node.
725 computedValue = addressElement.GetAttribute("street");//.node.
727 catch(System.Exception ex)
729 computedValue = "Exception " + ex.Message;
732 // Write out results
734 results.expected = expectedValue;
735 results.actual = computedValue;
737 util.resetData();
739 AssertEquals (results.expected, results.actual);
742 //------------------------ End test case core-0012E --------------------------
744 //-------------------------- test case core-00013E ----------------------------
746 // Testing feature - If The "setAttributeNode(newAttr)" method replaces
747 // an existing Attr node with the same name, then it
748 // should return the previously existing Attr node.
750 // Testing approach - Retrieve the last child of the third employee and add
751 // a new attribute node to it. The new attribute node to
752 // be added is "street", which is already present in this
753 // Element. The method should return the existing Attr
754 // node(old "street" Attr). This test make use of the
755 // "createAttribute(name)" method from the Document
756 // interface.
758 // Semantic Requirements: 1, 13
760 //----------------------------------------------------------------------------
762 [Test]
763 public void core0013E()
765 string computedValue = "";
766 string expectedValue = "No";
767 System.Xml.XmlElement addressElement = null;
768 System.Xml.XmlAttribute oldStreetAttribute = null;
769 System.Xml.XmlAttribute newAttribute = null;
771 testResults results = new testResults("Core0013E");
774 results.description = "The \"setAttributeNode(newAttr)\" method when the " +
775 "\"newAttr\" attribute node is already present in " +
776 "this element. The method should return the previously " +
777 "existing Attr node.";
779 // Access the last child of the third employee.
781 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
782 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
784 // Invoke its "setAttributeNode(newAttr)" method where
785 // newAttr was just created with the same name as an already existing
786 // attribute("street"). The existing attribute should be replaced with the
787 // new one and the method should return the existing "street" Attr node.
789 oldStreetAttribute = addressElement.SetAttributeNode(newAttribute);//.node.
791 // The "oldStreetAttribute" now contains the old Attr node and its
792 // "value" attribute should be available for examination.
794 computedValue = oldStreetAttribute.Value;
796 catch(System.Exception ex)
798 computedValue = "Exception " + ex.Message;
802 // Write out results
804 results.expected = expectedValue;
805 results.actual = computedValue;
807 util.resetData();
809 AssertEquals (results.expected, results.actual);
812 //------------------------ End test case core-0013E --------------------------
814 //-------------------------- test case core-00014E ----------------------------
816 // Testing feature - The "setAttributeNode(newAttr)" method returns the
817 // null value if no previously existing Attr node with the
818 // same name was replaced.
820 // Testing approach - Retrieve the last child of the third and add a new
821 // attribute node to it. The new attribute node to be
822 // added is "district", which is not part of this Element.
823 // The method should return the null value. This test makes
824 // use of the "createAttribute(name)" method from the
825 // Document interface.
827 // Semantic Requirements: 1, 15
829 //----------------------------------------------------------------------------
831 [Test]
832 public void core0014E()
834 object computedValue = null;
835 object expectedValue = null;
836 System.Xml.XmlElement addressElement = null;
837 System.Xml.XmlAttribute newAttribute = null;
839 testResults results = new testResults("Core0014E");
842 results.description = "The \"setAttributeNode(newAttr)\" method returns a " +
843 "null value if no previously existing Attr node was replaced.";
845 // Access the sixth child of the third employee.
847 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
848 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
850 // Invoke its "setAttributeNode(newAttr)" method where name = "newAttribute".
851 // This attribute is not part of this element. The method should add the
852 // new Attribute and return a null value.
854 computedValue = addressElement.SetAttributeNode(newAttribute);//.node.
856 catch(System.Exception ex)
858 computedValue = "Exception " + ex.Message;
862 // Write out results
864 results.expected = (expectedValue == null).ToString();
865 results.actual = (computedValue == null).ToString();
867 util.resetData();
869 AssertEquals (results.expected, results.actual);
872 //------------------------ End test case core-0014E --------------------------
874 //-------------------------- test case core-00015E ----------------------------
876 // Testing feature - The "removeAttributeNode(oldAttr)" method removes the
877 // specified attribute.
879 // Testing approach - Retrieve the last child of the third employee, add
880 // a new "district" node to it and the try to remove it.
881 // To verify that the node was removed this test uses the
882 // "getNamedItem(name)" from the NamedNodeMap interface.
883 // This test also makes use of the "attributes" attribute
884 // from the Node interface.
886 // Semantic Requirements: 1, 14
888 //----------------------------------------------------------------------------
890 [Test]
891 public void core0015E()
893 object computedValue = null;
894 object expectedValue = null;
895 System.Xml.XmlElement addressElement = null;
896 System.Xml.XmlAttributeCollection attrList = null;
897 System.Xml.XmlAttribute newAttribute = null;
898 newAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
900 testResults results = new testResults("Core0015E");
903 results.description = "The \"removeAttributeNode(oldAttr)\" method removes the " +
904 "specified attribute node.";
906 // Access the sixth child of the third employee and add the new
907 // attribute to it.
909 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
910 addressElement.SetAttributeNode(newAttribute);//.node.
912 // Invoke its "removeAttributeNode(oldAttr)" method where
913 // name = "newAttribute" and remove that attribute node.
915 addressElement.RemoveAttributeNode(newAttribute);//.node.
917 // To ensure that the "district" attribute was indeed removed, a listing
918 // of all attributes is created by invoking the "attributes" attribute
919 // of "addressElement". After the list is created, we attempt to
920 // retrieve the "district" element from the list. A null value should
921 // be return in its place.
923 attrList = addressElement.Attributes;
924 computedValue = attrList.GetNamedItem("district");
926 catch(System.Exception ex)
928 computedValue = "Exception " + ex.Message;
931 // Write out results
933 results.expected = (expectedValue == null).ToString();
934 results.actual = (computedValue == null).ToString();
936 util.resetData();
938 AssertEquals (results.expected, results.actual);
941 //------------------------ End test case core-0015E --------------------------
943 //-------------------------- test case core-00016E ----------------------------
945 // Testing feature - The "removeAttributeNode(oldAttr)" method removes the
946 // specified attribute node and restore any default values.
948 // Testing approach - Retrieve the last child of the third employee and
949 // remove its "street" Attr node. Since this node has
950 // default value defined in the DTD file, that default
951 // value should immediately be the new value.
953 // Semantic Requirements: 1, 15
955 //----------------------------------------------------------------------------
957 [Test]
958 public void core0016E()
960 string computedValue = "";
961 string expectedValue = "Yes";
962 System.Xml.XmlElement addressElement = null;
963 System.Xml.XmlAttribute streetAttr = null;
964 //System.Xml.XmlNode thirdEmployee = null;
966 testResults results = new testResults("Core0016E");
969 results.description = "The \"removeAttributeNode(oldAttr)\" method removes the " +
970 "specified attribute node and restores any default values.";
972 // Access the sixth child of the third employee.
974 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
976 // Create an instance of an Attr object by retrieving the "street"
977 // attribute node, invoke its "removeAttributeNode(oldAttr)" method
978 // where name = "streetAttr" and remove that attribute node. Note that
979 // "the removeAttributeNode(oldAttr)" takes an Attr object as its
980 // parameter, that is why an Attr object (named "street") is first created.
982 streetAttr = addressElement.GetAttributeNode("street");//.node.
983 addressElement.RemoveAttributeNode(streetAttr);//.node.
985 // Since there is a default value defined for the "street" attribute, it
986 // should immediately be the new value for that attribute.
988 computedValue = addressElement.GetAttribute("street");//.node.
990 catch(System.Exception ex)
992 computedValue = "Exception " + ex.Message;
996 // Write out results
998 results.expected = expectedValue;
999 results.actual = computedValue;
1001 util.resetData();
1003 AssertEquals (results.expected, results.actual);
1006 //------------------------ End test case core-0016E --------------------------
1008 //-------------------------- test case core-00017E ----------------------------
1010 // Testing feature - The "removeAttributeNode(oldAttr)" method returns the
1011 // node that was removed.
1013 // Testing approach - Retrieve the last child of the third employee and
1014 // remove its "street" Attr node. The method should
1015 // return the old attribute node.
1017 // Semantic Requirements: 1, 16
1019 //----------------------------------------------------------------------------
1021 [Test]
1022 public void core0017E()
1024 string computedValue = "";
1025 string expectedValue = "No";
1026 System.Xml.XmlElement addressElement = null;
1027 System.Xml.XmlAttribute streetAttr = null;
1028 System.Xml.XmlAttribute oldStreetAttribute = null;
1030 testResults results = new testResults("Core0017E");
1033 results.description = "The \"removeAttributeNode(oldAttr)\" method returns the "+
1034 "removed attribute node.";
1036 // Access the sixth child of the third employee.
1038 addressElement = (System.Xml.XmlElement)util.nodeObject(util.THIRD,util.SIXTH);
1040 // create an instance of an Attr object by retrieving the "street"
1041 // attribute node, invoke its "removeAttributeNode(oldAttr)" method
1042 // where name = "streetAttr" and remove that attribute node. Note that
1043 // "the removeAttributeNode(oldAttr)" takes an Attr object as its
1044 // parameter, that is why an Attr object (named "street") is first created.
1046 streetAttr = addressElement.GetAttributeNode("street");//.node.
1047 oldStreetAttribute = addressElement.RemoveAttributeNode(streetAttr);//.node.
1049 // The method should return the removed attribute node. Its value can then
1050 // be examined.
1052 computedValue = oldStreetAttribute.Value;
1054 catch(System.Exception ex)
1056 computedValue = "Exception " + ex.Message;
1059 // Write out results
1061 results.expected = expectedValue;
1062 results.actual = computedValue;
1064 util.resetData();
1066 AssertEquals (results.expected, results.actual);
1069 //------------------------ End test case core-0017E --------------------------
1071 //-------------------------- test case core-00018E ----------------------------
1073 // Testing feature - The "getElementsByTagName(name)" method returns a list
1074 // of all descendant Elements with the given tag name.
1076 // Testing approach - Get a listing of all the descendant elements of the
1077 // root element using the string "employee" as the tag
1078 // name. The method should return a Node list of length
1079 // equal to 5. This test makes use of the "length"
1080 // attribute from the NodeList interface.
1082 // Semantic Requirements: 1, 17
1084 //----------------------------------------------------------------------------
1086 [Test]
1087 public void core0018E()
1089 int computedValue = 0;
1090 int expectedValue = 5;
1091 System.Xml.XmlNodeList employeeList = null;
1092 System.Xml.XmlElement docElement = null;
1094 testResults results = new testResults("Core0018E");
1096 results.description = "The \"getElementsByTagName(name)\" method returns a "+
1097 "NodeList of all descendant elements with the given " +
1098 "tag name(method returning a non-empty list)";
1100 // get a listing of all the elements that match the tag "employee".
1102 docElement = util.getRootNode();
1103 employeeList = docElement.GetElementsByTagName("employee");
1105 // The method should return a NodeList whose length can then be examined.
1107 computedValue = employeeList.Count;
1109 // Write out results
1111 results.expected = expectedValue.ToString();
1112 results.actual = computedValue.ToString();
1114 AssertEquals (results.expected, results.actual);
1117 //------------------------ End test case core-0018E --------------------------
1119 //-------------------------- test case core-00019E ----------------------------
1121 // Testing feature - The "getElementsByTagName(name)" returns a list of all
1122 // descendant Elements with the given tag name. Test
1123 // for an empty list.
1125 // Testing approach - Get a listing of all the descendant elements of the
1126 // root element using the string "noMatches" as the tag
1127 // name. The method should return a NodeList of length
1128 // equal to 0 since no descendant elements match the given
1129 // tag name. This test makes use of the "length" attribute
1130 // from the NodeList interface.
1132 // Semantic Requirements: 1, 17
1134 //----------------------------------------------------------------------------
1136 [Test]
1137 public void core0019E()
1139 int computedValue = 0;
1140 int expectedValue = 0;
1141 System.Xml.XmlNodeList employeeList = null;
1142 System.Xml.XmlElement docElement = null;
1144 testResults results = new testResults("Core0019E");
1146 results.description = "The \"getElementsByTagName(name)\" method returns a "+
1147 "NodeList of all descendant elements with the given " +
1148 "tag name (method returns an empty list)";
1150 // get a listing of all the elements that match the tag "noMatch".
1152 docElement = util.getRootNode();
1153 employeeList = docElement.GetElementsByTagName("noMatch");
1155 // The method should return a NodeList whose length can then be examined.
1157 computedValue = employeeList.Count;
1159 // Write out results
1161 results.expected = expectedValue.ToString();
1162 results.actual = computedValue.ToString();
1164 AssertEquals (results.expected, results.actual);
1167 //------------------------ End test case core-0019E --------------------------
1169 //-------------------------- test case core-00020E ----------------------------
1171 // Testing feature - The "getElementsByTagName(name)" returns a list of all
1172 // descendant Elements in the order the children were
1173 // encountered in a pre order traversal of the element tree.
1175 // Testing approach - Get a listing of all the descendant elements of the
1176 // root node using the string "employee" as the tag
1177 // name. The method should return a Node list of length
1178 // equal to 5 in the order the children were encountered.
1179 // Item number four in the list is accessed using a
1180 // subscript. Item number four is itself an Element node
1181 // with children and whose first child should be
1182 // "employeeId".
1184 // Semantic Requirements: 1, 18
1186 //----------------------------------------------------------------------------
1188 [Test]
1189 public void core0020E()
1191 string computedValue = "";
1192 string expectedValue = "employeeId";
1193 System.Xml.XmlNodeList employeeList = null;
1194 System.Xml.XmlNode fourthEmployee = null;
1195 System.Xml.XmlElement docElement = null;
1197 testResults results = new testResults("Core0020E");
1199 results.description = "The \"getElementsByTagName(name)\" returns a NodeList " +
1200 "of all descendant elements in the order the " +
1201 "children were encountered in a preorder traversal " +
1202 "of the element tree.";
1204 // get a listing of all the elements that match the tag "employee".
1206 docElement = util.getRootNode();
1207 employeeList = docElement.GetElementsByTagName("employee");
1210 // The method should return a NodeList of the children in the order the
1211 // children were encountered. Since "employeeList" is a NodeList we should
1212 // be able to access its elements by using a subscript. Item number four
1213 // is itself an Element node with six children and the first child
1214 // is "employeeId".
1216 fourthEmployee = employeeList.Item(util.FOURTH);
1217 computedValue = fourthEmployee.FirstChild.Name;
1219 // Write out results
1221 results.expected = expectedValue;
1222 results.actual = computedValue;
1224 AssertEquals (results.expected, results.actual);
1227 //------------------------ End test case core-0020E --------------------------
1229 //-------------------------- test case core-00021E ----------------------------
1231 // Testing feature - The "getElementsByTagName(name)" method may use the
1232 // special value "*" to match all the tags in the element
1233 // tree.
1235 // Testing approach - Get a listing of all the descendant elements of the
1236 // last employee by using the special value of "*". The
1237 // method should return all of the descendant children
1238 // (total of 6) in the order the children were encountered.
1240 // Semantic Requirements: 1, 19
1242 //----------------------------------------------------------------------------
1244 [Test]
1245 public void core0021E()
1247 string computedValue = "";
1248 string expectedValue = "employeeId name position salary gender address ";
1249 System.Xml.XmlNodeList elementList = null;
1250 System.Xml.XmlElement lastEmployee = null;
1252 testResults results = new testResults("Core0021E");
1254 results.description = "The \"getElementsByTagName(name)\" method may use the " +
1255 "special value \"*\" to match all the tags in the " +
1256 "element tree.";
1258 // get a listing of all the descendant elements of the last employee by using
1259 // the special value of "*".
1261 lastEmployee = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,-1);
1262 elementList = lastEmployee.GetElementsByTagName("*");//.node.
1264 // Traverse the list.
1266 for (int index = 0;index <= elementList.Count - 1;index++)
1267 computedValue += elementList.Item(index).Name+" ";
1269 // Write out results
1271 results.expected = expectedValue;
1272 results.actual = computedValue;
1274 AssertEquals (results.expected, results.actual);
1277 //------------------------ End test case core-0021E --------------------------
1279 //-------------------------- test case core-00022E ----------------------------
1281 // Testing feature - The "normalize()" method puts all the nodes in the
1282 // full depth of the sub-tree underneath this element
1283 // into a "normal" form.
1285 // Testing approach - Retrieve the third employee and access its second
1286 // child. This child contains a block of text that spread
1287 // accross multiple lines. The content of the "name"
1288 // child should be parsed and treated as a single Text node.
1290 // Semantic Requirements: 1, 20
1292 //----------------------------------------------------------------------------
1294 [Test]
1295 public void core0022E()
1297 string computedValue = "";
1298 string expectedValue = "Roger\n Jones";
1299 System.Xml.XmlNode idElement = null;
1300 System.Xml.XmlNode textNode = null;
1302 testResults results = new testResults("Core0022E");
1305 results.description = "The \"normalize()\" method puts all the nodes in the " +
1306 "full depth of the sub-tree of this element into a normal form.";
1308 // The "normalize() method should combine all the contiguous blocks of text
1309 // and form a single "Text" node. The "nodeValue" of that final Text node
1310 // should be the combination of all continuos blocks of text that do not
1311 // contain any markup language.
1313 idElement = util.nodeObject(util.THIRD,util.SECOND);
1314 idElement.Normalize();//.node.
1315 textNode = idElement.LastChild;//.node.
1317 // text should be in normal form now
1319 computedValue = textNode.Value;
1321 catch(System.Exception ex)
1323 computedValue = "Exception " + ex.Message;
1327 // Write out results
1329 results.expected = expectedValue;
1330 results.actual = computedValue;
1332 util.resetData();
1334 AssertEquals (results.expected, results.actual);
1337 //------------------------ End test case core-0022E --------------------------
1339 //-------------------------- test case core-00023E ---------------------------
1341 // Testing feature - The "setAttribute(name,value)" method raises an
1342 // INVALID_CHARACTER_ERR Exception if the specified
1343 // name contains an invalid character.
1345 // Testing approach - Retrieve the last child of the first employee
1346 // and call its "setAttribute(name,value)" method with
1347 // "name" containing an invalid character.
1349 // Semantic Requirements: 1, 21
1351 //----------------------------------------------------------------------------
1353 [Test]
1354 public void core0023E()
1356 string computedValue = "";
1357 System.Xml.XmlElement addressElement = null;
1358 string expectedValue = "System.ArgumentException";
1360 testResults results = new testResults("Core0023E");
1363 results.description = "The \"setAttribute(name,value)\" method raises an " +
1364 "ArgumentException if the specified " +
1365 "name contains an invalid character.";
1367 // Access the "address" element of the first employee.
1369 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
1371 // Attempt to set an attribute with an invalid character in its name.
1373 try
1375 addressElement.SetAttribute("invalid^Name","thisValue");//.node.
1377 catch(System.Exception ex)
1379 computedValue = ex.GetType().ToString();
1382 catch(System.Exception ex)
1384 computedValue = "Exception " + ex.Message;
1387 results.expected = expectedValue;
1388 results.actual = computedValue;
1390 util.resetData();
1392 AssertEquals (results.expected, results.actual);
1395 //------------------------ End test case core-0023E --------------------------
1397 //-------------------------- test case core-0024E ----------------------------
1399 // Testing feature - The "setAttribute(name,value)" method raises a
1400 // NO_MODIFICATION_ALLOWED_ERR Exception if this
1401 // node is readonly.
1403 // Testing approach - Retrieve the Element node inside the Entity node
1404 // named "ent4" and attempt to set an attribute for
1405 // it. Descendants of Entity nodes are readonly nodes
1406 // and therefore the desired exception should be raised.
1408 // Semantic Requirements: 22
1410 //----------------------------------------------------------------------------
1412 [Test]
1413 public void core0024E()
1415 string computedValue = "";
1416 System.Xml.XmlEntity entityNode = null;
1417 System.Xml.XmlElement entityDesc = null;
1418 string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
1420 testResults results = new testResults("Core0024E");
1423 results.description = "The \"setAttribute(name,value)\" method raises a " +
1424 "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";
1427 // Retreive the targeted data.
1429 entityNode = util.getEntity("ent4");
1430 entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;
1432 // Attempt to set an attribute for a readonly node should raise an exception.
1434 try
1436 entityDesc.SetAttribute("newAttribute","thisValue");
1438 catch(System.Exception ex)
1440 computedValue = ex.GetType ().FullName;
1443 catch(System.Exception ex)
1445 computedValue = "Exception " + ex.Message;
1447 results.expected = expectedValue;
1448 results.actual = computedValue;
1450 util.resetData();
1452 AssertEquals (results.expected, results.actual);
1455 //------------------------ End test case core-0024E --------------------------
1457 //-------------------------- test case core-00025E ---------------------------
1459 // Testing feature - The "removeAttribute(name)" method raises a
1460 // NO_MODIFICATION_ALLOWED_ERR Exception if this
1461 // node is readonly.
1463 // Testing approach - Retrieve the Element node inside the Entity node
1464 // named "ent4" and attempt to remove an attribute from
1465 // it. Descendants of Entity nodes are readonly nodes
1466 // and therefore the desired exception should be raised.
1468 // Semantic Requirements: 23
1470 //----------------------------------------------------------------------------
1472 [Test]
1473 public void core0025E()
1475 string computedValue = "";
1476 System.Xml.XmlEntity entityNode = null;
1477 System.Xml.XmlElement entityDesc = null;
1478 string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
1480 testResults results = new testResults("Core0025E");
1483 results.description = "The \"removeAttribute(name)\" method raises a " +
1484 "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";
1486 // Retrieve the targeted data.
1488 entityNode = util.getEntity("ent4");
1489 entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;
1491 // Attempt to set an attribute for a readonly node should raise an exception.
1493 try
1495 entityDesc.RemoveAttribute("attr1");
1497 catch(System.Exception ex)
1499 computedValue = ex.GetType ().FullName;
1502 catch(System.Exception ex)
1504 computedValue = "Exception " + ex.Message;
1506 results.expected = expectedValue;
1507 results.actual = computedValue;
1509 util.resetData();
1511 AssertEquals (results.expected, results.actual);
1514 //------------------------ End test case core-0025E --------------------------
1516 //-------------------------- test case core-00026E ---------------------------
1518 // Testing feature - The "setAttributeNode(newAttr)" method raises a
1519 // NO_MODIFICATION_ALLOWED_ERR Exception if this
1520 // node is readonly.
1522 // Testing approach - Retrieve the Element node inside the Entity node
1523 // named "ent4" and attempt to add a newly created Attr
1524 // node to it. Descendants of Entity nodes are readonly
1525 // nodes and therefore the desired exception should be
1526 // raised.
1528 // Semantic Requirements: 24
1530 //----------------------------------------------------------------------------
1532 [Test]
1533 public void core0026E()
1535 string computedValue = "";
1536 System.Xml.XmlEntity entityNode = null;
1537 System.Xml.XmlElement entityDesc = null;
1538 System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"newAttribute");
1539 string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
1541 testResults results = new testResults("Core0026E");
1544 results.description = "The \"setAttributeNode(newAttr)\" method raises a " +
1545 "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";
1547 // Retrieve targeted data
1549 entityNode = util.getEntity("ent4");
1550 entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;
1552 // Attempt to set an attribute for a readonly node should raise an exception.
1554 try
1556 entityDesc.SetAttributeNode(newAttr);
1558 catch(System.Exception ex)
1560 computedValue = ex.GetType ().FullName;
1563 catch(System.Exception ex)
1565 computedValue = "Exception " + ex.Message;
1567 results.expected = expectedValue;
1568 results.actual = computedValue;
1570 util.resetData();
1572 AssertEquals (results.expected, results.actual);
1575 //------------------------ End test case core-0026E --------------------------
1577 //-------------------------- test case core-00027E ---------------------------
1579 // Testing feature - The "removeAttributeNode(newAttr)" method raises a
1580 // NO_MODIFICATION_ALLOWED_ERR Exception if this
1581 // node is readonly.
1583 // Testing approach - Retrieve the Element node inside the Entity node
1584 // named "ent4" and attempt to remove its "attr1"
1585 // attribute. Descendants of Entity nodes are readonly
1586 // nodes and therefore the desired exception should be
1587 // raised.
1589 // Semantic Requirements: 25
1591 //----------------------------------------------------------------------------
1593 [Test]
1594 public void core0027E()
1596 string computedValue = "";
1597 System.Xml.XmlEntity entityNode = null;
1598 System.Xml.XmlElement entityDesc = null;
1599 System.Xml.XmlAttribute oldAttribute = null;
1600 string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;
1602 testResults results = new testResults("Core0027E");
1605 results.description = "The \"removeAttributeNode(newAttr)\" method raises a " +
1606 "NO_MODIFICATION_ALLOWED_ERR Exception if the node is readonly.";
1608 // Get an instance of an attribute node and retrieve targeted data.
1610 entityNode = util.getEntity("ent4");
1611 entityDesc = (System.Xml.XmlElement)entityNode.FirstChild;
1612 oldAttribute = ((System.Xml.XmlElement)entityNode.FirstChild).GetAttributeNode("attr1");
1614 // Attempt to set remove an attribute node from a readonly node (lastChild).
1615 // Should raise an exception.
1617 try
1619 entityDesc.RemoveAttributeNode(oldAttribute);
1621 catch(System.Exception ex)
1623 computedValue = ex.GetType ().FullName;
1626 catch(System.Exception ex)
1628 computedValue = "Exception " + ex.Message;
1630 results.expected = expectedValue;
1631 results.actual = computedValue;
1633 util.resetData();
1635 AssertEquals (results.expected, results.actual);
1638 //------------------------ End test case core-0027E --------------------------
1640 //-------------------------- test case core-00028E ---------------------------
1642 // Testing feature - The "setAttributeNode(newAttr)" method raises a
1643 // System.ArgumentException Exception if the "newAttr" was
1644 // created from a different document than the one that
1645 // created this document.
1647 // Testing approach - Retrieve the last employee and attempt to set
1648 // a new attribute node for its "employee" element.
1649 // The new attribute was created from a document
1650 // other than the one that crated this element,
1651 // therefore the desired exception should be raised.
1652 // This test uses the "createAttribute(newAttr)" method
1653 // from the Document interface.
1655 // Semantic Requirements: 26
1657 //----------------------------------------------------------------------------
1659 [Test]
1660 public void core0028E()
1662 System.Xml.XmlElement addressElement = null;
1663 string computedValue = "";
1664 System.Xml.XmlAttribute newAttr = null;
1665 string expectedValue = "System.ArgumentException";
1667 testResults results = new testResults("Core0028E");
1670 results.description = "The \"setAttributeNode(newAttr)\" method raises a " +
1671 "System.ArgumentException Exception if \"newAttr\" was created " +
1672 "from a different document than the one who created this node.";
1674 // Access the address Element of the last employee and attempt to set
1675 // a new attribute node.
1677 newAttr = util.getOtherDOMDocument().CreateAttribute("newAttribute");
1678 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
1680 // The new attribute was created from a different document and therefore
1681 // an exception should be raised.
1683 try
1685 addressElement.SetAttributeNode(newAttr);//.node.
1687 catch(System.Exception ex)
1689 computedValue = ex.GetType().ToString();
1692 catch(System.Exception ex)
1694 computedValue = "Exception " + ex.Message;
1696 results.expected = expectedValue;
1697 results.actual = computedValue;
1699 util.resetData();
1701 AssertEquals (results.expected, results.actual);
1704 //------------------------ End test case core-0028E --------------------------
1706 //-------------------------- test case core-00029E ---------------------------
1708 // Testing feature - The "setAttributeNode(newAttr)" method raises an
1709 // InvalidOperationException if the "newAttr"
1710 // attribute is already an attribute of another element.
1712 // Testing approach - Retrieve the last employee and attempt to set an
1713 // attribute node to one of its children that
1714 // already exist in another children. The attribute
1715 // node used is "street", which already exist in the
1716 // "address" element. An instance of that attribute
1717 // node is first retrived from the "address" element and
1718 // then attempted to be set in the "employeeId" element.
1719 // This should cause the intended exception to be raised.
1721 // Semantic Requirements: 27
1723 //----------------------------------------------------------------------------
1725 [Test]
1726 public void core0029E()
1728 string computedValue = "";
1729 System.Xml.XmlElement employeeIdElement = null;
1730 System.Xml.XmlElement addressElement = null;
1731 System.Xml.XmlAttribute newAttribute = null;
1732 string expectedValue = "InvalidOperationException";
1734 testResults results = new testResults("Core0029E");
1737 results.description = "The \"setAttributeNode(newAttr)\" method raises an "+
1738 "InvalidOperationException if \"newAttr\" attribute "+
1739 "is already being used by another element.";
1741 // Retrieve an already existing attribute from the "address" element.
1743 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
1744 newAttribute = addressElement.GetAttributeNode("street");//.node.
1746 // Access the "employeeId" element of the last employee.
1748 employeeIdElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.FIRST);
1750 // Attempt to set an attribute node with an already existing attribute node
1751 // in another element.
1753 try
1755 employeeIdElement.SetAttributeNode(newAttribute);//.node.
1757 catch(System.InvalidOperationException ex)
1759 computedValue = "InvalidOperationException";
1762 catch(System.Exception ex)
1764 computedValue = "Exception " + ex.Message;
1766 results.expected = expectedValue;
1767 results.actual = computedValue;
1769 util.resetData();
1771 AssertEquals (results.expected, results.actual);
1774 //------------------------ End test case core-0029E -------------------------
1776 //-------------------------- test case core-0030E ---------------------------
1778 // Testing feature - The "removeAttributeNode(oldAttr)" method raises a
1779 // NOT_FOUND_ERR Exception if the "oldAttr" attribute
1780 // is not an attribute of the element.
1782 // Testing approach - Retrieve the last employee and attempt to remove
1783 // a non existing attribute node. This should cause
1784 // the intended exception be raised. This test makes use
1785 // of the "createAttribute(name)" method from the
1786 // Document interface.
1788 // Semantic Requirements: 28
1790 //----------------------------------------------------------------------------
1792 [Test]
1793 public void core0030E()
1795 string computedValue = "";
1796 System.Xml.XmlElement addressElement = null;
1797 System.Xml.XmlAttribute oldAttribute = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"oldAttribute");
1798 string expectedValue = "System.ArgumentException";//util.NOT_FOUND1_ERR;
1800 testResults results = new testResults("Core0030E");
1803 results.description = "The \"removeAttributeNode(oldAttr)\" method raises a " +
1804 "NOT_FOUND_ERR Exception if \"oldAttr\" attribute " +
1805 "is not an attribute of the element.";
1807 // Access the "address" element of the last employee.
1809 addressElement = (System.Xml.XmlElement)util.nodeObject(util.FIFTH,util.SIXTH);
1811 // Attempt to remove a non-existing attribute. Should raise exception.
1813 try
1815 addressElement.RemoveAttributeNode(oldAttribute);//.node.
1817 catch(ArgumentException ex)
1819 computedValue = ex.GetType ().FullName;
1822 catch(System.Exception ex)
1824 computedValue = "Exception " + ex.Message;
1826 results.expected = expectedValue;
1827 results.actual = computedValue;
1829 util.resetData();
1831 AssertEquals (results.expected, results.actual);
1834 //------------------------ End test case core-0030E --------------------------