mono /mcs/class/System.XML/Test/System.Xml/nist_dom/fundamental/NamedNodeMap/NamedNodeMap.cs

Language C# Lines 1217
MD5 Hash 043562028c4db2de5868d93bc092913d Estimated Cost $14,394 (why?)
Repository https://bitbucket.org/danipen/mono.git View Raw File View Project SPDX
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
//**************************************************************************
//
//
//                       National Institute Of Standards and Technology
//                                     DTS Version 1.0
//         
//                                 NamedNodeMap Interface
//
// Written by: Carmelo Montanez
// Modified by:  Mary Brady
//
// Ported to System.Xml by: Mizrahi Rafael rafim@mainsoft.com
// Mainsoft Corporation (c) 2003-2004
//**************************************************************************
using System;
using System.Xml;

using nist_dom;
using NUnit.Framework;

namespace nist_dom.fundamental
{
    [TestFixture]
    public class NamedNodeMapTest
    {
        public static int i = 2;
/*
        public testResults[] RunTests()
        {
            testResults[] tests = new testResults[] {core0001M(), core0002M(), core0003M(),core0004M(),
                                                        core0005M(), core0006M(), core0007M(), core0008M(),
                                                        core0009M(), core0010M(), core0011M(),
                                                        core0014M(), core0015M(), core0016M(),
                                                        core0017M(), core0018M(), core0019M(), core0020M(),
                                                        core0021M()};
  
            return tests;
        }
*/
        //------------------------ test case core-0001M ------------------------
        //
        // Testing feature - The "getNamedItem(name)" method retrieves a node 
        //                   specified by name.
        //
        // Testing approach - Retrieve the second employee and create a NamedNodeMap 
        //                    listing of the attributes of its last child.  Once 
        //                    the list is created an invocation of the 
        //                    "getNamedItem(name)" method is done where 
        //                    name = "domestic".  This should result on the domestic 
        //                    Attr node being returned.
        //                    
        // Semantic Requirements: 1
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0001M()
        {
            string computedValue = "";
            string expectedValue = "domestic";
            System.Xml.XmlAttribute domesticAttr = null;
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0001M");
            try
            {
                results.description = "The \"getNamedItem(name)\" method retrieves a node " +
                    "specified by name.";
                //
                // Retrieve targeted data.
                //
                testNode = util.nodeObject(util.SECOND,util.SIXTH);
                domesticAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("domestic");
                computedValue = domesticAttr.Name;
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            //
            // Write out results 
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0001M --------------------------
        //
        //--------------------------- test case core-0002M ---------------------------
        //
        // Testing feature - The "getNamedItem(name)" method returns a node of any
        //                   type specified by name.
        //
        // Testing approach - Retrieve the second employee and create a NamedNodeMap
        //                    listing of the attributes of its last child.  Once
        //                    the list is created an invocation of the
        //                    "getNamedItem(name)" method is done where 
        //                    name = "street".  This should cause the method to return 
        //                    an Attr node.
        //
        // Semantic Requirements: 2 
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0002M()
        {
            string computedValue = "";
            string expectedValue = "street";
            System.Xml.XmlAttribute streetAttr = null;
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0002M");
            try
            {
                results.description = "The \"getNamedItem(name)\" method returns a node "+
                    "of any type specified by name (test for Attr node).";
                //
                // Retrieve targeted data and get its attributes.
                //
                testNode =  util.nodeObject(util.SECOND,util.SIXTH);
                streetAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("street");
                computedValue = streetAttr.Name;
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0002M --------------------------
        //
        //--------------------------- test case core-0003M ---------------------------
        //
        // Testing feature - The "getNamedItem(name)" method returns null if the
        //                   specified name did not identify any node in the map.
        //
        // Testing approach - Retrieve the second employee and create a NamedNodeMap
        //                    listing of the attributes of its last child.  Once
        //                    the list is created an invocation of the
        //                    "getNamedItem(name)" method is done where 
        //                    name = "district", this name does not match any names 
        //                    in the list and the method should return null.
        //
        // Semantic Requirements: 3 
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0003M()
        {
            object computedValue = null;
            object expectedValue = null;
            System.Xml.XmlNode testNode = null;


            testResults results = new testResults("Core0003M");
            try
            {
                results.description = "The \"getNamedItem(name)\" method returns null if the " +
                    "specified name did not identify any node in the map.";
                //
                // Retrieve targeted data and attempt to get a non-existing attribute.
                //
                testNode = util.nodeObject(util.SECOND,util.SIXTH);
                computedValue = testNode.Attributes.GetNamedItem("district");
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            //
            // Write out results
            //
            results.expected = (expectedValue == null).ToString();
            results.actual = (computedValue == null).ToString();

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0003M --------------------------
        //
        //--------------------------- test case core-0004M ---------------------------
        //
        // Testing feature - The "setNamedItem(arg)" method adds a node using its
        //                   nodeName attribute. 
        //
        // Testing approach - Retrieve the second employee and create a NamedNodeMap 
        //                    object from the attributes in its last child 
        //                    by invoking the "attributes" attribute.  Once the
        //                    list is created, the "setNamedItem(arg)" method is 
        //                    invoked with arg = newAttr, where newAttr is a new 
        //                    Attr Node previously created.  The "setNamedItem(arg)" 
        //                    method should add the new node to the NamedNodeItem 
        //                    object by using its "nodeName" attribute ("district" 
        //                    in this case).  Further this node is retrieved by using 
        //                    the "getNamedItem(name)" method.  This test uses the 
        //                    "createAttribute(name)" method from the Document 
        //                    interface.
        //
        // Semantic Requirements: 4 
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0004M()
        {
            string computedValue = "";
            string expectedValue = "district";
            System.Xml.XmlAttribute districtAttr = null;
            System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0004M");
            try
            {
                results.description = "The \"setNamedItem(arg)\" method adds a node "+
                    "using its nodeName attribute.";
                //
                // Retrieve targeted data and add new attribute.
                //
                testNode = util.nodeObject(util.SECOND,util.SIXTH);
                testNode.Attributes.SetNamedItem(newAttr);
                districtAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("district");
                computedValue = districtAttr.Name; 
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            util.resetData();
            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0004M --------------------------
        //
        //--------------------------- test case core-0005 ---------------------------
        //
        // Testing feature - If the node to be added by the "setNamedItem(arg)" method 
        //                   already exists in the NamedNodeMap, it is replaced by the 
        //                   new one.
        //
        // Testing approach - Retrieve the second employee and create a NamedNodeMap
        //                    object from the attributes in its last child.  Once
        //                    the list is created, the "setNamedItem(arg) method is 
        //                    invoked with arg = newAttr, where newAttr is a Node Attr
        //                    previously created and whose node name already exist
        //                    in the map.   The "setNamedItem(arg)" method should 
        //                    replace the already existing node with the new one.  
        //                    Further this node is retrieved by using the 
        //                    "getNamedItem(name)" method.  This test uses the 
        //                    "createAttribute(name)" method from the Document 
        //                    interface.
        //
        // Semantic Requirements: 5 
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0005M()
        {
            string computedValue = "";
            string expectedValue = "";
            System.Xml.XmlAttribute streetAttr = null;
            System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0005M");
            try
            {
                results.description = "If the node to be replaced by the \"setNamedItem(arg)\" " +
                    "method is already in the list, the existing node should " +
                    "be replaced by the new one.";

                //
                // Retrieve targeted data and add new attribute with name matching an 
                // already existing attribute.
                //
                testNode = util.nodeObject(util.SECOND,util.SIXTH);
                testNode.Attributes.SetNamedItem(newAttr);
                streetAttr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("street");
                computedValue = streetAttr.Value;
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }
            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            util.resetData();
            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0005M --------------------------
        //
        //--------------------------- test case core-0006 ---------------------------
        //
        // Testing feature - If the "setNamedItem(arg)" method replaces an already 
        //                   existing node with the same name then the already existing
        //                   node is returned. 
        //
        // Testing approach - Retrieve the third employee and create a "NamedNodeMap"
        //                    object of the attributes in its last child by
        //                    invoking the "attributes" attribute.  Once the
        //                    list is created, the "setNamedItem(arg) method is 
        //                    invoked with arg = newAttr, where newAttr is a Node Attr
        //                    previously created and whose node name already exist
        //                    in the map.  The "setNamedItem(arg)" method should replace
        //                    the already existing node with the new one and return
        //                    the existing node.  Further this node is retrieved by 
        //                    using the "getNamedItem(name)" method.  This test 
        //                    uses the "createAttribute(name)" method from the Document 
        //                    interface.
        //
        // Semantic Requirements: 6 
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0006M()
        {
            string computedValue = "";
            string expectedValue = "No";
            System.Xml.XmlNode returnedNode = null;
            System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"street");
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0006M");
            try
            {
                results.description = "If the \"setNamedItem(arg)\" method replaces an "+
                    "already existing node with the same name then it "+
                    "returns the already existing node.";
                //
                // Retrieve targeted data and examine value returned by the setNamedItem
                // method.
                //
                testNode = util.nodeObject(util.THIRD,util.SIXTH);
                returnedNode = testNode.Attributes.SetNamedItem(newAttr);
                computedValue = returnedNode.Value;
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }
            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            util.resetData();
            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0006M --------------------------
        //
        //--------------------------- test case core-0007 ---------------------------
        //
        // Testing feature - The "setNamedItem(arg)" method replace an 
        //                   already existing node with the same name. If a node with 
        //                   that name is already present in the collection, 
        //                   it is replaced by the new one.
        //
        // Testing approach - Retrieve the third employee and create a NamedNodeMap
        //                    object from the attributes in its last child. 
        //                    Once the list is created, the "setNamedItem(arg)" 
        //                    method is invoked with arg = newAttr, where newAttr is 
        //                    a new previously created Attr node The 
        //                    "setNamedItem(arg)" method should add the new node 
        //                    and return the new one.  Further this node is retrieved by 
        //                    using the "getNamedItem(name)" method.  This test 
        //                    uses the "createAttribute(name)" method from the 
        //                    Document interface.
        //
        // Semantic Requirements: 7 
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0007M()
        {
            string computedValue = "";
            string expectedValue = "district";
            System.Xml.XmlAttribute newAttr = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"district");
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0007M");
            try
            {
                results.description = "If a node with that name is already present in the collection. The \"setNamedItem(arg)\" method is replacing it by the new one";
                //
                // Retrieve targeted data and set new attribute.
                //
                testNode = util.nodeObject(util.THIRD,util.SIXTH);
                computedValue = testNode.Attributes.SetNamedItem(newAttr).Name;
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }
            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            util.resetData();
            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0007M --------------------------
        //
        //--------------------------- test case core-0008 ----------------------------
        //
        // Testing feature - The "removeNamedItem(name)" method removes a node
        //                   specified by name. 
        //
        // Testing approach - Retrieve the third employee and create a NamedNodeMap
        //                    object from the attributes in its last child. Once
        //                    the list is created, the "removeNamedItem(name)" 
        //                    method is invoked where "name" is the name of an 
        //                    existing attribute.  The "removeNamedItem(name)" method
        //                    should remove the specified attribute and its "specified"
        //                    attribute (since this is an Attr node) should be set
        //                    to false.  
        //
        // Semantic Requirements: 8 
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0008M()
        {
            string computedValue = "";
            string expectedValue = "False";
            System.Xml.XmlNode testNode = null;
            System.Xml.XmlAttribute Attr = null;

            testResults results = new testResults("Core0008M");
            try
            {
                results.description = "The \"removeNamedItem(name)\" method removes "+
                    "a node specified by name.";
                //
                // Retrive targeted data and and remove attribute.  It should no longer
                // be specified.
                //
                testNode = (System.Xml.XmlNode)util.nodeObject(util.THIRD,util.SIXTH);
                testNode.Attributes.RemoveNamedItem("street");
                Attr = (System.Xml.XmlAttribute)testNode.Attributes.GetNamedItem("street");
                computedValue = Attr.Specified.ToString();
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }
            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            util.resetData();
            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0008M --------------------------
        //
        //--------------------------- test case core-0009 ----------------------------
        //
        // Testing feature - If the node removed by the "removeNamedItem(name)" method
        //                   is an Attr node with a default value, its is immediately
        //                   replaced.
        //
        // Testing approach - Retrieve the third employee and create a NamedNodeMap
        //                    object from the attributes in its last child.  Once
        //                    the list is created, the "removeNamedItem(name)" method
        //                    is invoked where "name" is the name of an existing
        //                    attribute ("street)".  The "removeNamedItem(name)" method
        //                    should remove the "street" attribute and since it has 
        //                    a default value of "Yes", that value should immediately
        //                    be the attribute's value.
        //
        // Semantic Requirements: 9 
        //
        //----------------------------------------------------------------------------

        [Test]
#if NET_2_0
	[Category ("NotDotNet")]
#endif
	public void core0009M()
        {
            string computedValue = "";
            string expectedValue = "Yes";
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0009M");
            try
            {
                results.description = "If the node removed by the \"removeNamedItem(name)\" "+
                    "method is an Attr node with a default value, then "+
                    "it is immediately replaced.";
                //
                // Retrieve targeted data and remove attribute.
                //
                testNode = util.nodeObject(util.THIRD,util.SIXTH);
                testNode.Attributes.RemoveNamedItem("street");
                computedValue = testNode.Attributes.GetNamedItem("street").Value;
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }
            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            util.resetData();

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0009M --------------------------
        //
        //--------------------------- test case core-0010M ---------------------------
        //
        // Testing feature - The "removeNamedItem(name)" method returns the node removed
        //                   from the map.
        //
        // Testing approach - Retrieve the third employee and create a NamedNodeMap
        //                    object from the attributes in its last child. 
        //                    Once the list is created, the "removeNamedItem(name)" 
        //                    method is invoked where "name" is the name of an existing
        //                    attribute ("street)".  The "removeNamedItem(name)" 
        //                    method should remove the existing "street" attribute
        //                    and return it.
        //
        // Semantic Requirements: 10 
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0010M()
        {
            string computedValue = "";
            string expectedValue = "No";
            System.Xml.XmlNode returnedNode = null;
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0010M");
            try
            {
                results.description = "The \"removeNamedItem(name)\" method returns the "+
                    "node removed from the map.";
                //
                // Retrieve targeted data, remove attribute and examine returned value of
                // removeNamedItem method.
                //
                testNode = util.nodeObject(util.THIRD,util.SIXTH);
                returnedNode = testNode.Attributes.RemoveNamedItem("street");
                computedValue = returnedNode.Value;
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            util.resetData();

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0010M --------------------------
        //
        //--------------------------- test case core-0011M ---------------------------
        //
        // Testing feature - The "removeNamedItem(name)" method returns null if the
        //                   name specified does not exists in the map.
        //
        // Testing approach - Retrieve the third employee and create a NamedNodeMap
        //                    object from the attributes in its last child.
        //                    Once the list is created, the "removeNamedItem(name)" 
        //                    method is invoked where "name" does not exist in the 
        //                    map.  The method should return null.
        //
        // Semantic Requirements: 11
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0011M()
        {
            object computedValue = null;
            object expectedValue = null;
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0011M");
            try
            {
                results.description = "The \"removeNamedItem(name)\" method returns null "+
                    "if the specified \"name\" is not in the map.";
                //
                // Retrieve targeted data and attempt to remove a non-existing attribute.
                //
                testNode = util.nodeObject(util.THIRD,util.SIXTH);
                computedValue = testNode.Attributes.RemoveNamedItem("district");
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            //
            // Write out results
            //
            results.expected = (expectedValue == null).ToString();
            results.actual = (computedValue == null).ToString();

            util.resetData();

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0011M --------------------------
        //
        //--------------------------- test case core-0012M ---------------------------
        //
        // Testing feature - The "item(index)" method returns the indexth item in the
        //                   map (test for first item).
        //
        // Testing approach - Retrieve the second employee and create a NamedNodeMap
        //                    object from the attributes in its last child by
        //                    by invoking the "attributes" attribute.  Once
        //                    the list is created, the "item(index)" method is
        //                    invoked with index = 0.  This should return the node at
        //                    the first position.  Since there are no guarantees that
        //                    first item in the map is the one that was listed first 
        //                    in the attribute list the test checks for all of them.
        //
        // Semantic Requirements: 12
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0012M()
        {
            //string testName = "core-0012M";
            string computedValue = "";
//            string expectedValue = "domestic or street";
            string expectedValue = "domestic";
            System.Xml.XmlNode returnedNode = null;
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0012M");
            try
            {
                results.description = "Retrieve the first item in the map via the \"item(index)\" method."; 

                //
                // Retrieve targeted data and invoke "item" method.
                //  
                testNode = util.nodeObject(util.SECOND,util.SIXTH);
                returnedNode = testNode.Attributes.Item(0);
                computedValue = returnedNode.Name;
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0012M --------------------------
        //
        //--------------------------- test case core-0013M ---------------------------
        //
        // Testing feature - The "item(index)" method returns the indexth item in the
        //                   map (test for last item).
        //
        // Testing approach - Retrieve the second employee and create a NamedNodeMap
        //                    object from the attributes in its last child. 
        //                    Once the list is created, the "item(index)" method is
        //                    invoked with index = 1.  This should return the node at
        //                    the last position.  Since there are no guarantees that
        //                    the last item in the map is the one that was listed last 
        //                    in the attribute list, the test checks for all of them.
        //
        // Semantic Requirements: 12
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0013M()
        {
            string computedValue = "";
//            string expectedValue = "domestic or street";
            string expectedValue = "street";
            System.Xml.XmlNode returnedNode = null;
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0013M");
            try
            {
                results.description = "Retrieve the last item in the map via the \"item(index)\" method."; 
                //
                // Retrieve targeted data and invoke "item" attribute.
                //
                testNode = util.nodeObject(util.THIRD,util.SIXTH);
                returnedNode = testNode.Attributes.Item(1);
                computedValue = returnedNode.Name;
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }
            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0013M --------------------------
        //
        //--------------------------- test case core-0014M ---------------------------
        //
        // Testing feature - The "item(index)" method returns null if the index is 
        //                   greater than the number of nodes in the map.
        //
        // Testing approach - Retrieve the second employee and create a NamedNodeMap
        //                    object from the attributes in its last child. 
        //                    element by invoking the "attributes" attribute.  Once
        //                    the list is created, the "item(index)" method is
        //                    invoked with index = 3.  This index value is greater than
        //                    the number of nodes in the map and under that condition
        //                    the method should return null.
        //
        // Semantic Requirements: 13
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0014M()
        {
            object computedValue = null;
            object expectedValue = null;
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0014M");
            try
            {
                results.description = "The \"item(index)\" method returns null if the "+
                    "index is greater than the number of nodes in the map.";

                //
                // Retrieve targeted data and invoke "item" method.
                //
                testNode = util.nodeObject(util.THIRD,util.SIXTH);
                computedValue = testNode.Attributes.Item(3);
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            //
            // Write out results
            //
            results.expected = (expectedValue == null).ToString();
            results.actual = (computedValue == null).ToString();

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0014M --------------------------
        //
        //--------------------------- test case core-0015M ---------------------------
        //
        // Testing feature - The "item(index)" method returns null if the index is
        //                   equal to the number of nodes in the map.
        //
        // Testing approach - Retrieve the second employee and create a NamedNodeMap
        //                    object from the attributes in its last child 
        //                    Once the list is created, the "item(index)" method is
        //                    invoked with index = 2.  This index value is equal to 
        //                    the number of nodes in the map and under that condition
        //                    the method should return null (first item is at position
        //                    0).
        //
        // Semantic Requirements: 13
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0015M()
        {
            object computedValue = null;
            object expectedValue = null;
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0015M");
            try
            {
                results.description = "The \"item(index)\" method returns null if the index " +
                    "is equal to the number of nodes in the map.";
                //
                // Retrieve targeted data and invoke "item" method.
                //
                testNode = util.nodeObject(util.THIRD,util.SIXTH);
                computedValue = testNode.Attributes.Item(2);
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }
            //
            // Write out results
            //
            results.expected = (expectedValue == null).ToString();
            results.actual = (computedValue == null).ToString();

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0015M --------------------------
        //
        //--------------------------- test case core-0016M ---------------------------
        //
        // Testing feature - The "length" attribute contains the total number of
        //                   nodes in the map.
        //
        // Testing approach - Retrieve the second employee and create a NamedNodeMap
        //                    object from the attributes in its last child. 
        //                    Once the list is created, the "length" attribute is
        //                    invoked.  That attribute should contain the number 2. 
        //
        // Semantic Requirements: 14
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0016M()
        {
            string computedValue = "";
            string expectedValue = "2";
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0016M");
            try
            {
                results.description = "The \"length\" attribute contains the number of " +
                    "nodes in the map.";
                //
                // Retrieve targeted data and invoke "length" attribute.
                //
                testNode = util.nodeObject(util.THIRD,util.SIXTH);
                computedValue = testNode.Attributes.Count.ToString();
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }
            //
            // Write out results
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0016M --------------------------
        //
        //--------------------------- test case core-0017M ---------------------------
        //
        // Testing feature - The range of valid child nodes indices is 0 to length - 1.
        //
        // Testing approach - Create a NamedNodeMap object from the attributes of the
        //                    last child of the third employee and traverse the
        //                    list from index 0 to index length - 1.  All indices
        //                    should be valid.
        //
        // Semantic Requirements: 15 
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0017M()
        {
            string computedValue = "";
            string expectedValue = "0 1 ";
            int lastIndex = 0;
            //string attributes = "";
            System.Xml.XmlNode testNode = null;

            testResults results = new testResults("Core0017M");
            try
            {
                results.description = "The range of valid child nodes indices is 0 to " +
                    "length - 1.";
                //
                // Retrieve targeted data and compute list length.
                //
                testNode = util.nodeObject(util.THIRD,util.SIXTH);
                lastIndex = testNode.Attributes.Count - 1;
                //
                // Traverse the list from 0 to length - 1.  All indices should be valid.
                //
                for (int index = 0;index <= lastIndex; index++)
                    computedValue += index+" ";
            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }
            //
            // Write out results.
            //
            results.expected = expectedValue;
            results.actual = computedValue;

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0017M --------------------------
        //
        //--------------------------- test case core-0018M ---------------------------
        //
        // Testing feature - The "setNamedItem(arg) method raises a System.ArgumentException
        //                   Exception if "arg" was created from a different 
        //                   document than the one that created the NamedNodeMap.
        //
        // Testing approach - Create a NamedNodeMap object from the attributes of the
        //                    last child of the third employee and attempt to 
        //                    add another Attr node to it that was created from a 
        //                    different DOM document.  This condition should raise
        //                    the desired exception.  This method uses the
        //                    "createAttribute(name)" method from the Document
        //                    interface. 
        //
        // Semantic Requirements: 16
        //
        //----------------------------------------------------------------------------

        [Test]
	[Category ("NotDotNet")] // MS DOM is buggy
	public void core0018M()
        {
            string computedValue = "";
            
            System.Xml.XmlAttribute newAttrNode = util.getOtherDOMDocument().CreateAttribute("newAttribute");
            System.Xml.XmlNode testNode = null;
            string expectedValue = "System.ArgumentException";

            testResults results = new testResults("Core0018M");

            results.description = "The \"setNamedItem(arg)\" method raises a "+
                "System.ArgumentException Exception if \"arg\" was " +
                "created from a document different from the one that created "+
                "the NamedNodeList.";
            //
            // Retrieve targeted data and attempt to add an element that was created
            // from a different document.  Should raise an exception.
            //
            testNode = util.nodeObject(util.THIRD,util.SIXTH);

            try 
            {
                testNode.Attributes.SetNamedItem(newAttrNode);
            } 
            catch(System.Exception ex) 
            {
                computedValue = ex.GetType().ToString();
            }


            results.expected = expectedValue;
            results.actual = computedValue;

            util.resetData();

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0018M --------------------------
        //
        //--------------------------- test case core-0019M ---------------------------
        //
        // Testing feature - The "setNamedItem(arg) method raises a 
        //                   NO_MODIFICATION_ALLOWED_ERR Exception if this
        //                   NamedNodeMap is readonly.
        //
        // Testing approach - Create a NamedNodeMap object from the first child of the
        //                    Entity named "ent4" inside the DocType node and then 
        //                    attempt to add a new item to the list.  It should raise 
        //                    the desired exception as this is a readonly NamedNodeMap.
        //                   
        // Semantic Requirements: 17
        //
        //----------------------------------------------------------------------------

        [Test]
	[Category ("NotDotNet")] // MS DOM is buggy
	public void core0019M()
        {
            string computedValue = "";
            System.Xml.XmlNode testNode = null;
            System.Xml.XmlNode entityDesc;
            System.Xml.XmlAttribute newAttrNode = (System.Xml.XmlAttribute)util.createNode(util.ATTRIBUTE_NODE,"newAttribute");
            string expectedValue = "System.ArgumentException";//util.NO_MODIFICATION_ALLOWED_ERR;

            testResults results = new testResults("Core0019M");

            results.description = "The \"setNamedItem(arg)\" method raises a " +
                "NO_MODIFICATION_ALLOWED_ERR Exception if this "+
                "NamedNodeMap is readonly.";
            //
            // Create a NamedNodeMap object and attempt to add a node to it.
            // Should raise an exception.
            //
            testNode = util.getEntity("ent4");
            entityDesc = testNode.FirstChild;

            try 
            {
                entityDesc.Attributes.SetNamedItem(newAttrNode);
            }
            catch(ArgumentException ex) 
            {
                computedValue = ex.GetType ().FullName; 
            }


            results.expected = expectedValue;
            results.actual = computedValue;

            util.resetData();

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0019M --------------------------
        //
        //--------------------------- test case core-0020M ---------------------------
        //
        // Testing feature - The "setNamedItem(arg) method raises an
        //                   INUSE_ATTRIBUTE_ERR Exception if "arg" is an Attr 
        //                   that is already an attribute of another Element.
        //
        // Testing approach - Create a NamedNodeMap object from the attributes of the
        //                    third child and attempt to add an attribute that is
        //                    already being used by the first employee.  An attempt
        //                    to add such an attribute should raise the desired
        //                    exception. 
        //
        // Semantic Requirements: 18
        //
        //----------------------------------------------------------------------------

        [Test]
	[Category ("NotDotNet")]
	public void core0020M()
        {
            string computedValue= "";
            System.Xml.XmlAttribute inUseAttribute = null;
            System.Xml.XmlElement firstEmployee = null;
            System.Xml.XmlNode testNode = null;
            string expectedValue = "System.ArgumentException";//util.INUSE_ATTRIBUTE_ERR;

            testResults results = new testResults("Core0020M");
            try
            {
                results.description = "The \"setNamedItem(arg)\" method raises an "+
                    "INUSE_ATTRIBUTE_ERR Exception if \"arg\" "+
                    "is an Attr node that is already an attribute "+
                    "of another Element.";

                firstEmployee = (System.Xml.XmlElement)util.nodeObject(util.FIRST,util.SIXTH);
                inUseAttribute = firstEmployee.GetAttributeNode("domestic");
                //
                // Attempt to add an attribute that is already used by another element 
                // should raise an exception.
                //
                testNode = util.nodeObject(util.THIRD,util.SIXTH);

                try 
                {
                    testNode.Attributes.SetNamedItem(inUseAttribute);
                }
                catch (System.Exception ex) 
                {
                    computedValue = ex.GetType ().FullName; 
                }

            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            results.expected = expectedValue;
            results.actual = computedValue;

            util.resetData();

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0020M --------------------------
        //
        //--------------------------- test case core-0021M ---------------------------
        //
        // Testing feature - The "removeNamedItem(name) method raises an
        //                   NOT_FOUND_ERR Exception if there is no node
        //                   named "name" in the map.
        //
        // Testing approach - Create a NamedNodeMap object from the attributes of the
        //                    last child of the third employee and attempt to
        //                    remove the "district" attribute.  There is no node named
        //                    "district" in the list and therefore the desired 
        //                    exception should be raised.
        //
        // System.Xml       - return null, if a matching node was not found.
        //
        // Semantic Requirements: 19
        //
        //----------------------------------------------------------------------------

        [Test]
	public void core0021M()
        {
            object computedValue = null;
            System.Xml.XmlNode testNode = null;
            object expectedValue = null;//util.NOT_FOUND1_ERR;

            testResults results = new testResults("Core0021M");
            try
            {
                results.description = "The \"removeNamedItem(name)\" method raises a " +
                    "NOT_FOUND_ERR Exception if there is no node "+
                    "named \"name\" in the map.";
                //
                // Create a NamedNodeMap object and attempt to remove an attribute that
                // is not in the list should raise an exception.
                //
                testNode = util.nodeObject(util.THIRD,util.SIXTH);

                try 
                {
                    //null if a matching node was not found
                    computedValue = testNode.Attributes.RemoveNamedItem("district");
                }
                catch(System.Exception ex) 
                {
                    computedValue = ex.Message; 
                }

            }
            catch(System.Exception ex)
            {
                computedValue = "Exception " + ex.Message;
            }

            results.expected = (expectedValue == null).ToString();
            results.actual = (computedValue == null).ToString();

            util.resetData();

            Assert.AreEqual (results.expected, results.actual);
        }

        //------------------------ End test case core-0021M --------------------------
    }
}
Back to Top