Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DataTableTest2.cs « System.Data « Test « System.Data « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 368101ddb696d149370693649329d7d6caf3cc2b (plain)
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
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
// Authors:
//   Rafael Mizrahi   <rafim@mainsoft.com>
//   Erez Lotan       <erezl@mainsoft.com>
//   Oren Gurfinkel   <oreng@mainsoft.com>
//   Ofer Borstein
// 
// Copyright (c) 2004 Mainsoft Co.
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using NUnit.Framework;
using System;
using System.Data;
using MonoTests.System.Data.Utils;

namespace MonoTests_System.Data
{
	[TestFixture] public class DataTableTest2
	{
		private bool _EventTriggered = false;
		private bool EventRaised = false;
		private bool EventValues = false;

		class ProtectedTestClass : DataTable
		{
			public ProtectedTestClass() : base()
			{
				this.Columns.Add("Id",typeof(int));
				this.Columns.Add("Value",typeof(string));
				this.Rows.Add(new object[] {1,"one"});
				this.Rows.Add(new object[] {2,"two"});
				this.AcceptChanges();
			}

			public void OnColumnChanged_Test()
			{
				OnColumnChanged(new DataColumnChangeEventArgs(this.Rows[0],this.Columns["Value"],"NewValue")); 
			}

			public void OnColumnChanging_Test()
			{
				OnColumnChanging(new DataColumnChangeEventArgs(this.Rows[0],this.Columns["Value"],"NewValue")); 
			}

			public void OnRemoveColumn_Test()
			{
				OnRemoveColumn(this.Columns[0]); 
			}

			public DataTable CreateInstance_Test()
			{
				return CreateInstance();
			}

			public void OnRowChanged_Test(DataRowAction drAction )
			{
				base.OnRowChanged(new DataRowChangeEventArgs(this.Rows[0],drAction )); 
			}

			public void OnRowChanging_Test(DataRowAction drAction )
			{
				base.OnRowChanging(new DataRowChangeEventArgs(this.Rows[0],drAction )); 
			}

			public void OnRowDeleted_Test(DataRowAction drAction )
			{
				base.OnRowDeleted(new DataRowChangeEventArgs(this.Rows[0],drAction )); 
			}

			public void OnRowDeleting_Test(DataRowAction drAction )
			{
				base.OnRowDeleting(new DataRowChangeEventArgs(this.Rows[0],drAction )); 
			}
		}

		[Test] public void AcceptChanges()
		{
			String sNewValue = "NewValue";
			DataRow drModified,drDeleted,drAdded;
			DataTable dt = DataProvider.CreateParentDataTable();

			drModified = dt.Rows[0];
			drModified[1] = sNewValue; //DataRowState = Modified ,DataRowVersion = Proposed

			drDeleted = dt.Rows[1];
			drDeleted.Delete();		//DataRowState =  Deleted

			drAdded = dt.NewRow();			
			dt.Rows.Add(drAdded);	//DataRowState =  Added

			dt.AcceptChanges();

			// AcceptChanges - Unchanged1
			Assert.AreEqual(DataRowState.Unchanged , drModified.RowState  , "DT1");

			// AcceptChanges - Current
			Assert.AreEqual(sNewValue , drModified[1,DataRowVersion.Current] , "DT2");

			// AcceptChanges - Unchanged2
			Assert.AreEqual(DataRowState.Unchanged , drAdded.RowState  , "DT3");

			// AcceptChanges - Detached
			Assert.AreEqual(DataRowState.Detached  , drDeleted.RowState  , "DT4");
		}

		[Test] public void ChildRelations()
		{
			DataTable dtChild,dtParent;
			DataSet ds = new DataSet();
			//Create tables
			dtChild = DataProvider.CreateChildDataTable();
			dtParent= DataProvider.CreateParentDataTable(); 
			//Add tables to dataset
			ds.Tables.Add(dtChild);
			ds.Tables.Add(dtParent);

			DataRelationCollection drlCollection;
			DataRelation drl = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);

			// Checking ChildRelations - default value
			//Check default
			drlCollection = dtParent.ChildRelations; 
			Assert.AreEqual(0, drlCollection.Count  , "DT5");

			ds.Relations.Add(drl);
			drlCollection = dtParent.ChildRelations; 

			// Checking ChildRelations Count
			Assert.AreEqual(1, drlCollection.Count  , "DT6");

			// Checking ChildRelations Value
			Assert.AreEqual(drl, drlCollection[0] , "DT7");
		}

		[Test] public void Clear()
		{
			DataTable dt = DataProvider.CreateParentDataTable();
			dt.Clear();
			// Clear
			Assert.AreEqual(0, dt.Rows.Count  , "DT8");
		}

		[Test] public void Clone()
		{
			DataTable dt1,dt2 = DataProvider.CreateParentDataTable();
			dt2.Constraints.Add("Unique",dt2.Columns[0],true);
			dt2.Columns[0].DefaultValue=7;

			dt1 = dt2.Clone();

			for (int i=0; i<dt2.Constraints.Count; i++)
			{
				// Clone - Constraints[{0}],i)
				Assert.AreEqual(dt2.Constraints[i].ConstraintName ,  dt1.Constraints[i].ConstraintName , "DT9");
			}

			for (int i=0; i<dt2.Columns.Count; i++)
			{
				// Clone - Columns[{0}].ColumnName,i)
				Assert.AreEqual(dt2.Columns[i].ColumnName ,  dt1.Columns[i].ColumnName  , "DT10");

				// Clone - Columns[{0}].DataType,i)
				Assert.AreEqual(dt2.Columns[i].DataType ,  dt1.Columns[i].DataType , "DT11");
			}
		}

		[Test] public void ColumnChanged()
		{
			DataTable dt = DataProvider.CreateParentDataTable();

			dt.ColumnChanged += new DataColumnChangeEventHandler( Column_Changed );

			_EventTriggered=false;
			// ColumnChanged - EventTriggered
			dt.Rows[0][1] = "NewValue";
			Assert.AreEqual(true , _EventTriggered , "DT12");

			_EventTriggered=false;
			dt.ColumnChanged -= new DataColumnChangeEventHandler( Column_Changed );
			// ColumnChanged - NO EventTriggered
			dt.Rows[0][1] = "VeryNewValue";
			Assert.AreEqual(false , _EventTriggered , "DT13");
		}

		private void Column_Changed( object sender, DataColumnChangeEventArgs e )
		{
			_EventTriggered = true;
		}

		[Test] public void ColumnChanging()
		{
			DataTable dt = DataProvider.CreateParentDataTable();

			dt.ColumnChanging  += new DataColumnChangeEventHandler( Column_Changeding );

			_EventTriggered=false;
			// ColumnChanged - EventTriggered
			dt.Rows[0][1] = "NewValue";
			Assert.AreEqual(true , _EventTriggered , "DT14");

			_EventTriggered=false;
			dt.ColumnChanging  -= new DataColumnChangeEventHandler( Column_Changeding );
			// ColumnChanged - NO EventTriggered
			dt.Rows[0][1] = "VeryNewValue";
			Assert.AreEqual(false , _EventTriggered , "DT15");
		}

		private void Column_Changeding( object sender, DataColumnChangeEventArgs e )
		{
			_EventTriggered = true;
		}

		[Test] public void Columns()
		{
			DataTable dtParent;
			DataColumnCollection dcl;
			dtParent= DataProvider.CreateParentDataTable(); 

			dcl = dtParent.Columns; 

			// Checking ColumnsCollection != null 
			Assert.AreEqual(false, dcl == null  , "DT16");

			// Checking ColumnCollection Count  1
			Assert.AreEqual(6, dcl.Count  , "DT17");

			// Checking ColumnCollection Count 2
			dtParent.Columns.Add(new DataColumn("Test"));
			Assert.AreEqual(7, dcl.Count  , "DT18");

			// Checking ColumnCollection - get columnn by different case
			DataColumn tmp = dtParent.Columns["TEST"];
			Assert.AreEqual(dtParent.Columns["Test"], tmp  , "DT19");

			// Checking ColumnCollection colummn name case sensetive
			dtParent.Columns.Add(new DataColumn("test"));
			Assert.AreEqual(8, dcl.Count  , "DT20");

			// Checking ColumnCollection - get columnn by different case,ArgumentException
			try
			{
				DataColumn tmp1 = dtParent.Columns["TEST"];
				Assert.Fail("DT21: indexer Failed to throw ArgumentException");
			}
			catch (ArgumentException) {}
			catch (AssertionException exc) {throw  exc;}
			catch (Exception exc)
			{
				Assert.Fail("DT22: Indexer. Wrong exception type. Got:" + exc);
			}
		}

		[Test] public void Compute()
		{
			DataTable dt = DataProvider.CreateChildDataTable();

			//Get expected
			DataRow[] drArr = dt.Select("ParentId=1");
			Int64 iExSum = 0;
			foreach (DataRow dr in drArr)
			{
				iExSum += (int)dr["ChildId"];
			}
			object objCompute=null;
			// Compute - sum values
			objCompute = dt.Compute("Sum(ChildId)","ParentId=1");
			Assert.AreEqual(Int64.Parse(objCompute.ToString()) , Int64.Parse(iExSum.ToString()), "DT23");

			// Compute - sum type
			Assert.AreEqual(typeof(Int64).FullName , objCompute.GetType().FullName, "DT24");

			//get expected
			double iExAvg = 0;
			drArr = dt.Select("ParentId=5");
			foreach (DataRow dr in drArr)
			{
				iExAvg += (double)dr["ChildDouble"];
			}
			iExAvg = iExAvg / drArr.Length;

			// Compute - Avg value
			objCompute = dt.Compute("Avg(ChildDouble)","ParentId=5");
			Assert.AreEqual(double.Parse(objCompute.ToString()) , double.Parse(iExAvg.ToString()), "DT25");

			// Compute - Avg type
			Assert.AreEqual(typeof(double).FullName , objCompute.GetType().FullName, "DT26");
		}

		[Test] public void Constraints()
		{
			DataTable dtParent;
			ConstraintCollection consColl;
			dtParent= DataProvider.CreateParentDataTable(); 

			consColl = dtParent.Constraints;
			// Checking Constraints  != null 
			Assert.AreEqual(false, consColl == null  , "DT27");

			// Checking Constraints Count
			Assert.AreEqual(0, consColl.Count  , "DT28");

			// Checking Constraints Count
			//Add primary key
			dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns[0]};
			Assert.AreEqual(1, consColl.Count   , "DT29");
		}

		[Test] public void Copy()
		{
			DataTable dt1,dt2 = DataProvider.CreateParentDataTable();
			dt2.Constraints.Add("Unique",dt2.Columns[0],true);
			dt2.Columns[0].DefaultValue=7;

			dt1 = dt2.Copy();

			for (int i=0; i<dt2.Constraints.Count; i++)
			{
				// Copy - Constraints[{0}],i)
				Assert.AreEqual(dt2.Constraints[i].ConstraintName ,  dt1.Constraints[i].ConstraintName , "DT30");
			}

			for (int i=0; i<dt2.Columns.Count; i++)
			{
				// Copy - Columns[{0}].ColumnName,i)
				Assert.AreEqual(dt2.Columns[i].ColumnName ,  dt1.Columns[i].ColumnName  , "DT31");

				// Copy - Columns[{0}].DataType,i)
				Assert.AreEqual(dt2.Columns[i].DataType ,  dt1.Columns[i].DataType , "DT32");
			}

			DataRow[] drArr1,drArr2;
			drArr1 = dt1.Select("");
			drArr2 = dt2.Select("");
			for (int i=0; i<drArr1.Length ; i++)
			{
				// Copy - Data [ParentId]{0} ,i)
				Assert.AreEqual(drArr2[i]["ParentId"], drArr1[i]["ParentId"], "DT33");
				// Copy - Data [String1]{0} ,i)
				Assert.AreEqual(drArr2[i]["String1"], drArr1[i]["String1"], "DT34");
				// Copy - Data [String2]{0} ,i)
				Assert.AreEqual(drArr2[i]["String2"], drArr1[i]["String2"], "DT35");
			}
		}

		[Test] public void CreateInstance()
		{
			// CreateInstance
			ProtectedTestClass C = new ProtectedTestClass();
			DataTable dt = C.CreateInstance_Test();
			Assert.AreEqual(true , dt != null , "DT36");
		}

		[Test] public void DataSet()
		{
			DataTable dtParent;
			DataSet ds;
			dtParent= DataProvider.CreateParentDataTable(); 

			ds = dtParent.DataSet; 

			// Checking DataSet == null
			Assert.AreEqual(null, ds, "DT37");

			// Checking DataSet != null
			ds = new DataSet("MyDataSet");
			ds.Tables.Add(dtParent);
			Assert.AreEqual(true, dtParent.DataSet != null , "DT38");

			// Checking DataSet Name
			Assert.AreEqual("MyDataSet", dtParent.DataSet.DataSetName  , "DT39");
		}

		[Test] public void DefaultView()
		{
			DataTable dtParent;
			DataView dv;
			dtParent= DataProvider.CreateParentDataTable(); 
			dv = dtParent.DefaultView ;

			// Checking DataView != null
			Assert.AreEqual(true, dv != null, "DT40");
		}

		[Test] public void EndLoadData()
		{
			DataTable dt = DataProvider.CreateParentDataTable();
			dt.Columns[0].AllowDBNull = false;

			// EndLoadData
			dt.BeginLoadData();
			dt.LoadDataRow(new object[] {null,"A","B"},false);

			try
			{
				//ConstraintException will be throw
				dt.EndLoadData();
				Assert.Fail("DT41: EndLoadData Failed to throw ConstraintException");
			}
			catch (ConstraintException) {}
			catch (AssertionException exc) {throw  exc;}
			catch (Exception exc)
			{
				Assert.Fail("DT42: EndLoadData Wrong exception type. Got:" + exc);
			}
		}

		[Test] public void GetChanges()
		{
			DataTable dt1,dt2 = DataProvider.CreateParentDataTable();
			dt2.Constraints.Add("Unique",dt2.Columns[0],true);
			dt2.Columns[0].DefaultValue=7;

			//make some changes
			dt2.Rows[0].Delete();
			dt2.Rows[1].Delete();
			dt2.Rows[2].Delete();
			dt2.Rows[3].Delete();

			dt1 = dt2.GetChanges();

			for (int i=0; i<dt2.Constraints.Count; i++)
			{
				// GetChanges - Constraints[{0}],i)
				Assert.AreEqual(dt2.Constraints[i].ConstraintName ,  dt1.Constraints[i].ConstraintName , "DT43");
			}

			for (int i=0; i<dt2.Columns.Count; i++)
			{
				// GetChanges - Columns[{0}].ColumnName,i)
				Assert.AreEqual(dt2.Columns[i].ColumnName ,  dt1.Columns[i].ColumnName  , "DT44");

				// GetChanges - Columns[{0}].DataType,i)
				Assert.AreEqual(dt2.Columns[i].DataType ,  dt1.Columns[i].DataType , "DT45");
			}

			DataRow[] drArr1,drArr2;

			drArr1 = dt1.Select("","",DataViewRowState.Deleted );
			drArr2 = dt2.Select("","",DataViewRowState.Deleted );

			for (int i=0; i<drArr1.Length ; i++)
			{
				// GetChanges - Data [ParentId]{0} ,i)
				Assert.AreEqual(drArr1[i]["ParentId",DataRowVersion.Original ],drArr2[i]["ParentId",DataRowVersion.Original], "DT46");
				// GetChanges - Data [String1]{0} ,i)
				Assert.AreEqual(drArr1[i]["String1", DataRowVersion.Original],drArr2[i]["String1",DataRowVersion.Original],  "DT47");
				// GetChanges - Data [String2]{0} ,i)
				Assert.AreEqual(drArr1[i]["String2", DataRowVersion.Original],drArr2[i]["String2",DataRowVersion.Original],  "DT48");
			}
		}

		[Test] public void GetChanges_ByDataRowState()
		{
			DataTable dt1,dt2 = DataProvider.CreateParentDataTable();
			dt2.Constraints.Add("Unique",dt2.Columns[0],true);
			dt2.Columns[0].DefaultValue=7;

			//make some changes
			dt2.Rows[0].Delete(); //DataRowState.Deleted 
			dt2.Rows[1].Delete(); //DataRowState.Deleted 
			dt2.Rows[2].BeginEdit();
			dt2.Rows[2]["String1"] = "Changed"; //DataRowState.Modified 
			dt2.Rows[2].EndEdit();

			dt2.Rows.Add(new object[] {"99","Temp1","Temp2"}); //DataRowState.Added 

			// *********** Checking GetChanges - DataRowState.Deleted ************
			dt1=null;
			dt1 = dt2.GetChanges(DataRowState.Deleted);
			CheckTableSchema (dt1,dt2,DataRowState.Deleted.ToString());
			DataRow[] drArr1,drArr2;
			drArr1 = dt1.Select("","",DataViewRowState.Deleted );
			drArr2 = dt2.Select("","",DataViewRowState.Deleted );

			for (int i=0; i<drArr1.Length ; i++)
			{
				// GetChanges(Deleted) - Data [ParentId]{0} ,i)
				Assert.AreEqual(drArr1[i]["ParentId",DataRowVersion.Original ],drArr2[i]["ParentId",DataRowVersion.Original],  "DT49");
				// GetChanges(Deleted) - Data [String1]{0} ,i)
				Assert.AreEqual(drArr1[i]["String1", DataRowVersion.Original],drArr2[i]["String1",DataRowVersion.Original],  "DT50");
				// GetChanges(Deleted) - Data [String2]{0} ,i)
				Assert.AreEqual(drArr1[i]["String2", DataRowVersion.Original],drArr2[i]["String2",DataRowVersion.Original],  "DT51");
			}

			// *********** Checking GetChanges - DataRowState.Modified ************
			dt1=null;
			dt1 = dt2.GetChanges(DataRowState.Modified);
			CheckTableSchema (dt1,dt2,DataRowState.Modified.ToString());
			drArr1 = dt1.Select("","");
			drArr2 = dt2.Select("","",DataViewRowState.ModifiedCurrent);

			for (int i=0; i<drArr1.Length ; i++)
			{
				// GetChanges(Modified) - Data [ParentId]{0} ,i)
				Assert.AreEqual(drArr2[i]["ParentId"], drArr1[i]["ParentId"], "DT52");
				// GetChanges(Modified) - Data [String1]{0} ,i)
				Assert.AreEqual(drArr2[i]["String1"], drArr1[i]["String1"], "DT53");
				// GetChanges(Modified) - Data [String2]{0} ,i)
				Assert.AreEqual(drArr2[i]["String2"], drArr1[i]["String2" ], "DT54");
			}

			// *********** Checking GetChanges - DataRowState.Added ************
			dt1=null;
			dt1 = dt2.GetChanges(DataRowState.Added);
			CheckTableSchema (dt1,dt2,DataRowState.Added.ToString());
			drArr1 = dt1.Select("","");
			drArr2 = dt2.Select("","",DataViewRowState.Added );

			for (int i=0; i<drArr1.Length ; i++)
			{
				// GetChanges(Added) - Data [ParentId]{0} ,i)
				Assert.AreEqual(drArr2[i]["ParentId"], drArr1[i]["ParentId"], "DT55");
				// GetChanges(Added) - Data [String1]{0} ,i)
				Assert.AreEqual(drArr2[i]["String1"], drArr1[i]["String1"], "DT56");
				// GetChanges(Added) - Data [String2]{0} ,i)
				Assert.AreEqual(drArr2[i]["String2"], drArr1[i]["String2" ], "DT57");
			}

			// *********** Checking GetChanges - DataRowState.Unchanged  ************
			dt1=null;
			dt1 = dt2.GetChanges(DataRowState.Unchanged);
			CheckTableSchema (dt1,dt2,DataRowState.Unchanged .ToString());
			drArr1 = dt1.Select("","");
			drArr2 = dt2.Select("","",DataViewRowState.Unchanged  );

			for (int i=0; i<drArr1.Length ; i++)
			{
				// GetChanges(Unchanged) - Data [ParentId]{0} ,i)
				Assert.AreEqual(drArr2[i]["ParentId"], drArr1[i]["ParentId"], "DT58");
				// GetChanges(Unchanged) - Data [String1]{0} ,i)
				Assert.AreEqual(drArr2[i]["String1"], drArr1[i]["String1"], "DT59");
				// GetChanges(Unchanged) - Data [String2]{0} ,i)
				Assert.AreEqual(drArr2[i]["String2"], drArr1[i]["String2" ], "DT60");
			}
		}

		private void CheckTableSchema(DataTable dt1, DataTable dt2,string Description)
		{
			for (int i=0; i<dt2.Constraints.Count; i++)
			{
				// GetChanges - Constraints[{0}] - {1},i,Description)
				Assert.AreEqual(dt2.Constraints[i].ConstraintName ,  dt1.Constraints[i].ConstraintName , "DT61");
			}

			for (int i=0; i<dt2.Columns.Count; i++)
			{
				// GetChanges - Columns[{0}].ColumnName - {1},i,Description)
				Assert.AreEqual(dt2.Columns[i].ColumnName ,  dt1.Columns[i].ColumnName  , "DT62");

				// GetChanges - Columns[{0}].DataType {1},i,Description)
				Assert.AreEqual(dt2.Columns[i].DataType ,  dt1.Columns[i].DataType , "DT63");
			}
		}

		[Test] public void GetErrors()
		{
			DataTable dt = DataProvider.CreateParentDataTable();
			DataRow[] drArr = new DataRow[3];
			drArr[0] = dt.Rows[0];
			drArr[1] = dt.Rows[2];
			drArr[2] = dt.Rows[5];

			drArr[0].RowError = "Error1";
			drArr[1].RowError = "Error2";
			drArr[2].RowError = "Error3";

			// GetErrors
			Assert.AreEqual(dt.GetErrors(), drArr , "DT64");
		}

		[Test] public new void GetHashCode()
		{
			DataTable dt = DataProvider.CreateParentDataTable();
			int iHashCode;
			iHashCode = dt.GetHashCode();        

			for (int i=0; i<10 ;i++)
			{
				// HashCode - i= + i.ToString()
				Assert.AreEqual(dt.GetHashCode()  , iHashCode , "DT65");
			}
		}

		[Test] public new void GetType()
		{
			DataTable dt = DataProvider.CreateParentDataTable();
			Type tmpType = typeof(DataTable);

			// GetType
			Assert.AreEqual(tmpType,  dt.GetType() , "DT66");
		}

		[Test] public void HasErrors()
		{
			DataTable dtParent;
			dtParent= DataProvider.CreateParentDataTable(); 

			// Checking HasErrors default 
			Assert.AreEqual(false, dtParent.HasErrors , "DT67");

			// Checking HasErrors Get 
			dtParent.Rows[0].RowError = "Error on row 0";
			dtParent.Rows[2].RowError = "Error on row 2";
			Assert.AreEqual(true, dtParent.HasErrors , "DT68");
		}

		[Test] public void ImportRow()
		{
			DataTable dt1,dt2;
			dt1 = DataProvider.CreateParentDataTable();
			dt2 = DataProvider.CreateParentDataTable();
			DataRow dr = dt2.NewRow();
			dr.ItemArray = new object[] {99,"",""};
			dt2.Rows.Add(dr);

			// ImportRow - Values
			dt1.ImportRow(dr);
			Assert.AreEqual(dr.ItemArray,  dt1.Rows[dt1.Rows.Count-1].ItemArray  , "DT69");

			// ImportRow - DataRowState
			Assert.AreEqual(dr.RowState ,  dt1.Rows[dt1.Rows.Count-1].RowState , "DT70");
		}

		[Test] public void LoadDataRow()
		{
			DataTable dt;
			DataRow dr;
			dt = DataProvider.CreateParentDataTable();
			dt.PrimaryKey= new DataColumn[] {dt.Columns[0]};	//add ParentId as Primary Key
			dt.Columns["String1"].DefaultValue = "Default";

			dr = dt.Select("ParentId=1")[0];

			//Update existing row without accept changes
			dt.BeginLoadData();
			dt.LoadDataRow(new object[] {1,null,"Changed"},false);
			dt.EndLoadData();

			// LoadDataRow(update1) - check column String1
			Assert.AreEqual(dr["String1"], dt.Columns["String1"].DefaultValue   , "DT71");

			// LoadDataRow(update1) - check column String2
			Assert.AreEqual(dr["String2"], "Changed", "DT72");

			// LoadDataRow(update1) - check row state
			Assert.AreEqual(DataRowState.Modified , dr.RowState , "DT73");

			//Update existing row with accept changes
			dr = dt.Select("ParentId=2")[0];

			dt.BeginLoadData();
			dt.LoadDataRow(new object[] {2,null,"Changed"},true);
			dt.EndLoadData();

			// LoadDataRow(update2) - check row state
			Assert.AreEqual(DataRowState.Unchanged  , dr.RowState , "DT74");

			//Add New row without accept changes
			dt.BeginLoadData();
			dt.LoadDataRow(new object[] {99,null,"Changed"},false);
			dt.EndLoadData();

			// LoadDataRow(insert1) - check column String2
			dr = dt.Select("ParentId=99")[0];
			Assert.AreEqual("Changed" , dr["String2"] , "DT75");

			// LoadDataRow(insert1) - check row state
			Assert.AreEqual(DataRowState.Added   , dr.RowState , "DT76");

			//Add New row with accept changes
			dt.BeginLoadData();
			dt.LoadDataRow(new object[] {100,null,"Changed"},true);
			dt.EndLoadData();

			// LoadDataRow(insert2) - check row and values
			dr = dt.Select("ParentId=100")[0];
			Assert.AreEqual("Changed" , dr["String2"] , "DT77");

			// LoadDataRow(insert2) - check row state
			Assert.AreEqual(DataRowState.Unchanged    , dr.RowState , "DT78");
		}

		[Test] public void Locale()
		{
			DataTable dtParent;
			DataSet ds = new DataSet("MyDataSet");

			dtParent= DataProvider.CreateParentDataTable(); 
			ds.Tables.Add(dtParent);
			System.Globalization.CultureInfo culInfo = System.Globalization.CultureInfo.CurrentCulture ;

			// Checking Locale default from system 
			Assert.AreEqual(culInfo, dtParent.Locale  , "DT79");

			// Checking Locale default from dataset 
			culInfo = new System.Globalization.CultureInfo("fr"); // = French
			ds.Locale = culInfo;
			Assert.AreEqual(culInfo , dtParent.Locale , "DT80");

			// Checking Locale get/set 
			culInfo = new System.Globalization.CultureInfo("fr"); // = French
			dtParent.Locale = culInfo ;
			Assert.AreEqual(culInfo , dtParent.Locale , "DT81");
		}

		[Test] public void MinimumCapacity()
		{
			//				i get default=50, according to MSDN the value should be 25 
			//				// Checking MinimumCapacity default = 25 
			//				Assert.AreEqual(25, dtParent.MinimumCapacity , "DT82");
			//				EndCase(null);
			DataTable dt = new DataTable();

			// Checking MinimumCapacity get/set int.MaxValue 
			dt.MinimumCapacity = int.MaxValue; 
			Assert.AreEqual(int.MaxValue, dt.MinimumCapacity  , "DT83");

			// Checking MinimumCapacity get/set 0
			dt.MinimumCapacity = 0; 
			Assert.AreEqual(0, dt.MinimumCapacity  , "DT84");

			//				// Checking MinimumCapacity get/set int.MinValue 
			//				dtParent.MinimumCapacity = int.MinValue ; 
			//				Assert.AreEqual(int.MinValue, dtParent.MinimumCapacity  , "DT85");
			//				EndCase(null);
		}

		[Test] public void Namespace()
		{
			DataTable dtParent = new DataTable();

			// Checking Namespace default
			Assert.AreEqual(String.Empty, dtParent.Namespace, "DT86");

			// Checking Namespace set/get
			String s = "MyNamespace";
			dtParent.Namespace=s;
			Assert.AreEqual(s, dtParent.Namespace, "DT87");
		}

		[Test] public void NewRow()
		{
			DataTable dt;
			DataRow dr;
			dt = DataProvider.CreateParentDataTable();

			// NewRow
			dr = dt.NewRow();
			Assert.AreEqual(true , dr != null , "DT88");
		}

		[Test] public void OnColumnChanged()
		{
			ProtectedTestClass dt = new ProtectedTestClass(); 

			EventRaised = false;
			dt.OnColumnChanged_Test();
			// OnColumnChanged Event 1
			Assert.AreEqual(false , EventRaised , "DT89");
			EventRaised = false;
			EventValues = false;
			dt.ColumnChanged += new DataColumnChangeEventHandler(OnColumnChanged_Handler);
			dt.OnColumnChanged_Test();
			// OnColumnChanged Event 2
			Assert.AreEqual(true , EventRaised , "DT90");
			// OnColumnChanged Values
			Assert.AreEqual(true , EventValues , "DT91");
			dt.ColumnChanged -= new DataColumnChangeEventHandler(OnColumnChanged_Handler);
		}

		private void OnColumnChanged_Handler(Object sender,DataColumnChangeEventArgs e)
		{
			DataTable dt = (DataTable)sender;
			if ( (e.Column.Equals(dt.Columns["Value"])	)	&&
				(e.Row.Equals(dt.Rows[0])				)	&&
				(e.ProposedValue.Equals("NewValue"))	)
			{
				EventValues = true;
			}
			else
			{
				EventValues = false;
			}
			EventRaised = true;
		}

		[Test] public void OnColumnChanging()
		{
			ProtectedTestClass dt = new ProtectedTestClass(); 

			EventRaised = false;
			dt.OnColumnChanging_Test();
			// OnColumnChanging Event 1
			Assert.AreEqual(false , EventRaised , "DT92");
			EventRaised = false;
			EventValues = false;
			dt.ColumnChanging  += new DataColumnChangeEventHandler(OnColumnChanging_Handler);
			dt.OnColumnChanging_Test();
			// OnColumnChanging Event 2
			Assert.AreEqual(true , EventRaised , "DT93");
			// OnColumnChanging Values
			Assert.AreEqual(true , EventValues , "DT94");
			dt.ColumnChanging -= new DataColumnChangeEventHandler(OnColumnChanging_Handler);
		}

		private void OnColumnChanging_Handler(Object sender,DataColumnChangeEventArgs e)
		{
			DataTable dt = (DataTable)sender;
			if ( (e.Column.Equals(dt.Columns["Value"])	)	&&
				(e.Row.Equals(dt.Rows[0])				)	&&
				(e.ProposedValue.Equals("NewValue"))	)
			{
				EventValues = true;
			}
			else
			{
				EventValues = false;
			}
			EventRaised = true;
		}

		[Test] public void OnRemoveColumn()
		{
			ProtectedTestClass dt = new ProtectedTestClass(); 

			// OnRemoveColumn 
			dt.OnRemoveColumn_Test();
		}

		[Test] public void ParentRelations()
		{
			DataTable dtChild,dtParent;
			DataSet ds = new DataSet();
			//Create tables
			dtChild = DataProvider.CreateChildDataTable();
			dtParent= DataProvider.CreateParentDataTable(); 
			//Add tables to dataset
			ds.Tables.Add(dtChild);
			ds.Tables.Add(dtParent);

			DataRelationCollection drlCollection;
			DataRelation drl = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);

			// Checking ParentRelations - default value
			//Check default
			drlCollection = dtChild.ParentRelations; 
			Assert.AreEqual(0, drlCollection.Count  , "DT96");

			ds.Relations.Add(drl);
			drlCollection = dtChild.ParentRelations; 

			// Checking ParentRelations Count
			Assert.AreEqual(1, drlCollection.Count  , "DT97");

			// Checking ParentRelations Value
			Assert.AreEqual(drl, drlCollection[0] , "DT98");
		}

		[Test] public void Prefix()
		{
			DataTable dtParent = new DataTable();

			// Checking Prefix default
			Assert.AreEqual(String.Empty, dtParent.Prefix , "DT99");

			// Checking Prefix set/get
			String s = "MyPrefix";
			dtParent.Prefix=s;
			Assert.AreEqual(s, dtParent.Prefix, "DT100");
		}

		[Test] public void RejectChanges()
		{
			String sNewValue = "NewValue";
			DataRow drModified,drDeleted,drAdded;
			DataTable dt = DataProvider.CreateParentDataTable();

			drModified = dt.Rows[0];
			drModified[1] = sNewValue; //DataRowState = Modified ,DataRowVersion = Proposed

			drDeleted = dt.Rows[1];
			drDeleted.Delete();		//DataRowState =  Deleted

			drAdded = dt.NewRow();			
			dt.Rows.Add(drAdded);	//DataRowState =  Added

			dt.RejectChanges();

			// RejectChanges - Unchanged1
			Assert.AreEqual(DataRowState.Unchanged , drModified.RowState  , "DT101");

			// RejectChanges - Unchanged2
			Assert.AreEqual(DataRowState.Detached , drAdded.RowState  , "DT102");

			// RejectChanges - Detached
			Assert.AreEqual(DataRowState.Unchanged   , drDeleted.RowState  , "DT103");
		}			

		[Test] public void Reset()
		{
			DataTable dt1 = DataProvider.CreateParentDataTable();
			DataTable dt2 = DataProvider.CreateChildDataTable();
			dt1.PrimaryKey  = new DataColumn[] {dt1.Columns[0]};
			dt2.PrimaryKey  = new DataColumn[] {dt2.Columns[0],dt2.Columns[1]};
			DataRelation rel = new DataRelation("Rel",dt1.Columns["ParentId"],dt2.Columns["ParentId"]);
			DataSet ds = new DataSet();
			ds.Tables.AddRange(new DataTable[] {dt1,dt2});
			ds.Relations.Add(rel);

			dt2.Reset();

			// Reset - ParentRelations
			Assert.AreEqual(0 , dt2.ParentRelations.Count  , "DT104");
			// Reset - Constraints
			Assert.AreEqual(0 , dt2.Constraints.Count  , "DT105");
			// Reset - Rows
			Assert.AreEqual(0 , dt2.Rows.Count  , "DT106");
			// Reset - Columns
			Assert.AreEqual(0 , dt2.Columns.Count  , "DT107");
		}

		[Test] public void RowChanged()
		{
			DataTable dt = DataProvider.CreateParentDataTable();

			dt.RowChanged += new DataRowChangeEventHandler ( Row_Changed );

			_EventTriggered=false;
			// RowChanged - 1
			dt.Rows[0][1] = "NewValue";
			Assert.AreEqual(true , _EventTriggered , "DT108");

			_EventTriggered=false;
			// RowChanged - 2
			dt.Rows[0].BeginEdit(); 
			dt.Rows[0][1] = "NewValue";
			Assert.AreEqual(false , _EventTriggered , "DT109");

			_EventTriggered=false;
			// RowChanged - 3
			dt.Rows[0].EndEdit();
			Assert.AreEqual(true , _EventTriggered , "DT110");

			_EventTriggered=false;
			dt.RowChanged -= new DataRowChangeEventHandler  ( Row_Changed );
			// RowChanged - 4
			dt.Rows[0][1] = "NewValue A";
			Assert.AreEqual(false , _EventTriggered , "DT111");
		}

		private void Row_Changed( object sender, DataRowChangeEventArgs e )
		{
			_EventTriggered = true;
		}

		[Test] public void RowChanging()
		{
			DataTable dt = DataProvider.CreateParentDataTable();

			dt.RowChanging  += new DataRowChangeEventHandler ( Row_Changing );

			_EventTriggered=false;
			// RowChanging - 1
			dt.Rows[0][1] = "NewValue";
			Assert.AreEqual(true , _EventTriggered , "DT112");

			_EventTriggered=false;
			// RowChanging - 2
			dt.Rows[0].BeginEdit(); 
			dt.Rows[0][1] = "NewValue";
			Assert.AreEqual(false , _EventTriggered , "DT113");

			_EventTriggered=false;
			// RowChanging - 3
			dt.Rows[0].EndEdit();
			Assert.AreEqual(true , _EventTriggered , "DT114");

			_EventTriggered=false;
			dt.RowChanging  -= new DataRowChangeEventHandler ( Row_Changing );
			// RowChanging - 4
			dt.Rows[0][1] = "NewValue A";
			Assert.AreEqual(false , _EventTriggered , "DT115");
		}

		private void Row_Changing( object sender, DataRowChangeEventArgs e )
		{
			_EventTriggered = true;
		}

		[Test] public void RowDeleted()
		{
			DataTable dt = DataProvider.CreateParentDataTable();

			dt.RowDeleted += new DataRowChangeEventHandler ( Row_Deleted );

			_EventTriggered=false;
			// RowDeleted - 1
			dt.Rows[0].Delete();
			Assert.AreEqual(true , _EventTriggered , "DT116");

			_EventTriggered=false;
			dt.RowDeleted -= new DataRowChangeEventHandler ( Row_Deleted );
			// RowDeleted - 2
			dt.Rows[1].Delete();
			Assert.AreEqual(false , _EventTriggered , "DT117");
		}

		private void Row_Deleted( object sender, DataRowChangeEventArgs e )
		{
			_EventTriggered = true;
		}

		[Test] public void RowDeleting()
		{
			DataTable dt = DataProvider.CreateParentDataTable();

			dt.RowDeleting  += new DataRowChangeEventHandler ( Row_Deleting );

			_EventTriggered=false;
			// RowDeleting - 1
			dt.Rows[0].Delete();
			Assert.AreEqual(true , _EventTriggered , "DT118");

			_EventTriggered=false;
			dt.RowDeleting  -= new DataRowChangeEventHandler ( Row_Deleting );
			// RowDeleting - 2
			dt.Rows[1].Delete();
			Assert.AreEqual(false , _EventTriggered , "DT119");
		}

		private void Row_Deleting( object sender, DataRowChangeEventArgs e )
		{
			_EventTriggered = true;
		}

		[Test] public void Rows()
		{
			DataTable dtParent;
			dtParent = DataProvider.CreateParentDataTable();

			// Checking Rows
			Assert.AreEqual(true, dtParent.Rows != null, "DT120");

			// Checking rows count
			Assert.AreEqual(true, dtParent.Rows.Count > 0 , "DT121");
		}

		[Test] public void Select()
		{
			DataTable dt = DataProvider.CreateParentDataTable();

			DataRow[] drSelect = dt.Select();
			DataRow[] drResult = new DataRow[dt.Rows.Count] ;
			dt.Rows.CopyTo(drResult,0);

			// Select

			Assert.AreEqual(drResult, drSelect , "DT122");
		}

		[Test] public void Select_ByFilter()
		{
			DataSet ds = new DataSet();
			ds.Tables.Add(DataProvider.CreateParentDataTable());

			DataTable dt = DataProvider.CreateChildDataTable();
			ds.Tables.Add(dt);
			DataRow[] drSelect = null;
			System.Collections.ArrayList al = new System.Collections.ArrayList();

			//add column with special name
			DataColumn dc = new DataColumn("Column#",typeof(int));
			dc.DefaultValue=-1;
			dt.Columns.Add(dc);
			//put some values
			dt.Rows[0][dc] = 100;
			dt.Rows[1][dc] = 200;
			dt.Rows[2][dc] = 300;
			dt.Rows[4][dc] = -400;

			//for trim function
			dt.Rows[0]["String1"] = dt.Rows[0]["String1"] + "   \t\n ";
			dt.Rows[0]["String1"] = "   \t\n " + dt.Rows[0]["String1"] ;
			dt.Rows[0]["String1"] = dt.Rows[0]["String1"] + "    ";

			ds.Tables[0].Rows[0]["ParentBool"] = DBNull.Value;
			ds.Tables[0].Rows[2]["ParentBool"] = DBNull.Value;
			ds.Tables[0].Rows[3]["ParentBool"] = DBNull.Value;

			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) 
			{
				if ((int)dr["ChildId"] == 1)
				{
					al.Add(dr);
				}
			}
			// Select_S - ChildId=1
			drSelect = dt.Select("ChildId=1");
			Assert.AreEqual(al.ToArray(), drSelect , "DT123");

			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) 
			{
				if ((int)dr["ChildId"] == 1)
				{
					al.Add(dr);
				}
			}
			// Select_S - ChildId='1'
			drSelect = dt.Select("ChildId='1'");
			Assert.AreEqual(al.ToArray(), drSelect , "DT124");
			//-------------------------------------------------------------
			// Select_S - ChildId= '1'  (whitespace in filter string.
			drSelect = dt.Select("ChildId= '1'");
			Assert.AreEqual(al.ToArray(), drSelect , "DT125");
			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) if (dr["String1"].ToString() == "1-String1") al.Add(dr);
			// Select_S - String1='1-String1'
			drSelect = dt.Select("String1='1-String1'");
			Assert.AreEqual(al.ToArray(), drSelect , "DT126");

			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) if ((int)dr["ChildId"] == 1 && dr["String1"].ToString() == "1-String1" ) al.Add(dr);
			// Select_S - ChildId=1 and String1='1-String1'
			drSelect = dt.Select("ChildId=1 and String1='1-String1'");
			Assert.AreEqual(al.ToArray(), drSelect , "DT127");

			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) if ((int)dr["ChildId"] + (int)dr["ParentId"] >= 4 ) al.Add(dr);
			// Select_S - ChildId+ParentId >= 4
			drSelect = dt.Select("ChildId+ParentId >= 4");
			CompareUnSorted(drSelect ,al.ToArray());

			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) 
			{
				if ((((int)dr["ChildId"] - (int)dr["ParentId"]) * -1) != 0 )
				{
					al.Add(dr);
				}
			}
			// Select_S - ChildId-ParentId) * -1  <> 0
			drSelect = dt.Select("(ChildId-ParentId) * -1  <> 0");
			CompareUnSorted(drSelect ,al.ToArray());

			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) if ( (double)dr["ChildDouble"] < ((int)dr["ParentId"]) % 4 ) al.Add(dr);
			// Select_S - ChildDouble < ParentId % 4
			drSelect = dt.Select("ChildDouble < ParentId % 4");
			CompareUnSorted(drSelect ,al.ToArray());

			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) if ( (double)dr["ChildDouble"] == 10 || (double)dr["ChildDouble"] == 20 || (double)dr["ChildDouble"] == 25 ) al.Add(dr);
			// Select_S - ChildDouble in (10,20,25)
			drSelect = dt.Select("ChildDouble in (10,20,25)");
			CompareUnSorted(drSelect ,al.ToArray());

			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) if ( dr["String2"].ToString().IndexOf("1-S") >= 0 ) al.Add(dr);
			// Select_S - String2 like '%1-S%'
			drSelect = dt.Select("String2 like '%1-S%'");
			Assert.AreEqual(al.ToArray(), drSelect , "DT128");

			//-------------------------------------------------------------
			//If a column name contains one of the above characters,(ex. #\/=><+-*%&|^'" and so on) the name must be wrapped in brackets. For example to use a column named "Column#" in an expression, you would write "[Column#]":
			al.Clear();
			foreach (DataRow dr in dt.Rows ) if ( (int)dr["Column#"] <= 0) al.Add(dr);
			// Select_S - [Column#] <= 0 
			drSelect = dt.Select("[Column#] <= 0 ");
			CompareUnSorted(drSelect ,al.ToArray());
			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) if ( (int)dr["Column#"] <= 0) al.Add(dr);
			// Select_S - [Column#] <= 0
			drSelect = dt.Select("[Column#] <= 0");
			CompareUnSorted(drSelect ,al.ToArray());

			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) if (((DateTime)dr["ChildDateTime"]).CompareTo(new DateTime(2000,12,12)) > 0  ) al.Add(dr);
			// Select_S - ChildDateTime > #12/12/2000# 
			drSelect = dt.Select("ChildDateTime > #12/12/2000# ");
			CompareUnSorted(drSelect ,al.ToArray());

			//-------------------------------------------------------------

			al.Clear();
			foreach (DataRow dr in dt.Rows ) if ( ((DateTime)dr["ChildDateTime"]).CompareTo(new DateTime(1999,1,12,12,06,30)) > 0  ) al.Add(dr);
			// Select_S - ChildDateTime > #1/12/1999 12:06:30 PM#  
			drSelect = dt.Select("ChildDateTime > #1/12/1999 12:06:30 PM#  ");
			CompareUnSorted(drSelect ,al.ToArray());

			//-------------------------------------------------------------

			al.Clear();
			foreach (DataRow dr in dt.Rows ) if ( ((DateTime)dr["ChildDateTime"]).CompareTo(new DateTime(2005,12,03,17,06,30)) >= 0  || ((DateTime)dr["ChildDateTime"]).CompareTo(new DateTime(1980,11,03)) <= 0 ) al.Add(dr);
			// Select_S - ChildDateTime >= #12/3/2005 5:06:30 PM# or ChildDateTime <= #11/3/1980#  
			drSelect = dt.Select("ChildDateTime >= #12/3/2005 5:06:30 PM# or ChildDateTime <= #11/3/1980#  ");
			CompareUnSorted(drSelect ,al.ToArray());

#if LATER
			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) if ( dr["ChildDouble"].ToString().Length > 10) al.Add(dr);
				// Select_S - Len(Convert(ChildDouble,'System.String')) > 10
				drSelect = dt.Select("Len(Convert(ChildDouble,'System.String')) > 10");
				Assert.AreEqual(al.ToArray(), drSelect , "DT129");
#endif
			//-------------------------------------------------------------
			al.Clear();
			foreach (DataRow dr in dt.Rows ) if ( dr["String1"].ToString().Trim().Substring(0,2) == "1-") al.Add(dr);
			// Select_S - SubString(Trim(String1),1,2) = '1-'
			drSelect = dt.Select("SubString(Trim(String1),1,2) = '1-'");
			Assert.AreEqual(al.ToArray(), drSelect , "DT130");
			//-------------------------------------------------------------
			/*
			al.Clear();
			foreach (DataRow dr in ds.Tables[0].Rows ) if ( dr.IsNull("ParentBool") || (bool)dr["ParentBool"]) al.Add(dr);
				// Select_S - IsNull(ParentBool,true)
				drSelect = ds.Tables[0].Select("IsNull(ParentBool,true) ");
				Assert.AreEqual(al.ToArray(), drSelect , "DT131");
			*/
			//-------------------------------------------------------------
			al.Clear();
			// Select_S - Relation not exists, Exception
			try
			{
				drSelect = dt.Select("Parent.ParentId = ChildId");
				Assert.Fail("DT132: Select Failed to throw IndexOutOfRangeException");
			}
			catch (IndexOutOfRangeException) {}
			catch (AssertionException exc) {throw  exc;}
			catch (Exception exc)
			{
				Assert.Fail("DT133: Select. Wrong exception type. Got:" + exc);
			}
			//-------------------------------------------------------------
			al.Clear();
			ds.Relations.Add(new DataRelation("ParentChild",ds.Tables[0].Columns[0],ds.Tables[1].Columns[0]));
			foreach (DataRow dr in dt.Rows ) if ( (int)dr["ChildId"] == (int)dr.GetParentRow("ParentChild")["ParentId"]) al.Add(dr);
			// Select_S - Parent.ParentId = ChildId
			drSelect = dt.Select("Parent.ParentId = ChildId");
			Assert.AreEqual(al.ToArray(), drSelect , "DT134");
		}

		private void CompareUnSorted(Array a, Array b)
		{
			string msg = string.Format("Failed while comparing(Array a ={0} ({1}), Array b = {2} ({3}))]", a.ToString(), a.GetType().FullName, b.ToString(), b.GetType().FullName);
			foreach (object item in a)
			{
				if (Array.IndexOf(b, item) < 0)	//b does not contain the current item.
				{
					Assert.Fail(msg);
				}
			}

			foreach (object item in b)
			{
				if (Array.IndexOf(a, item) < 0)	//a does not contain the current item.
				{
					Assert.Fail(msg);
					return;
				}
			}
		}

		[Test] public void Select_ByFilterDataViewRowState()
		{
			DataTable dt = DataProvider.CreateParentDataTable();
			DataRow[] drSelect, drResult;

			dt.Rows[0].Delete();
			dt.Rows[1]["ParentId"] = 1;
			dt.Rows[2]["ParentId"] = 1;
			dt.Rows[3].Delete();
			dt.Rows.Add(new object[] {1,"A","B"});
			dt.Rows.Add(new object[] {1,"C","D"});
			dt.Rows.Add(new object[] {1,"E","F"});

			drSelect = dt.Select("ParentId=1","",DataViewRowState.Added );
			drResult = GetResultRows(dt,DataRowState.Added);
			// Select_SSD DataViewRowState.Added
			Assert.AreEqual(drResult, drSelect , "DT135");

			drSelect = dt.Select("ParentId=1","",DataViewRowState.CurrentRows  );
			drResult = GetResultRows(dt,DataRowState.Unchanged | DataRowState.Added  | DataRowState.Modified );
			// Select_SSD DataViewRowState.CurrentRows
			Assert.AreEqual(drResult, drSelect , "DT136");

			drSelect = dt.Select("ParentId=1","",DataViewRowState.Deleted  );
			drResult = GetResultRows(dt,DataRowState.Deleted );
			// Select_SSD DataViewRowState.Deleted
			Assert.AreEqual(drResult, drSelect , "DT137");

			drSelect = dt.Select("ParentId=1","",DataViewRowState.ModifiedCurrent | DataViewRowState.ModifiedOriginal  );
			drResult = GetResultRows(dt,DataRowState.Modified );
			// Select_SSD ModifiedCurrent or ModifiedOriginal
			Assert.AreEqual(drResult, drSelect , "DT138");
		}

		private DataRow[] GetResultRows(DataTable dt,DataRowState State)
		{
			System.Collections.ArrayList al = new System.Collections.ArrayList();
			DataRowVersion drVer = DataRowVersion.Current;

			//From MSDN -	The row the default version for the current DataRowState.
			//				For a DataRowState value of Added, Modified or Current, 
			//				the default version is Current. 
			//				For a DataRowState of Deleted, the version is Original.
			//				For a DataRowState value of Detached, the version is Proposed.

			if (	((State & DataRowState.Added)		> 0)  
				| ((State & DataRowState.Modified)	> 0)  
				| ((State & DataRowState.Unchanged)	> 0) ) 
				drVer = DataRowVersion.Current;
			if ( (State & DataRowState.Deleted)		> 0
				| (State & DataRowState.Detached)	> 0 )  
				drVer = DataRowVersion.Original; 

			foreach (DataRow dr in dt.Rows )
			{
				if ( dr.HasVersion(drVer) 
					&& ((int)dr["ParentId", drVer] == 1) 
					&& ((dr.RowState & State) > 0 ) 
					)
					al.Add(dr);
			}
			DataRow[] result = (DataRow[])al.ToArray((typeof(DataRow)));
			return result; 
		}	

		[Test] public void TableName()
		{
			DataTable dtParent = new DataTable();

			// Checking TableName default
			Assert.AreEqual(String.Empty, dtParent.TableName, "DT139");

			// Checking TableName set/get
			String s = "MyTable";
			dtParent.TableName=s;
			Assert.AreEqual(s, dtParent.TableName, "DT140");
		}

		[Test] public new void  ToString() 
		{
			DataTable dt = DataProvider.CreateParentDataTable();
			dt.DisplayExpression = dt.Columns[0].ColumnName ;

			string sToString = dt.TableName + " + " + dt.DisplayExpression;
			// ToString
			Assert.AreEqual(sToString , dt.ToString() , "DT141");
		}

		[Test] public void caseSensitive()
		{
			DataTable dtParent = new DataTable();

			// Checking default
			Assert.AreEqual(false, dtParent.CaseSensitive  , "DT142");

			// Checking set/get
			dtParent.CaseSensitive = true;
			Assert.AreEqual(true, dtParent.CaseSensitive , "DT143");
		}

		[Test] public void ctor()
		{
			DataTable dt;
			dt = new DataTable();

			// ctor
			Assert.AreEqual(false, dt == null, "DT144");
		}

		[Test] public void ctor_ByName()
		{
			DataTable dt;
			string sName = "MyName";

			dt = new DataTable(sName);

			// Ctor
			Assert.AreEqual(false , dt == null , "DT145");

			// Ctor TableName
			Assert.AreEqual(sName , dt.TableName , "DT146");
		}

		[Test] public void displayExpression()
		{
			DataTable dtParent;
			dtParent= DataProvider.CreateParentDataTable(); 

			// Checking DisplayExpression default 
			Assert.AreEqual(String.Empty , dtParent.DisplayExpression , "DT147");

			// Checking DisplayExpression Set/Get 
			dtParent.DisplayExpression = dtParent.Columns[0].ColumnName;
			Assert.AreEqual(dtParent.Columns[0].ColumnName, dtParent.DisplayExpression  , "DT148");
		}

		[Test] public void extendedProperties()
		{
			DataTable dtParent;
			PropertyCollection pc;
			dtParent= DataProvider.CreateParentDataTable(); 

			pc = dtParent.ExtendedProperties ;

			// Checking ExtendedProperties default 
			Assert.AreEqual(true, pc != null, "DT149");

			// Checking ExtendedProperties count 
			Assert.AreEqual(0, pc.Count , "DT150");
		}

		[Test] public void primaryKey()
		{
			DataTable dtParent;
			dtParent = DataProvider.CreateParentDataTable();

			// Checking PrimaryKey default
			Assert.AreEqual(0, dtParent.PrimaryKey.Length , "DT151");

			// Checking PrimaryKey set/get
			DataColumn[] dcArr = new DataColumn[] {dtParent.Columns[0]}; 
			dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns[0]};
			Assert.AreEqual(dcArr, dtParent.PrimaryKey  , "DT152");

			dtParent.PrimaryKey=null;
			DataSet ds = new DataSet();
			DataRow dr = null;
			ds.Tables.Add(dtParent);

			//check primary key - ColumnType String, ds.CaseSensitive = false;
			ds.CaseSensitive = false;
			dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns["String1"]};
			// check primary key - ColumnType String, ds.CaseSensitive = false;
			dr = dtParent.NewRow();
			dr.ItemArray = dtParent.Rows[0].ItemArray;
			dr["String1"] = dr["String1"].ToString().ToUpper();  
			try
			{
				dtParent.Rows.Add(dr);
				Assert.Fail("DT153: Rows.Add Failed to throw ConstraintException");
			}
			catch (ConstraintException) {}
			catch (AssertionException exc) {throw  exc;}
			catch (Exception exc)
			{
				Assert.Fail("DT154: Rows.Add. Wrong exception type. Got:" + exc);
			}
			if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);

			//check primary key - ColumnType String, ds.CaseSensitive = true;		
			ds.CaseSensitive = true;
			// check primary key ConstraintException - ColumnType String, ds.CaseSensitive = true;
			dr = dtParent.NewRow();
			dr.ItemArray = dtParent.Rows[0].ItemArray;
			dr["String1"] = dr["String1"].ToString();  
			try
			{
				dtParent.Rows.Add(dr);
				Assert.Fail("DT155: Rows.Add Failed to throw ConstraintException");
			}
			catch (ConstraintException) {}
			catch (AssertionException exc) {throw  exc;}
			catch (Exception exc)
			{
				Assert.Fail("DT156: Rows.Add. Wrong exception type. Got:" + exc);
			}
			if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);

			//check primary key - ColumnType String, ds.CaseSensitive = true;		
			ds.CaseSensitive = true;

			// check primary key - ColumnType String, ds.CaseSensitive = true;
			dr = dtParent.NewRow();
			dr.ItemArray = dtParent.Rows[0].ItemArray;
			dr["String1"] = dr["String1"].ToString().ToUpper() ;  
			dtParent.Rows.Add(dr);
			Assert.AreEqual(true, dtParent.Rows.Contains(dr["String1"]), "DT157");

			if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);

			dtParent.PrimaryKey=null;
			dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns["ParentDateTime"]};
			// check primary key - ColumnType DateTime
			dr = dtParent.NewRow();
			dr.ItemArray = dtParent.Rows[0].ItemArray;
			dr["ParentDateTime"] = DateTime.Now;
			dtParent.Rows.Add(dr);
			Assert.AreEqual(true, dtParent.Rows.Contains(dr["ParentDateTime"]), "DT158");
			if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);

			// check primary key ConstraintException- ColumnType DateTime
			dr = dtParent.NewRow();
			dr.ItemArray = dtParent.Rows[0].ItemArray;
			dr["ParentDateTime"] = dtParent.Rows[0]["ParentDateTime"];
			try
			{
				dtParent.Rows.Add(dr);
				Assert.Fail("DT159: Rows.Add Failed to throw ConstraintException");
			}
			catch (ConstraintException) {}
			catch (AssertionException exc) {throw  exc;}
			catch (Exception exc)
			{
				Assert.Fail("DT160: Rows.Add. Wrong exception type. Got:" + exc);
			}
			if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);

			dtParent.PrimaryKey=null;
			dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns["ParentDouble"]};
			// check primary key - ColumnType ParentDouble, value=Epsilon
			dr = dtParent.NewRow();
			dr.ItemArray = dtParent.Rows[0].ItemArray;
			dr["ParentDouble"] = Double.Epsilon ;
			dtParent.Rows.Add(dr);
			Assert.AreEqual(true, dtParent.Rows.Contains(dr["ParentDouble"]), "DT161");
			if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);

			// check primary key ConstraintException - ColumnType ParentDouble
			dr = dtParent.NewRow();
			dr.ItemArray = dtParent.Rows[0].ItemArray;
			dr["ParentDouble"] = dtParent.Rows[0]["ParentDouble"];
			try
			{
				dtParent.Rows.Add(dr);
				Assert.Fail("DT162: Rows.Add Failed to throw ConstraintException");
			}
			catch (ConstraintException) {}
			catch (AssertionException exc) {throw  exc;}
			catch (Exception exc)
			{
				Assert.Fail("DT163: Rows.Add. Wrong exception type. Got:" + exc);
			}
			if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);

			//
			// SubTest
			//
			dtParent.PrimaryKey=null;
			// check primary key ConstraintException - ColumnType ParentBool 
			try
			{
				//ParentBool is not unique, will raise exception
				dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns["ParentBool"]};
				Assert.Fail("DT164: PrimaryKey Failed to throw ArgumentException");
			}
			catch (ArgumentException) {}
			catch (AssertionException exc) {throw  exc;}
			catch (Exception exc)
			{
				Assert.Fail("DT165: PrimaryKey. Wrong exception type. Got:" + exc);
			}
			if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);

			//
			// SubTest
			//
			dtParent.PrimaryKey=null;
			dtParent.PrimaryKey = new DataColumn[] {dtParent.Columns["ParentDouble"],dtParent.Columns["ParentDateTime"]};
			// check primary key - ColumnType Double,DateTime test1
			dr = dtParent.NewRow();
			dr.ItemArray = dtParent.Rows[0].ItemArray;
			dr["ParentDouble"] = dtParent.Rows[0]["ParentDouble"];
			dr["ParentDateTime"] = DateTime.Now;
			dtParent.Rows.Add(dr);
			Assert.AreEqual(true, dtParent.Rows.Contains(new object[] {dr["ParentDouble"],dr["ParentDateTime"]}), "DT166");
			if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);

			// check primary key - ColumnType Double,DateTime test2
			dr = dtParent.NewRow();
			dr.ItemArray = dtParent.Rows[0].ItemArray;
			dr["ParentDateTime"] = dtParent.Rows[0]["ParentDateTime"];
			dr["ParentDouble"] = 99.399;
			dtParent.Rows.Add(dr);
			Assert.AreEqual(true, dtParent.Rows.Contains(new object[] {dr["ParentDouble"],dr["ParentDateTime"]}), "DT167");
			if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);

			// check primary key ConstraintException - ColumnType Double,DateTime 
			dr = dtParent.NewRow();
			dr.ItemArray = dtParent.Rows[0].ItemArray;
			dr["ParentDouble"] = dtParent.Rows[0]["ParentDouble"];
			dr["ParentDateTime"] = dtParent.Rows[0]["ParentDateTime"];
			try
			{
				dtParent.Rows.Add(dr);
				Assert.Fail("DT168: Rows.Add Failed to throw ConstraintException");
			}
			catch (ConstraintException) {}
			catch (AssertionException exc) {throw  exc;}
			catch (Exception exc)
			{
				Assert.Fail("DT169: Rows.Add. Wrong exception type. Got:" + exc);
			}
			if (dr.RowState != DataRowState.Detached) dtParent.Rows.Remove(dr);

			DataTable dtChild = DataProvider.CreateChildDataTable();
			ds.Tables.Add(dtChild);
			dtParent.PrimaryKey = null;
			//this test was addedd to check java exception: 
			//System.ArgumentException: Cannot remove UniqueConstraint because the ForeignKeyConstraint myRelation exists.
			// check add primary key with relation 
			ds.Relations.Add(new DataRelation("myRelation",ds.Tables[0].Columns[0],ds.Tables[1].Columns[0]));
			//the following line will cause java to fail
			ds.Tables[0].PrimaryKey = new DataColumn[] {ds.Tables[0].Columns[0],ds.Tables[0].Columns[1]}; 
			Assert.AreEqual(2, ds.Tables[0].PrimaryKey.Length , "DT170");
		}
	
		// Test for bug #76213
		[Test]
		public void Compute_WithoutSchemaData_Test()
		{
                        DataSet ds = new DataSet ("TestData");
                        DataTable table = ds.Tables.Add ("TestTable");

                        table.Columns.Add ("Id");
                        table.Columns.Add ("Value");

                        table.Rows.Add (new object[] {"1","4.5"});
                        table.Rows.Add (new object[] {"2","7.5"});
                        table.Rows.Add (new object[] {"3","2.5"});
                        table.Rows.Add (new object[] {"4","3.5"});
			
			Assert.AreEqual ("1",
				 table.Compute ("Min(Id)",String.Empty),"#1");	
			Assert.AreEqual ("4",
				 table.Compute ("Max(Id)",String.Empty),"#2");	
			Assert.AreEqual ("2.5",
				 table.Compute ("Min(Value)",String.Empty),"#3");	
			Assert.AreEqual ("7.5",
				 table.Compute ("Max(Value)",String.Empty),"#4");	
		}

		[Test]
		public void BeginLoadData()
		{
			DataTable dt = DataProvider.CreateParentDataTable();
			dt.Columns[0].AllowDBNull = false;
			       
			//dt.BeginLoadData();
			try
			{
				//if BeginLoadData has not been called, an exception will be throw
				dt.LoadDataRow(new object[] {null,"A","B"},false);
				Assert.Fail("DT170: Failed to throw NoNullAllowedException");
			}
			catch (NoNullAllowedException) {}
			catch (AssertionException exc) {throw  exc;}
			catch (Exception exc)
			{
				Assert.Fail("DT171: Wrong exception type. Got:" + exc);
			}


			DataTable dt1 = DataProvider.CreateUniqueConstraint();

			bool excptionOccurd = false;

			try
			{
				dt1.BeginLoadData();

				DataRow  dr = dt1.NewRow();
				dr[0] = 3;
				dt1.Rows.Add(dr);
				dt1.EndLoadData(); // constraint violation

				Assert.Fail("DT172: Failed to throw ConstraintException");
			}
			catch (ConstraintException) 
			{
				Assert.AreEqual(2,dt1.GetErrors().Length,"DT173");
				Assert.AreEqual(true,dt1.GetErrors()[0].RowError.Length > 10,"DT174");
				Assert.AreEqual(true,dt1.GetErrors()[1].RowError.Length > 10,"DT175");
			}
			catch (AssertionException exc) {throw  exc;}
			catch (Exception exc)
			{
				Assert.Fail("DT176: Wrong exception type. Got:" + exc);
			}
			

			DataSet ds=null;
			excptionOccurd = false;
			try
			{
				ds= DataProvider.CreateForigenConstraint();
				ds.Tables[0].BeginLoadData();
				ds.Tables[0].Rows[0][0] = 10; //Forigen constraint violation
				//ds.Tables[0].AcceptChanges();
				ds.Tables[0].EndLoadData();

				Assert.Fail("DT177: Failed to throw ConstraintException");
			}
			catch (ConstraintException) 
			{
				Assert.AreEqual(3,ds.Tables[1].GetErrors().Length,"DT178");
				for(int index=0;index<3;index++)
				{
					Assert.AreEqual(true,ds.Tables[1].GetErrors()[index].RowError.Length > 10,"DT179");
				}
			}
			catch (AssertionException exc) {throw  exc;}
			catch (Exception exc)
			{
				Assert.Fail("DT180: Wrong exception type. Got:" + exc);
			}
		}

		private DataRowAction drExpectedAction;
		
		public void OnRowChanged()
		{
			ProtectedTestClass dt = new ProtectedTestClass(); 

			EventRaised = false;
			dt.OnRowChanged_Test(DataRowAction.Nothing );
			
			Assert.IsFalse(EventRaised ,"DT181" );

			dt.RowChanged += new DataRowChangeEventHandler(OnRowChanged_Handler);
			foreach (int i in Enum.GetValues(typeof(DataRowAction)))
			{
				EventRaised = false;
				EventValues = false;
				drExpectedAction = (DataRowAction)i;
				dt.OnRowChanged_Test(drExpectedAction);
	            
				Assert.IsTrue(EventRaised ,"DT182" );

				Assert.IsTrue(EventValues  ,"DT183" );
			}
			dt.RowChanged -= new DataRowChangeEventHandler(OnRowChanged_Handler);
		}

		private void OnRowChanged_Handler(Object sender,DataRowChangeEventArgs e)
		{
			
			DataTable dt = (DataTable)sender;
			if (dt.Rows[0].Equals(e.Row) && e.Action == drExpectedAction)
				EventValues = true;
			EventRaised = true;
		}

		[Test]
		public void OnRowChanging()
		{
			ProtectedTestClass dt = new ProtectedTestClass(); 

			EventRaised = false;
			dt.OnRowChanging_Test(DataRowAction.Nothing );
			
			Assert.IsFalse(EventRaised ,"DT184" );

			dt.RowChanging += new DataRowChangeEventHandler(OnRowChanging_Handler);
			foreach (int i in Enum.GetValues(typeof(DataRowAction)))
			{
				EventRaised = false;
				EventValues = false;
				drExpectedAction = (DataRowAction)i;
				dt.OnRowChanging_Test(drExpectedAction);
	            
				Assert.IsTrue(EventRaised ,"DT185" );
				
				Assert.IsTrue(EventValues  ,"DT186" );
			}
			dt.RowChanging -= new DataRowChangeEventHandler(OnRowChanging_Handler);
		}

		private void OnRowChanging_Handler(Object sender,DataRowChangeEventArgs e)
		{
			
			DataTable dt = (DataTable)sender;
			if (dt.Rows[0].Equals(e.Row) && e.Action == drExpectedAction)
				EventValues = true;
			EventRaised = true;
		}

		[Test]
		public void OnRowDeleted()
		{
			ProtectedTestClass dt = new ProtectedTestClass(); 

			EventRaised = false;
			dt.OnRowDeleted_Test(DataRowAction.Nothing );

			Assert.IsFalse(EventRaised ,"DT187" );

			dt.RowDeleted += new DataRowChangeEventHandler(OnRowDeleted_Handler);
			foreach (int i in Enum.GetValues(typeof(DataRowAction)))
			{
				EventRaised = false;
				EventValues = false;
				drExpectedAction = (DataRowAction)i;
				dt.OnRowDeleted_Test(drExpectedAction);

				Assert.IsTrue(EventRaised ,"DT188" );
				
				Assert.IsTrue(EventValues  ,"DT189" );
			}
			dt.RowDeleted -= new DataRowChangeEventHandler(OnRowDeleted_Handler);
		}


		private void OnRowDeleted_Handler(Object sender,DataRowChangeEventArgs e)
		{
			DataTable dt = (DataTable)sender;
			if (dt.Rows[0].Equals(e.Row) && e.Action == drExpectedAction)
				EventValues = true;
			EventRaised = true;
		}

		public void OnRowDeleting()
		{
			ProtectedTestClass dt = new ProtectedTestClass(); 

			EventRaised = false;
			dt.OnRowDeleting_Test(DataRowAction.Nothing );

			Assert.IsFalse(EventRaised ,"DT190" );

			dt.RowDeleting += new DataRowChangeEventHandler(OnRowDeleting_Handler);
			foreach (int i in Enum.GetValues(typeof(DataRowAction)))
			{
				EventRaised = false;
				EventValues = false;
				drExpectedAction = (DataRowAction)i;
				dt.OnRowDeleting_Test(drExpectedAction);
	            
				Assert.IsTrue(EventRaised ,"DT191" );
				
				Assert.IsTrue(EventValues  ,"DT192" );
			}
			dt.RowDeleting -= new DataRowChangeEventHandler(OnRowDeleting_Handler);
		}

		[Test]
		public void BeginInit_PrimaryKey_1 ()
		{
			DataTable table = new DataTable ();
			DataColumn col = table.Columns.Add ("col", typeof (int));
			table.PrimaryKey = new DataColumn[] {col};
			table.AcceptChanges ();
			Assert.AreEqual (1, table.PrimaryKey.Length, "#1");
		
			table.BeginInit ();
			DataColumn col2 = new DataColumn ("col2", typeof (int));
			table.Columns.AddRange (new DataColumn[] {col2});
			table.PrimaryKey = new DataColumn[] {col2};
			table.EndInit ();
			Assert.AreEqual (1, table.PrimaryKey.Length, "#2");
			Assert.AreEqual ("col2", table.PrimaryKey[0].ColumnName, "#3");
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void BeginInit_PrimaryKey_2()
		{
			DataTable table = new DataTable ();
			DataColumn col = table.Columns.Add ("col", typeof (int));
			table.PrimaryKey = new DataColumn[] {col};
			table.AcceptChanges ();
	
			// ms.net behavior.	
			table.BeginInit ();
			DataColumn col1 = new DataColumn ("col1", typeof (int));
			table.Columns.AddRange (new DataColumn[] {col1});
			UniqueConstraint uc = new UniqueConstraint ("", new String[] {"col1"}, true);
			table.Constraints.AddRange (new Constraint[] {uc});
			table.EndInit ();
		}

		[Test]
		public void BeginInit_PrimaryKey_3 ()
		{
			DataTable table = new DataTable ();
			DataColumn col1 = table.Columns.Add ("col1", typeof (int));
			DataColumn col2 = table.Columns.Add ("col2", typeof (int));
		
			// ms.net behavior
			table.BeginInit ();
			UniqueConstraint uc = new UniqueConstraint ("", new String[] {"col1"}, true);
			table.Constraints.AddRange (new Constraint[] {uc});
			table.PrimaryKey = new DataColumn [] {col2};
			table.EndInit ();

			Assert.AreEqual ("col1", table.PrimaryKey[0].ColumnName, "#1");
		}
		
		[Test]
		public void PrimaryKey_OnFailing ()
		{
			DataTable table = new DataTable ();
			DataColumn col1 = table.Columns.Add ("col1", typeof (int));
			table.PrimaryKey = new DataColumn[] {col1};
			try {
				table.PrimaryKey  = new DataColumn[] { new DataColumn ("col2", typeof (int))};
			} catch (Exception e) {}
			Assert.AreEqual ("col1", table.PrimaryKey[0].ColumnName, "#1");
		}

		[Test]
		public void BeginInit_Cols_Constraints ()
		{
			DataTable table = new DataTable ();

			// if both cols and constraints are added after BeginInit, the cols
			// should be added, before the constraints are added/validated
			table.BeginInit ();
			DataColumn col1 = new DataColumn ("col1", typeof (int));
			table.Columns.AddRange (new DataColumn[] {col1});
			UniqueConstraint uc = new UniqueConstraint ("", new String[] {"col1"}, false);
			table.Constraints.AddRange (new Constraint[] {uc});
			// no exception shud be thrown
			table.EndInit ();

			Assert.AreEqual (1, table.Constraints.Count, "#1");
		}

		private void OnRowDeleting_Handler(Object sender,DataRowChangeEventArgs e)
		{
			
			DataTable dt = (DataTable)sender;
			if (dt.Rows[0].Equals(e.Row) && e.Action == drExpectedAction)
				EventValues = true;
			EventRaised = true;
		}

		[Test]
		public void Select_StringString()
		{
        	DataTable dt = DataProvider.CreateChildDataTable();
	        
			DataRow[] drSelect;
			System.Collections.ArrayList al;

			//add some rows
			dt.Rows.Add(new object[] {99,88,"bla","wowww"});
			dt.Rows.Add(new object[] {999,888,"","woowww"});

			//get excepted resault
			al = new System.Collections.ArrayList();
			foreach (DataRow dr in dt.Rows )
			{
				if ((int)dr["ChildId"] == 1)
					al.Add(dr);
			}
			//al.Reverse();
			al.Sort(new DataRowsComparer("ParentId", "Desc"));

			drSelect = dt.Select("ChildId=1","ParentId Desc");
			Assert.AreEqual(al.ToArray(),drSelect ,"DT193");


			//get excepted resault
			al = new System.Collections.ArrayList();
			foreach (DataRow dr in dt.Rows )
			{
				if (dr["String1"].ToString() == "1-String1")
					al.Add(dr);
			}
			//al.Reverse();
			al.Sort(new DataRowsComparer("ParentId", "Desc"));

			drSelect = dt.Select("String1='1-String1'","ParentId Desc");
			Assert.AreEqual(al.ToArray(),drSelect ,"DT194");
			

			//get excepted resault
			al = new System.Collections.ArrayList();
			foreach (DataRow dr in dt.Rows )
			{
				if ((int)dr["ChildId"] == 1 && dr["String1"].ToString() == "1-String1")
					al.Add(dr);
			}
			//al.Reverse();
			al.Sort(new DataRowsComparer("ParentId", "Desc"));

			drSelect = dt.Select("ChildId=1 and String1='1-String1'","ParentId Desc");
			Assert.AreEqual(al.ToArray(),drSelect ,"DT195");
			

			//get excepted resault
			al = new System.Collections.ArrayList();
			foreach (DataRow dr in dt.Rows )
			{
				if (dr["String1"].ToString().Length < 4 )
					al.Add(dr);
			}
			//al.Reverse();
			al.Sort(new DataRowsComparer("ParentId", "Desc"));

			drSelect = dt.Select("Len(String1) < 4 ","ParentId Desc");
			Assert.AreEqual(al.ToArray(),drSelect ,"DT196");
			

			//get excepted resault
			al = new System.Collections.ArrayList();
			foreach (DataRow dr in dt.Rows )
			{
				if ( dr["String1"].ToString().IndexOf("String") > 0 )
					al.Add(dr);
			}
			//al.Reverse();
			al.Sort(new DataRowsComparer("ParentId", "Desc"));

			drSelect = dt.Select("String1 like '%%String*'  ","ParentId Desc");
			Assert.AreEqual(al.ToArray(),drSelect ,"DT197");
			

			//get excepted resault
			al = new System.Collections.ArrayList();
			foreach (DataRow dr in dt.Rows )
			{
				if (((int)dr["ChildId"] == 2) || ((int)dr["ChildId"] == 3))
					al.Add(dr);
			}
			//al.Reverse();
			al.Sort(new DataRowsComparer("ParentId", "Desc"));

			drSelect = dt.Select("ChildId in (2,3)  ","ParentId Desc");
			Assert.AreEqual(al.ToArray(),drSelect ,"DT198");
			

			//get excepted resault
			al = new System.Collections.ArrayList();
			foreach (DataRow dr in dt.Rows )
			{
				if ((((int)dr["ChildId"] * (int)dr["ParentId"]) > 5 ))
					al.Add(dr);
			}
			al.Sort(new DataRowsComparer("ChildId", "Asc"));

			drSelect = dt.Select("ChildId * ParentId > 5 ","ChildId Asc");
			// Cannot check this way as ArrayList.Sort uses unstable sort and 
			// so the Order of the elements is not preserved when elements are equal
			//Assert.AreEqual(al.ToArray(),drSelect ,"DT199");
			Assert.AreEqual (al.Count, drSelect.Length, "#DT199");
			for (int i=0; i<al.Count; ++i){
				// check the datarow is present and that the sort order is correct
				Assert.IsTrue (Array.IndexOf (drSelect, al[i]) != -1, "#DT_199_2_"+i);
				Assert.AreEqual ( ((DataRow)al[i])["ChildId"], drSelect[i]["ChildId"], "#DT_199_1" +i);
			}

			//get excepted resault
			al = new System.Collections.ArrayList();
			foreach (DataRow dr in dt.Rows )
			{
				if (dr["String2"].ToString().Substring(2,3) == "Str" )
					al.Add(dr);
			}
			al.Sort(new DataRowsComparer("ParentId", "Desc"));

			drSelect = dt.Select("SubString(String2,3,3) like 'Str' ","ParentId Desc");
			Assert.AreEqual(al.ToArray(),drSelect ,"DT200");
		}

		[Test]
		[ExpectedException(typeof(ArgumentException))]
#if !TARGET_JVM
		[Category ("NotWorking")]
#endif
		public void Select_StringString_2()
		{
			DataTable dt = DataProvider.CreateParentDataTable();
			//Checking the parsing of the sort string
			dt.Select(dt.Columns[0].ColumnName + "=1","[x");
		}

		[Test]
		[ExpectedException(typeof(IndexOutOfRangeException))]
		public void Select_StringString_3()
		{	
			DataTable dt = DataProvider.CreateParentDataTable();
			//Select - parse sort string checking 1");
			dt.Select(dt.Columns[0].ColumnName,dt.Columns[0].ColumnName + "1");
		}

		internal class DataRowsComparer : System.Collections.IComparer
		{
			#region Memebers
			private string _columnName;
			private string _direction;
			#endregion

			#region Constructors
			public DataRowsComparer(string columnName, string direction)
			{
				_columnName = columnName;
				if (direction.ToLower() != "asc" && direction.ToLower() != "desc")
				{
					throw new ArgumentException("Direction can only be one of: 'asc' or 'desc'");
				}
				_direction = direction;
			}
			#endregion

			#region IComparer Members

			public int Compare(object x, object y)
			{
				DataRow drX = (DataRow)x;
				DataRow drY = (DataRow)y;

				object objX = drX[_columnName];
				object objY = drY[_columnName];

				int compareResult = System.Collections.Comparer.Default.Compare(objX, objY);

				//If we are comparing desc we need to reverse the result.
				if (_direction.ToLower() == "desc")
				{
					compareResult = -compareResult;
				}

				return compareResult;

			}

			#endregion

		}
	}
}