New test.
[mono.git] / mcs / class / System.Data / Test / System.Data / DataRowTest2.cs
1 // Authors:
2 //   Rafael Mizrahi   <rafim@mainsoft.com>
3 //   Erez Lotan       <erezl@mainsoft.com>
4 //   Oren Gurfinkel   <oreng@mainsoft.com>
5 //   Ofer Borstein
6 // 
7 // Copyright (c) 2004 Mainsoft Co.
8 // 
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using NUnit.Framework;
30 using System;
31 using System.IO;
32 using System.ComponentModel;
33 using System.Data;
34 using MonoTests.System.Data.Utils;
35
36 namespace MonoTests.System.Data
37 {
38         [TestFixture] public class DataRowTest2
39         {
40                 bool _rowChanged;
41
42                 [SetUp]
43                 public void SetUp ()
44                 {
45                         _rowChanged = false;
46                 }
47
48                 [Test] public void AcceptChanges()
49                 {
50                         DataTable myTable = new DataTable("myTable"); 
51                         DataRow myRow;
52                         myRow = myTable.NewRow();
53                         myTable.Rows.Add(myRow);
54
55                         // DataRow AcceptChanges
56                         // DataRowState.Added -> DataRowState.Unchanged 
57                         myTable.AcceptChanges();
58                         Assert.AreEqual(DataRowState.Unchanged , myRow.RowState , "DRW1");
59                 }
60
61                 [Test] public void CancelEdit()
62                 {
63                         DataTable myTable = new DataTable("myTable"); 
64                         DataColumn dc = new DataColumn("Id",typeof(int));
65                         dc.Unique=true;
66                         myTable.Columns.Add(dc);
67                         myTable.Rows.Add(new object[] {1});
68                         myTable.Rows.Add(new object[] {2});
69                         myTable.Rows.Add(new object[] {3});
70
71                         DataRow myRow = myTable.Rows[0];
72                         myRow.BeginEdit();
73                         myRow[0] = 7;
74                         myRow.CancelEdit();
75
76                         // DataRow CancelEdit
77                         Assert.AreEqual(true ,  (int)myRow[0] == 1, "DRW2");
78                 }
79
80                 [Test] public void ClearErrors()
81                 {
82                         DataTable dt = new DataTable("myTable"); 
83                         DataRow dr = dt.NewRow();
84                         dr.RowError = "err";
85
86                         // DataRow ClearErrors
87                         Assert.AreEqual(true ,  dr.HasErrors , "DRW3");
88
89                         // DataRow ClearErrors
90                         dr.ClearErrors();
91                         Assert.AreEqual(false ,  dr.HasErrors , "DRW4");
92                 }
93
94                 [Test] public void Delete()
95                 {
96                         DataTable myTable = new DataTable("myTable"); 
97                         DataColumn dc = new DataColumn("Id",typeof(int));
98                         dc.Unique=true;
99                         myTable.Columns.Add(dc);
100                         myTable.Rows.Add(new object[] {1});
101                         myTable.Rows.Add(new object[] {2});
102                         myTable.Rows.Add(new object[] {3});
103                         myTable.AcceptChanges();
104
105                         DataRow myRow = myTable.Rows[0];
106                         myRow.Delete();
107
108                         // Delete1
109                         Assert.AreEqual(DataRowState.Deleted  ,  myRow.RowState , "DRW5");
110
111                         // Delete2
112                         myTable.AcceptChanges();
113                         Assert.AreEqual(DataRowState.Detached  ,  myRow.RowState , "DRW6");
114                 }
115
116                 [Test] public void EndEdit()
117                 {
118                         DataTable myTable = new DataTable("myTable"); 
119                         DataColumn dc = new DataColumn("Id",typeof(int));
120                         dc.Unique=true;
121                         myTable.Columns.Add(dc);
122                         myTable.Rows.Add(new object[] {1});
123                         myTable.Rows.Add(new object[] {2});
124                         myTable.Rows.Add(new object[] {3});
125
126                         DataRow myRow = myTable.Rows[0];
127
128                         int iProposed;
129                         //After calling the DataRow object's BeginEdit method, if you change the value, the Current and Proposed values become available
130                         myRow.BeginEdit();
131                         myRow[0] = 7;
132                         iProposed = (int)myRow[0,DataRowVersion.Proposed];
133                         myRow.EndEdit();
134
135                         // EndEdit
136                         Assert.AreEqual(iProposed ,  (int)myRow[0,DataRowVersion.Current] , "DRW7");
137                 }
138
139                 [Test] public void Equals()
140                 {
141                         DataTable myTable = new DataTable("myTable"); 
142                         DataRow dr1,dr2;
143                         dr1 = myTable.NewRow();
144                         dr2 = myTable.NewRow();
145
146                         // not equals
147                         Assert.AreEqual(false  , dr1.Equals(dr2), "DRW8");
148
149                 dr1=dr2;
150                         // equals
151                         Assert.AreEqual(true , dr1.Equals(dr2), "DRW9");
152                 }
153
154                 [Test] public void GetChildRows_ByDataRealtion()
155                 {
156                         DataRow dr;
157                         DataRow[] drArrExcepted,drArrResult;
158                         DataTable dtChild,dtParent;
159                         DataSet ds = new DataSet();
160
161                         //Create tables
162                         dtChild = DataProvider.CreateChildDataTable();
163                         dtParent= DataProvider.CreateParentDataTable(); 
164
165                         //Add tables to dataset
166                         ds.Tables.Add(dtChild);
167                         ds.Tables.Add(dtParent);
168                         dr = dtParent.Rows[0];
169
170                         //Add Relation
171                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
172                         ds.Relations.Add(dRel);
173                         //Get Excepted result
174                         drArrExcepted = dtChild.Select("ParentId=" + dr["ParentId"]);
175                         //Get Result
176                         drArrResult = dr.GetChildRows(dRel);
177
178                         // GetChildRows_D
179                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW10");
180                 }
181
182                 [Test] public void GetChildRows_ByDataRealtionDataRowVersion()
183                 {
184                         DataRow drParent;
185                         DataRow[] drArrExcepted,drArrResult;
186                         DataTable dtChild,dtParent;
187                         DataSet ds = new DataSet();
188                         //Create tables
189                         dtChild = DataProvider.CreateChildDataTable();
190                         dtParent= DataProvider.CreateParentDataTable(); 
191                         //Add tables to dataset
192                         ds.Tables.Add(dtChild);
193                         ds.Tables.Add(dtParent);
194                         //Add Relation
195                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
196                         ds.Relations.Add(dRel);
197
198                         drParent = dtParent.Rows[0];
199
200                         // Teting: DateTime.Now.ToShortTimeString()
201                         //Get Excepted result
202                         drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );
203                         //Get Result DataRowVersion.Current
204                         drArrResult = drParent.GetChildRows(dRel,DataRowVersion.Current);
205                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW11");
206
207                         // Teting: DataRow.GetParentRows_D_D
208                         //Get Excepted result
209                         drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.OriginalRows );
210                         //Get Result DataRowVersion.Current
211                         drArrResult = drParent.GetChildRows(dRel,DataRowVersion.Original );
212                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW12");
213
214                         // Teting: DataRow.GetParentRows_D_D
215                         //Get Excepted result, in this case Current = Default
216                         drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows);
217                         //Get Result DataRowVersion.Current
218                         drArrResult = drParent.GetChildRows(dRel,DataRowVersion.Default  );
219                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW13");
220
221                         // Teting: DataRow.GetParentRows_D_D
222                         drParent.BeginEdit();
223                         drParent["String1"] = "Value";
224                         //Get Excepted result
225                         drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );
226                         //Get Result DataRowVersion.Current
227                         drArrResult = drParent.GetChildRows(dRel,DataRowVersion.Proposed  );
228                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW14");
229                 }
230
231                 [Test] public void GetChildRows_ByName()
232                 {
233                         DataRow dr;
234                         DataRow[] drArrExcepted,drArrResult;
235                         DataTable dtChild,dtParent;
236                         DataSet ds = new DataSet();
237
238                         //Create tables
239                         dtChild = DataProvider.CreateChildDataTable();
240                         dtParent= DataProvider.CreateParentDataTable(); 
241
242                         //Add tables to dataset
243                         ds.Tables.Add(dtChild);
244                         ds.Tables.Add(dtParent);
245                         dr = dtParent.Rows[0];
246
247                         //Add Relation
248                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
249                         ds.Relations.Add(dRel);
250                         //Get Excepted result
251                         drArrExcepted = dtChild.Select("ParentId=" + dr["ParentId"]);
252                         //Get Result
253                         drArrResult = dr.GetChildRows("Parent-Child");
254
255                         // GetChildRows_S
256                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW15");
257                 }
258
259                 [Test] public void GetChildRows_ByNameDataRowVersion()
260                 {
261                         DataRow drParent;
262                         DataRow[] drArrExcepted,drArrResult;
263                         DataTable dtChild,dtParent;
264                         DataSet ds = new DataSet();
265                         //Create tables
266                         dtChild = DataProvider.CreateChildDataTable();
267                         dtParent= DataProvider.CreateParentDataTable(); 
268                         //Add tables to dataset
269                         ds.Tables.Add(dtChild);
270                         ds.Tables.Add(dtParent);
271                         //Add Relation
272                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
273                         ds.Relations.Add(dRel);
274
275                         drParent = dtParent.Rows[0];
276
277                         // GetChildRows_SD 1
278                         //Get Excepted result
279                         drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );
280                         //Get Result DataRowVersion.Current
281                         drArrResult = drParent.GetChildRows("Parent-Child",DataRowVersion.Current);
282                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW16");
283
284                         // GetChildRows_SD 2
285                         //Get Excepted result
286                         drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.OriginalRows );
287                         //Get Result DataRowVersion.Current
288                         drArrResult = drParent.GetChildRows("Parent-Child",DataRowVersion.Original );
289                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW17");
290
291                         // GetParentRows_SD 3
292                         //Get Excepted result, in this case Current = Default
293                         drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows);
294                         //Get Result DataRowVersion.Current
295                         drArrResult = drParent.GetChildRows("Parent-Child",DataRowVersion.Default  );
296                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW18");
297
298                         // GetParentRows_SD 4
299                         drParent.BeginEdit();
300                         drParent["String1"] = "Value";
301                         //Get Excepted result
302                         drArrExcepted = dtChild.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );
303                         //Get Result DataRowVersion.Current
304                         drArrResult = drParent.GetChildRows("Parent-Child",DataRowVersion.Proposed  );
305                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW19");
306                 }
307
308                 [Test] public void GetColumnError_ByIndex()
309                 {
310                         string sColErr = "Error!";
311                         DataTable dt = new DataTable("myTable"); 
312                         DataColumn dc = new DataColumn("Column1"); 
313                         dt.Columns.Add(dc);
314                         DataRow dr = dt.NewRow();
315
316                         // GetColumnError 1
317                         Assert.AreEqual(String.Empty ,  dr.GetColumnError(0) , "DRW20");
318
319                         dr.SetColumnError(0,sColErr );
320
321                         // GetColumnError 2
322                         Assert.AreEqual(sColErr ,  dr.GetColumnError(0) , "DRW21");
323                 }
324
325                 [Test] public void GetColumnError_ByName()
326                 {
327                         string sColErr = "Error!";
328                         DataTable dt = new DataTable("myTable"); 
329                         DataColumn dc = new DataColumn("Column1"); 
330                         dt.Columns.Add(dc);
331                         DataRow dr = dt.NewRow();
332
333                         // GetColumnError 1
334                         Assert.AreEqual(String.Empty ,  dr.GetColumnError("Column1") , "DRW22");
335
336                         dr.SetColumnError("Column1",sColErr );
337
338                         // GetColumnError 2
339                         Assert.AreEqual(sColErr ,  dr.GetColumnError("Column1") , "DRW23");
340                 }
341
342                 [Test] public void GetColumnsInError()
343                 {
344                         string sColErr = "Error!";
345                         DataColumn[] dcArr;
346                         DataTable dt = new DataTable("myTable"); 
347                         //init some columns
348                         dt.Columns.Add(new DataColumn());
349                         dt.Columns.Add(new DataColumn());
350                         dt.Columns.Add(new DataColumn());
351                         dt.Columns.Add(new DataColumn());
352                         dt.Columns.Add(new DataColumn());
353
354                         //init some rows
355                         dt.Rows.Add(new object[] {});
356                         dt.Rows.Add(new object[] {});
357                         dt.Rows.Add(new object[] {});
358
359                         DataRow dr = dt.Rows[1];
360
361                         dcArr = dr.GetColumnsInError();
362
363                         // GetColumnsInError 1
364                         Assert.AreEqual(0,  dcArr.Length , "DRW24");
365
366                         dr.SetColumnError(0,sColErr);
367                         dr.SetColumnError(2,sColErr);
368                         dr.SetColumnError(4,sColErr);
369
370                         dcArr = dr.GetColumnsInError();
371
372                         // GetColumnsInError 2
373                         Assert.AreEqual(3, dcArr.Length , "DRW25");
374
375                         //check that the right columns taken
376                         // GetColumnsInError 3
377                         Assert.AreEqual(dt.Columns[0], dcArr[0], "DRW26");
378
379                         // GetColumnsInError 4
380                         Assert.AreEqual(dt.Columns[2], dcArr[1], "DRW27");
381
382                         // GetColumnsInError 5
383                         Assert.AreEqual(dt.Columns[4], dcArr[2], "DRW28");
384                 }
385
386                 [Test] public new void GetHashCode()
387                 {
388                         int iHashCode;
389                         DataRow dr;
390                         DataTable dt = new DataTable();
391                         dr = dt.NewRow();
392
393                         iHashCode = dr.GetHashCode();
394                         for (int i=0; i<10; i++)
395                         {       //must return the same value each time
396                                 // GetHashCode #" + i
397                                 Assert.AreEqual(dr.GetHashCode() ,  iHashCode , "DRW29");
398                         }
399                 }
400
401                 [Test] public void GetParentRow_ByDataRelation()
402                 {
403                         DataRow drExcepted,drResult,drChild;
404                         DataTable dtChild,dtParent;
405                         DataSet ds = new DataSet();
406
407                         //Create tables
408                         dtChild = DataProvider.CreateChildDataTable();
409                         dtParent = DataProvider.CreateParentDataTable(); 
410
411                         //Add tables to dataset
412                         ds.Tables.Add(dtChild);
413                         ds.Tables.Add(dtParent);
414
415                         //Add Relation
416                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
417                         ds.Relations.Add(dRel);
418
419                         //Excepted result
420                         drExcepted = dtParent.Rows[0];
421
422                         //Get Result
423                         drChild = dtChild.Select("ParentId=" + drExcepted["ParentId"])[0]; 
424                         drResult = drChild.GetParentRow(dRel);
425
426                         // GetParentRow_D
427                         Assert.AreEqual(drExcepted.ItemArray,  drResult.ItemArray , "DRW30");
428                 }
429
430                 [Test] public void GetParentRow_ByDataRelationDataRowVersion()
431                 {
432                         DataRow drParent,drChild;
433                         DataRow drArrExcepted,drArrResult;
434                         DataTable dtChild,dtParent;
435                         DataSet ds = new DataSet();
436                         //Create tables
437                         dtChild = DataProvider.CreateChildDataTable();
438                         dtParent= DataProvider.CreateParentDataTable(); 
439                         //Add tables to dataset
440                         ds.Tables.Add(dtChild);
441                         ds.Tables.Add(dtParent);
442                         //Add Relation
443                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
444                         ds.Relations.Add(dRel);
445
446                         drParent = dtParent.Rows[0];
447                         drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
448
449                         // GetParentRow_DD 1
450                         //Get Excepted result
451                         drArrExcepted = drParent;
452                         //Get Result DataRowVersion.Current
453                         drArrResult = drChild.GetParentRow(dRel,DataRowVersion.Current);
454                         Assert.AreEqual(drArrExcepted.ItemArray,  drArrResult.ItemArray , "DRW31");
455
456                         // GetParentRow_DD 2
457                         //Get Excepted result
458                         drArrExcepted = drParent;
459                         //Get Result DataRowVersion.Current
460                         drArrResult = drChild.GetParentRow(dRel,DataRowVersion.Original );
461                         Assert.AreEqual(drArrExcepted.ItemArray,  drArrResult.ItemArray , "DRW32");
462
463                         // GetParentRow_DD 3
464                         //Get Excepted result, in this case Current = Default
465                         drArrExcepted = drParent;
466                         //Get Result DataRowVersion.Current
467                         drArrResult = drChild.GetParentRow(dRel,DataRowVersion.Default  );
468                         Assert.AreEqual(drArrExcepted.ItemArray,  drArrResult.ItemArray , "DRW33");
469
470                         // GetParentRow_DD 4
471                         drChild.BeginEdit();
472                         drChild["String1"] = "Value";
473                         //Get Excepted result
474                         drArrExcepted = drParent;
475                         //Get Result DataRowVersion.Current
476                         drArrResult = drChild.GetParentRow(dRel,DataRowVersion.Proposed  );
477                         Assert.AreEqual(drArrExcepted.ItemArray,  drArrResult.ItemArray , "DRW34");
478                 }
479
480                 [Test] public void GetParentRow_ByName()
481                 {
482                         DataRow drExcepted,drResult,drChild;
483                         DataTable dtChild,dtParent;
484                         DataSet ds = new DataSet();
485
486                         //Create tables
487                         dtChild = DataProvider.CreateChildDataTable();
488                         dtParent = DataProvider.CreateParentDataTable(); 
489
490                         //Add tables to dataset
491                         ds.Tables.Add(dtChild);
492                         ds.Tables.Add(dtParent);
493
494                         //Add Relation
495                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
496                         ds.Relations.Add(dRel);
497
498                         //Excepted result
499                         drExcepted = dtParent.Rows[0];
500
501                         //Get Result
502                         drChild = dtChild.Select("ParentId=" + drExcepted["ParentId"])[0]; 
503                         drResult = drChild.GetParentRow("Parent-Child");
504
505                         // GetParentRow_S
506                         Assert.AreEqual(drExcepted.ItemArray,  drResult.ItemArray , "DRW35");
507                 }
508
509                 [Test] public void GetParentRow_ByNameDataRowVersion()
510                 {
511                         DataRow drParent,drChild;
512                         DataRow drArrExcepted,drArrResult;
513                         DataTable dtChild,dtParent;
514                         DataSet ds = new DataSet();
515                         //Create tables
516                         dtChild = DataProvider.CreateChildDataTable();
517                         dtParent= DataProvider.CreateParentDataTable(); 
518                         //Add tables to dataset
519                         ds.Tables.Add(dtChild);
520                         ds.Tables.Add(dtParent);
521                         //Add Relation
522                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
523                         ds.Relations.Add(dRel);
524
525                         drParent = dtParent.Rows[0];
526                         drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
527
528                         // GetParentRow_SD 1
529                         //Get Excepted result
530                         drArrExcepted = drParent;
531                         //Get Result DataRowVersion.Current
532                         drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Current);
533                         Assert.AreEqual(drArrExcepted.ItemArray,  drArrResult.ItemArray , "DRW36");
534
535                         // GetParentRow_SD 2
536                         //Get Excepted result
537                         drArrExcepted = drParent;
538                         //Get Result DataRowVersion.Current
539                         drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Original );
540                         Assert.AreEqual(drArrExcepted.ItemArray,  drArrResult.ItemArray , "DRW37");
541
542                         // GetParentRow_SD 3
543                         //Get Excepted result, in this case Current = Default
544                         drArrExcepted = drParent;
545                         //Get Result DataRowVersion.Current
546                         drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Default  );
547                         Assert.AreEqual(drArrExcepted.ItemArray,  drArrResult.ItemArray , "DRW38");
548
549                         // GetParentRow_SD 4
550                         drChild.BeginEdit();
551                         drChild["String1"] = "Value";
552                         //Get Excepted result
553                         drArrExcepted = drParent;
554                         //Get Result DataRowVersion.Current
555                         drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Proposed  );
556                         Assert.AreEqual(drArrExcepted.ItemArray,  drArrResult.ItemArray , "DRW39");
557                 }
558
559                 [Test] public void GetParentRows_ByDataRelation()
560                 {
561                         DataRow dr;
562                         DataRow[] drArrExcepted,drArrResult;
563                         DataTable dtChild,dtParent;
564                         DataSet ds = new DataSet();
565
566                         //Create tables
567                         dtChild = DataProvider.CreateChildDataTable();
568                         dtParent = DataProvider.CreateParentDataTable(); 
569
570                         //Add tables to dataset
571                         ds.Tables.Add(dtChild);
572                         ds.Tables.Add(dtParent);
573                         dr = dtParent.Rows[0];
574
575                         //Duplicate several rows in order to create Many to Many relation
576                         dtParent.ImportRow(dr); 
577                         dtParent.ImportRow(dr); 
578                         dtParent.ImportRow(dr); 
579
580                         //Add Relation
581                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"],false);
582                         ds.Relations.Add(dRel);
583                         //Get Excepted result
584                         drArrExcepted = dtParent.Select("ParentId=" + dr["ParentId"]);
585                         dr = dtChild.Select("ParentId=" + dr["ParentId"])[0];
586                         //Get Result
587                         drArrResult = dr.GetParentRows(dRel);
588
589                         // GetParentRows_D
590                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW40");
591                 }
592
593                 [Test] public void GetParentRows_ByName()
594                 {
595                         DataRow dr;
596                         DataRow[] drArrExcepted,drArrResult;
597                         DataTable dtChild,dtParent;
598                         DataSet ds = new DataSet();
599
600                         //Create tables
601                         dtChild = DataProvider.CreateChildDataTable();
602                         dtParent = DataProvider.CreateParentDataTable(); 
603
604                         //Add tables to dataset
605                         ds.Tables.Add(dtChild);
606                         ds.Tables.Add(dtParent);
607                         dr = dtParent.Rows[0];
608
609                         //Duplicate several rows in order to create Many to Many relation
610                         dtParent.ImportRow(dr); 
611                         dtParent.ImportRow(dr); 
612                         dtParent.ImportRow(dr); 
613
614                         //Add Relation
615                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"],false);
616                         ds.Relations.Add(dRel);
617                         //Get Excepted result
618                         drArrExcepted = dtParent.Select("ParentId=" + dr["ParentId"]);
619                         dr = dtChild.Select("ParentId=" + dr["ParentId"])[0];
620                         //Get Result
621                         drArrResult = dr.GetParentRows("Parent-Child");
622
623                         // GetParentRows_S
624                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW41");
625                 }
626
627                 [Test] public void GetParentRows_ByNameDataRowVersion()
628                 {
629                         DataRow drParent,drChild;
630                         DataRow[] drArrExcepted,drArrResult;
631                         DataTable dtChild,dtParent;
632                         DataSet ds = new DataSet();
633                         //Create tables
634                         dtChild = DataProvider.CreateChildDataTable();
635                         dtParent= DataProvider.CreateParentDataTable(); 
636                         //Add tables to dataset
637                         ds.Tables.Add(dtChild);
638                         ds.Tables.Add(dtParent);
639                         //Add Relation
640                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"],false);
641                         ds.Relations.Add(dRel);
642
643                         //Create several copies of the first row
644                         drParent = dtParent.Rows[0];    //row[0] has versions: Default,Current,Original
645                         dtParent.ImportRow(drParent);   //row[1] has versions: Default,Current,Original
646                         dtParent.ImportRow(drParent);   //row[2] has versions: Default,Current,Original
647                         dtParent.ImportRow(drParent);   //row[3] has versions: Default,Current,Original
648                         dtParent.ImportRow(drParent);   //row[4] has versions: Default,Current,Original
649                         dtParent.ImportRow(drParent);   //row[5] has versions: Default,Current,Original
650                         dtParent.AcceptChanges();
651
652                         //Get the first child row for drParent
653                         drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
654
655                         DataRow[] drTemp = dtParent.Select("ParentId=" + drParent["ParentId"]);
656                         //                              Console.WriteLine("********");
657                         //                              foreach (DataRow d in drTemp)
658                         //                              {
659                         //                                      CheckRowVersion(d);
660                         //                              }
661                         drTemp[0].BeginEdit();
662                         drTemp[0]["String1"] = "NewValue"; //row now has versions: Proposed,Current,Original,Default
663                         drTemp[1].BeginEdit();
664                         drTemp[1]["String1"] = "NewValue"; //row now has versions: Proposed,Current,Original,Default
665
666                         //              Console.WriteLine("********");
667                         //              foreach (DataRow d in drTemp)
668                         //              {
669                         //                      CheckRowVersion(d);
670                         //              }
671                         //              Console.WriteLine("********");
672
673                         // Check DataRowVersion.Current
674                         //Check DataRowVersion.Current 
675                         drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );
676                         drArrResult = drChild.GetParentRows("Parent-Child",DataRowVersion.Current);
677                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW42");
678
679                         //Check DataRowVersion.Current 
680                         // Teting: DataRow.GetParentRows_D_D ,DataRowVersion.Original
681                         drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.OriginalRows );
682                         drArrResult = drChild.GetParentRows("Parent-Child",DataRowVersion.Original );
683                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW43");
684
685                         //Check DataRowVersion.Default
686                         // Teting: DataRow.GetParentRows_D_D ,DataRowVersion.Default
687                         drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows);
688                         drArrResult = drChild.GetParentRows("Parent-Child",DataRowVersion.Default  );
689                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW44");
690
691                 /* .Net don't work as expected
692                         //Check DataRowVersion.Proposed
693                         // Teting: DataRow.GetParentRows_D_D ,DataRowVersion.Proposed
694                         drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.ModifiedCurrent);
695                         //drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.ModifiedOriginal );
696
697                         drArrResult = drChild.GetParentRows("Parent-Child",DataRowVersion.Proposed  );
698                         Assert.AreEqual(drArrExcepted,  drArrResult, "DRW45");
699                 */              
700                 }
701
702                 private void CheckRowVersion(DataRow dr)
703                 {
704                         Console.WriteLine("");
705                         if (dr.HasVersion(DataRowVersion.Current)) Console.WriteLine("Has " + DataRowVersion.Current.ToString());
706                         if (dr.HasVersion(DataRowVersion.Default)) Console.WriteLine("Has " + DataRowVersion.Default.ToString());
707                         if (dr.HasVersion(DataRowVersion.Original)) Console.WriteLine("Has " + DataRowVersion.Original.ToString());
708                         if (dr.HasVersion(DataRowVersion.Proposed)) Console.WriteLine("Has " + DataRowVersion.Proposed.ToString());
709                 }
710
711                 [Test] public new void GetType()
712                 {
713                         Type myType;    
714                         DataTable dt = new DataTable(); 
715                         DataRow dr = dt.NewRow();
716                         myType = typeof(DataRow);
717
718                         // GetType
719                         Assert.AreEqual(typeof(DataRow), myType , "DRW46");
720                 }
721
722                 [Test] public void HasErrors()
723                 {
724                         DataTable dt = new DataTable("myTable"); 
725                         DataRow dr = dt.NewRow();
726
727                         // HasErrors (default)
728                         Assert.AreEqual(false, dr.HasErrors, "DRW47");
729
730                         dr.RowError = "Err";
731
732                         // HasErrors (set/get)
733                         Assert.AreEqual(true , dr.HasErrors , "DRW48");
734                 }
735
736                 [Test] public void HasVersion_ByDataRowVersion()
737                 {
738                         DataTable t = new DataTable("atable");
739                         t.Columns.Add("id", typeof(int));
740                         t.Columns.Add("name", typeof(string));
741                         t.Columns[0].DefaultValue = 1;
742                         t.Columns[1].DefaultValue = "something";
743
744                         // row r is detached
745                         DataRow r = t.NewRow();
746
747                         // HasVersion Test #10
748                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Current) , "DRW49");
749
750                         // HasVersion Test #11
751                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Original) , "DRW50");
752
753                         // HasVersion Test #12
754                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW51");
755
756                         // HasVersion Test #13
757                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Proposed) , "DRW52");
758
759                         r[0] = 4; 
760                         r[1] = "four";
761
762                         // HasVersion Test #20
763                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Current) , "DRW53");
764
765                         // HasVersion Test #21
766                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Original) , "DRW54");
767
768                         // HasVersion Test #22
769                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW55");
770
771                         // HasVersion Test #23
772                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Proposed) , "DRW56");
773
774                         t.Rows.Add(r);
775                         // now it is "added"
776
777                         // HasVersion Test #30
778                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Current) , "DRW57");
779
780                         // HasVersion Test #31
781                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Original) , "DRW58");
782
783                         // HasVersion Test #32
784                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW59");
785
786                         // HasVersion Test #33
787                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW60");
788
789                         t.AcceptChanges();
790                         // now it is "unchanged"
791
792                         // HasVersion Test #40
793                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Current) , "DRW61");
794
795                         // HasVersion Test #41
796                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Original) , "DRW62");
797
798                         // HasVersion Test #42
799                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW63");
800
801                         // HasVersion Test #43
802                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW64");
803
804                         r.BeginEdit();
805                         r[1] = "newvalue";
806
807                         // HasVersion Test #50
808                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Current) , "DRW65");
809
810                         // HasVersion Test #51
811                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Original) , "DRW66");
812
813                         // HasVersion Test #52
814                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW67");
815
816                         // HasVersion Test #53
817                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Proposed) , "DRW68");
818
819                         r.EndEdit();
820                         // now it is "modified"
821                         // HasVersion Test #60
822                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Current) , "DRW69");
823
824                         // HasVersion Test #61
825                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Original) , "DRW70");
826
827                         // HasVersion Test #62
828                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW71");
829
830                         // HasVersion Test #63
831                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW72");
832
833                         // this or t.AcceptChanges
834                         r.AcceptChanges(); 
835                         // now it is "unchanged" again
836                         // HasVersion Test #70
837                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Current) , "DRW73");
838
839                         // HasVersion Test #71
840                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Original) , "DRW74");
841
842                         // HasVersion Test #72
843                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Default) , "DRW75");
844
845                         // HasVersion Test #73
846                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW76");
847
848                         r.Delete();
849                         // now it is "deleted"
850
851                         // HasVersion Test #80
852                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Current) , "DRW77");
853
854                         // HasVersion Test #81
855                         Assert.AreEqual(true , r.HasVersion(DataRowVersion.Original) , "DRW78");
856
857                         // HasVersion Test #82
858                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Default) , "DRW79");
859
860                         // HasVersion Test #83
861                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW80");
862
863                         r.AcceptChanges();
864                         // back to detached
865                         // HasVersion Test #90
866                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Current) , "DRW81");
867
868                         // HasVersion Test #91
869                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Original) , "DRW82");
870
871                         // HasVersion Test #92
872                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Default) , "DRW83");
873
874                         // HasVersion Test #93
875                         Assert.AreEqual(false , r.HasVersion(DataRowVersion.Proposed) , "DRW84");
876                 }
877
878                 [Test] public void IsNull_ByDataColumn()
879                 {
880                         DataTable dt = new DataTable(); 
881                         DataColumn dc0 = new DataColumn("Col0",typeof(int));
882                         DataColumn dc1 = new DataColumn("Col1",typeof(int));
883                         dt.Columns.Add(dc0);
884                         dt.Columns.Add(dc1);
885                         dt.Rows.Add(new object[] {1234});
886                         DataRow dr = dt.Rows[0];
887
888                         // IsNull_I 2
889                         Assert.AreEqual(false , dr.IsNull(dc0) , "DRW85");
890
891                         // IsNull_I 2
892                         Assert.AreEqual(true , dr.IsNull(dc1) , "DRW86");
893                 }
894
895                 [Test] public void IsNull_ByDataColumnDataRowVersion()
896                 {
897                         DataTable dt = new DataTable(); 
898                         DataColumn dc0 = new DataColumn("Col0",typeof(int));
899                         DataColumn dc1 = new DataColumn("Col1",typeof(int));
900                         dt.Columns.Add(dc0);
901                         dt.Columns.Add(dc1);
902                         dt.Rows.Add(new object[] {1234});
903                         DataRow dr = dt.Rows[0];
904
905                         // IsNull - col0 Current
906                         Assert.AreEqual(false, dr.IsNull(dc0,DataRowVersion.Current) , "DRW87");
907
908                         // IsNull - col1 Current
909                         Assert.AreEqual(true, dr.IsNull(dc1,DataRowVersion.Current) , "DRW88");
910
911                         // IsNull - col0 Default
912                         Assert.AreEqual(false, dr.IsNull(dc0,DataRowVersion.Default) , "DRW89");
913                         // IsNull - col1 Default
914                         Assert.AreEqual(true, dr.IsNull(dc1,DataRowVersion.Default) , "DRW90");
915
916                         dr.BeginEdit();
917                         dr[0] = 9; //Change value, Create RowVersion Proposed
918
919                         // IsNull - col0 Proposed
920                         Assert.AreEqual(false, dr.IsNull(dc0,DataRowVersion.Proposed) , "DRW91");
921                         // IsNull - col1 Proposed
922                         Assert.AreEqual(true, dr.IsNull(dc1,DataRowVersion.Proposed) , "DRW92");
923
924                         dr.AcceptChanges();
925                         dr.Delete();
926
927                         // IsNull - col0 Original
928                         Assert.AreEqual(false, dr.IsNull(dc0,DataRowVersion.Original) , "DRW93");
929                 }
930
931                 [Test] public void IsNull_ByIndex()
932                 {
933                         DataTable dt = new DataTable(); 
934                         DataColumn dc0 = new DataColumn("Col0",typeof(int));
935                         DataColumn dc1 = new DataColumn("Col1",typeof(int));
936                         dt.Columns.Add(dc0);
937                         dt.Columns.Add(dc1);
938                         dt.Rows.Add(new object[] {1234});
939                         DataRow dr = dt.Rows[0];
940
941                         // IsNull_I 2
942                         Assert.AreEqual(false , dr.IsNull(0) , "DRW94");
943
944                         // IsNull_I 2
945                         Assert.AreEqual(true , dr.IsNull(1) , "DRW95");
946                 }
947
948                 [Test] public void IsNull_ByName()
949                 {
950                         DataTable dt = new DataTable(); 
951                         DataColumn dc0 = new DataColumn("Col0",typeof(int));
952                         DataColumn dc1 = new DataColumn("Col1",typeof(int));
953                         dt.Columns.Add(dc0);
954                         dt.Columns.Add(dc1);
955                         dt.Rows.Add(new object[] {1234});
956                         DataRow dr = dt.Rows[0];
957
958 #region --- assignment  ----
959                         // IsNull_S 1
960                         Assert.AreEqual(false, dr.IsNull("Col0"), "DRW96");
961
962                         // IsNull_S 2
963                         Assert.AreEqual(true, dr.IsNull("Col1"), "DRW97");
964 #endregion
965
966 #region --- bug 3124 ---
967
968                         // IsNull_S 1
969                         MemoryStream st = new MemoryStream();
970                         StreamWriter sw = new StreamWriter(st);
971                         sw.Write("<?xml version=\"1.0\" standalone=\"yes\"?><NewDataSet>");
972                         sw.Write("<Table><EmployeeNo>9</EmployeeNo></Table>");
973                         sw.Write("</NewDataSet>");
974                         sw.Flush();
975                         st.Position=0;
976                         DataSet ds = new DataSet();
977                         ds.ReadXml(st);
978                         //  Here we add the expression column
979                         ds.Tables[0].Columns.Add("ValueListValueMember", typeof(object), "EmployeeNo");
980
981                         foreach( DataRow row in ds.Tables[0].Rows )
982                         {
983                                 // Console.WriteLine(row["ValueListValueMember"].ToString() + " " );
984                                 if( row.IsNull("ValueListValueMember") == true )
985                                         Assert.AreEqual("Failed", "SubTest", "DRW98");
986                                 else
987                                         Assert.AreEqual("Passed", "Passed", "DRW99");
988                         }
989
990 #endregion
991                 }
992
993                 [Test] public void Item()
994                 {
995                         // init table with columns
996                         DataTable myTable = new DataTable("myTable"); 
997
998                         myTable.Columns.Add(new DataColumn("Id",typeof(int)));
999                         myTable.Columns.Add(new DataColumn("Name",typeof(string)));
1000                         DataColumn dc = myTable.Columns[0];
1001
1002                         myTable.Rows.Add(new object[] {1,"Ofer"});
1003                         myTable.Rows.Add(new object[] {2,"Ofer"});
1004
1005                         myTable.AcceptChanges();
1006
1007                         DataRow myRow = myTable.Rows[0];
1008
1009                         //Start checking
1010
1011                         // Item - index
1012                         Assert.AreEqual(1 , (int)myRow[0] , "DRW100");
1013
1014                         // Item - string
1015                         Assert.AreEqual(1 ,  (int)myRow["Id"] , "DRW101");
1016
1017                         // Item - Column
1018                         Assert.AreEqual(1 ,  (int)myRow[dc] , "DRW102");
1019
1020                         // Item - index,Current
1021                         Assert.AreEqual(1 ,  (int)myRow[0,DataRowVersion.Current ] , "DRW103");
1022
1023                         // Item - string,Current
1024                         Assert.AreEqual(1 ,  (int)myRow["Id",DataRowVersion.Current] , "DRW104");
1025
1026                         // Item - columnn,Current
1027                         Assert.AreEqual(1 ,  (int)myRow[dc,DataRowVersion.Current] , "DRW105");
1028
1029                         //      testMore();
1030                 }
1031
1032                 /*public void testMore()
1033                 {
1034                         DataTable dt = DataProvider.CreateParentDataTable();
1035                         dt.Rows[0].BeginEdit();
1036                         dt.Rows[0][0] = 10;
1037                         dt.Rows[0].EndEdit();
1038                         dt.AcceptChanges();
1039                 }*/
1040
1041                 [Test] public void RejectChanges()
1042                 {
1043                         DataTable dt = new DataTable(); 
1044                         DataColumn dc0 = new DataColumn("Col0",typeof(int));
1045                         DataColumn dc1 = new DataColumn("Col1",typeof(int));
1046                         dt.Columns.Add(dc0);
1047                         dt.Columns.Add(dc1);
1048                         dt.Rows.Add(new object[] {1234});
1049                         dt.AcceptChanges();
1050                         DataRow dr = dt.Rows[0];
1051
1052                         dr[0] = 567;
1053                         dr[1] = 789;
1054                         dr.RejectChanges();
1055
1056                         // RejectChanges - row 0
1057                         Assert.AreEqual(1234  ,  (int)dr[0], "DRW106");
1058
1059                         // RejectChanges - row 1
1060                         Assert.AreEqual(DBNull.Value  ,  dr[1] , "DRW107");
1061
1062                         dr.Delete();
1063                         dr.RejectChanges();
1064
1065                         // RejectChanges - count
1066                         Assert.AreEqual(1 ,  dt.Rows.Count , "DRW108");
1067                 }
1068
1069                 [Test] public void RowState()
1070                 {
1071                         DataTable myTable = new DataTable("myTable"); 
1072                         DataColumn dc = new DataColumn("Name",typeof(string));
1073                         myTable.Columns.Add(dc);
1074                         DataRow myRow;
1075
1076                         // Create a new DataRow.
1077                         myRow = myTable.NewRow();
1078
1079                         // Detached row.
1080
1081                         // Detached
1082                         Assert.AreEqual(DataRowState.Detached ,  myRow.RowState , "DRW109");
1083
1084                         myTable.Rows.Add(myRow);
1085                         // New row.
1086
1087                         // Added
1088                         Assert.AreEqual(DataRowState.Added ,  myRow.RowState , "DRW110");
1089
1090                         myTable.AcceptChanges();
1091                         // Unchanged row.
1092
1093                         // Unchanged
1094                         Assert.AreEqual(DataRowState.Unchanged ,  myRow.RowState , "DRW111");
1095
1096                         myRow["Name"] = "Scott";
1097                         // Modified row.
1098
1099                         // Modified
1100                         Assert.AreEqual(DataRowState.Modified ,  myRow.RowState , "DRW112");
1101
1102                         myRow.Delete();
1103                         // Deleted row.
1104
1105                         // Deleted
1106                         Assert.AreEqual(DataRowState.Deleted ,  myRow.RowState , "DRW113");
1107                 }
1108
1109                 [Test] public void SetColumnError_ByDataColumnError()
1110                 {
1111                         string sColErr = "Error!";
1112                         DataTable dt = new DataTable("myTable"); 
1113                         DataColumn dc = new DataColumn("Column1"); 
1114                         dt.Columns.Add(dc);
1115                         DataRow dr = dt.NewRow();
1116
1117                         // empty string
1118                         Assert.AreEqual(String.Empty,  dr.GetColumnError(dc) , "DRW114");
1119
1120                         dr.SetColumnError(dc,sColErr );
1121
1122                         // error string
1123                         Assert.AreEqual(sColErr, dr.GetColumnError(dc) , "DRW115");
1124                 }
1125
1126                 [Test] public void SetColumnError_ByIndexError()
1127                 {
1128                         string sColErr = "Error!";
1129                         DataTable dt = new DataTable("myTable"); 
1130                         DataColumn dc = new DataColumn("Column1"); 
1131                         dt.Columns.Add(dc);
1132                         DataRow dr = dt.NewRow();
1133
1134                         // empty string
1135                         Assert.AreEqual(String.Empty ,  dr.GetColumnError(0) , "DRW116");
1136
1137                         dr.SetColumnError(0,sColErr );
1138
1139                         // error string
1140                         Assert.AreEqual(sColErr  ,  dr.GetColumnError(0) , "DRW117");
1141                         dr.SetColumnError (0, "");
1142                         Assert.AreEqual("",  dr.GetColumnError (0) , "DRW118");
1143                 }
1144
1145                 [Test] public void SetColumnError_ByColumnNameError()
1146                 {
1147                         string sColErr = "Error!";
1148                         DataTable dt = new DataTable("myTable"); 
1149                         DataColumn dc = new DataColumn("Column1"); 
1150                         dt.Columns.Add(dc);
1151                         DataRow dr = dt.NewRow();
1152
1153                         // empty string
1154                         Assert.AreEqual(String.Empty,  dr.GetColumnError("Column1") , "DRW118");
1155
1156                         dr.SetColumnError("Column1",sColErr );
1157
1158                         // error string
1159                         Assert.AreEqual(sColErr,  dr.GetColumnError("Column1") , "DRW119");
1160                 }
1161
1162                 [Test] public void SetParentRow_ByDataRow()
1163                 {
1164                         DataRow drParent,drChild;
1165                         DataRow drArrExcepted,drArrResult;
1166                         DataTable dtChild,dtParent;
1167                         DataSet ds = new DataSet();
1168                         //Create tables
1169                         dtChild = DataProvider.CreateChildDataTable();
1170                         dtParent= DataProvider.CreateParentDataTable(); 
1171                         //Add tables to dataset
1172                         ds.Tables.Add(dtChild);
1173                         ds.Tables.Add(dtParent);
1174                         //Add Relation
1175                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
1176                         ds.Relations.Add(dRel);
1177
1178                         drParent = dtParent.Rows[0];
1179                         drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
1180
1181                         drChild.SetParentRow(drParent);
1182
1183                         //Get Excepted result
1184                         drArrExcepted = drParent;
1185                         //Get Result DataRowVersion.Current
1186                         drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Current);
1187
1188                         // SetParentRow
1189                         Assert.AreEqual(drArrExcepted ,  drArrResult, "DRW120");
1190                 }
1191
1192                 [Test]
1193                 public void testMore()
1194                 {
1195                         DataSet ds = DataProvider.CreateForigenConstraint();
1196                         DataRow drParent = ds.Tables[0].Rows[0];
1197                         //DataRow[] drArray =  ds.Tables[1].Rows[0].GetParentRows(ds.Tables[1].ParentRelations[0]);
1198                         ds.Tables[1].Rows[0].SetParentRow(drParent);
1199                 }
1200
1201                 [Test]
1202                 public void test()
1203                 {
1204                         // test SetParentRow
1205                         DataTable parent = DataProvider.CreateParentDataTable();
1206                         DataTable child = DataProvider.CreateChildDataTable();
1207                         DataRow dr = parent.Rows[0];
1208                         dr.Delete();
1209                         parent.AcceptChanges();
1210
1211                         child.Rows[0].SetParentRow(dr);
1212                 }
1213
1214                 public void checkForLoops()
1215                 {
1216                         DataSet ds = new DataSet();
1217                         //Create tables
1218                         DataTable  dtChild = DataProvider.CreateChildDataTable();
1219                         DataTable dtParent= DataProvider.CreateParentDataTable(); 
1220                         //Add tables to dataset
1221                         ds.Tables.Add(dtChild);
1222                         ds.Tables.Add(dtParent);
1223
1224                         dtChild.Rows.Clear();
1225                         dtParent.Rows.Clear();
1226
1227                         dtParent.ChildRelations.Add(dtParent.Columns[0],dtChild.Columns[0]);
1228                         dtChild.ChildRelations.Add(dtChild.Columns[0],dtParent.Columns[0]);
1229
1230                         dtChild.Rows[0].SetParentRow(dtParent.Rows[0]);
1231                         dtParent.Rows[0].SetParentRow(dtChild.Rows[0]);
1232                 }
1233
1234                 public void checkForLoopsAdvenced()
1235                 {
1236                         //Create tables
1237                         DataTable  dtChild = new DataTable();
1238                         dtChild.Columns.Add("Col1",typeof(int));
1239                         dtChild.Columns.Add("Col2",typeof(int));
1240
1241                         DataRelation drl = new DataRelation("drl1",dtChild.Columns[0],dtChild.Columns[1]);
1242                         dtChild.ChildRelations.Add(drl);
1243                         dtChild.Rows[0].SetParentRow(dtChild.Rows[1]);
1244                         dtChild.Rows[1].SetParentRow(dtChild.Rows[0]);
1245                 }
1246
1247                 [Test] public void SetParentRow_ByDataRowDataRelation()
1248                 {
1249                         DataRow drParent,drChild;
1250                         DataRow drArrExcepted,drArrResult;
1251                         DataTable dtChild,dtParent;
1252                         DataSet ds = new DataSet();
1253                         //Create tables
1254                         dtChild = DataProvider.CreateChildDataTable();
1255                         dtParent= DataProvider.CreateParentDataTable(); 
1256                         //Add tables to dataset
1257                         ds.Tables.Add(dtChild);
1258                         ds.Tables.Add(dtParent);
1259                         //Add Relation
1260                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
1261                         ds.Relations.Add(dRel);
1262
1263                         drParent = dtParent.Rows[0];
1264                         drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
1265
1266                         drChild.SetParentRow(drParent ,dRel);
1267
1268                         //Get Excepted result
1269                         drArrExcepted = drParent;
1270                         //Get Result DataRowVersion.Current
1271                         drArrResult = drChild.GetParentRow("Parent-Child",DataRowVersion.Current);
1272
1273                         // SetParentRow
1274                         Assert.AreEqual(drArrExcepted ,  drArrResult, "DRW121");
1275                 }
1276
1277                 [Test] public void Table()
1278                 {
1279                         DataTable dt1,dt2;
1280                         dt2 = new DataTable("myTable"); 
1281                         DataRow dr = dt2.NewRow();
1282                         dt1 = dr.Table;
1283
1284                         // ctor
1285                         Assert.AreEqual(dt2, dt1 , "DRW122");
1286                 }
1287
1288                 [Test] public new  void ToString()
1289                 {
1290                         DataRow dr;
1291                         DataTable dtParent;
1292                         dtParent= DataProvider.CreateParentDataTable(); 
1293                         dr = dtParent.Rows[0];
1294
1295                         // ToString
1296                         Assert.AreEqual(true, dr.ToString().ToLower().StartsWith("system.data.datarow") , "DRW123");
1297                 }
1298                 
1299                 [Test] public void DataRow_RowError()
1300                 {
1301                         DataTable dt = new DataTable ("myTable"); 
1302                         DataRow dr = dt.NewRow ();
1303         
1304                         Assert.AreEqual ( dr.RowError, string.Empty );
1305                                                 
1306                         dr.RowError = "Err";
1307                         Assert.AreEqual ( dr.RowError , "Err" );
1308                 }
1309                 
1310                 [Test] 
1311                 [ExpectedException (typeof (ConstraintException))]
1312                 public void DataRow_RowError2()
1313                 {
1314                         DataTable dt1 = DataProvider.CreateUniqueConstraint();
1315
1316                         dt1.BeginLoadData();
1317
1318                         DataRow  dr = dt1.NewRow();
1319                         dr[0] = 3;
1320                         dt1.Rows.Add(dr);
1321                         dt1.EndLoadData();
1322                 }
1323                 
1324                 [Test] 
1325                 [ExpectedException (typeof (ConstraintException))]
1326                 public void DataRow_RowError3()
1327                 {
1328                         DataSet ds= DataProvider.CreateForigenConstraint();
1329                         ds.Tables[0].BeginLoadData();
1330                         ds.Tables[0].Rows[0][0] = 10; 
1331                         ds.Tables[0].EndLoadData(); //Foreign constraint violation
1332                 }
1333
1334
1335                 [Test]
1336                 public void TestRowErrors ()
1337                 {
1338                         DataTable table = new DataTable ();
1339                         DataColumn col1 = table.Columns.Add ("col1", typeof (int));
1340                         DataColumn col2 = table.Columns.Add ("col2", typeof (int));
1341                         DataColumn col3 = table.Columns.Add ("col3", typeof (int));
1342
1343                         col1.AllowDBNull = false;
1344                         table.Constraints.Add ("uc", new DataColumn[] {col2,col3}, false);
1345                         table.BeginLoadData ();
1346                         table.Rows.Add (new object[] {null,1,1});
1347                         table.Rows.Add (new object[] {1,1,1});
1348                         try {
1349                                 table.EndLoadData ();
1350                                 Assert.Fail ("#0");
1351                         } catch (ConstraintException) {}
1352                         Assert.IsTrue (table.HasErrors, "#1");
1353                         DataRow[] rows = table.GetErrors ();
1354
1355                         Assert.AreEqual (2, rows.Length, "#2");
1356                         Assert.AreEqual ("Column 'col1' does not allow DBNull.Value.", table.Rows [0].RowError, "#3");
1357                         Assert.AreEqual ("Column 'col2, col3' is constrained to be unique.  Value '1, 1' is already present."
1358                                         , table.Rows [1].RowError, "#4");
1359
1360                         Assert.AreEqual (table.Rows [0].RowError, table.Rows [0].GetColumnError (0), "#5");
1361                         Assert.AreEqual (table.Rows [1].RowError, table.Rows [0].GetColumnError (1), "#6");
1362                         Assert.AreEqual (table.Rows [1].RowError, table.Rows [0].GetColumnError (2), "#7");
1363
1364                         Assert.AreEqual ("", table.Rows [1].GetColumnError (0), "#8");
1365                         Assert.AreEqual (table.Rows [1].RowError, table.Rows [1].GetColumnError (1), "#9");
1366                         Assert.AreEqual (table.Rows [1].RowError, table.Rows [1].GetColumnError (2), "#10");
1367                 }
1368
1369                 [Test]
1370                 public void BeginEdit()
1371                 {
1372                         DataTable myTable = new DataTable("myTable"); 
1373                         DataColumn dc = new DataColumn("Id",typeof(int));
1374                         dc.Unique=true;
1375                         myTable.Columns.Add(dc);
1376                         myTable.Rows.Add(new object[] {1});
1377                         myTable.Rows.Add(new object[] {2});
1378                         myTable.Rows.Add(new object[] {3});
1379                         
1380                         DataRow myRow = myTable.Rows[0];
1381                         
1382                         try     
1383                         { 
1384                                 myRow[0] = 2; //row[0] now conflict with row[1] 
1385                                 Assert.Fail("DRW121: failed to throw ConstraintException");
1386                         }
1387                         catch (ConstraintException) {}
1388                         catch (AssertionException exc) {throw  exc;}
1389                         catch (Exception exc)
1390                         {
1391                                 Assert.Fail("DRW122: Add. Wrong exception type. Got:" + exc);
1392                         }
1393
1394                         //Will NOT! throw exception
1395                         myRow.BeginEdit();
1396                         myRow[0] = 2; //row[0] now conflict with row[1] 
1397                                         
1398                         DataTable dt = DataProvider.CreateParentDataTable();
1399                         DataRow dr = dt.Rows[0];
1400                         dr.Delete();
1401                         try
1402                         {
1403                                 dr.BeginEdit();                         
1404                                 Assert.Fail("DRW123: failed to throw DeletedRowInaccessibleException");
1405                         }
1406                         catch (DeletedRowInaccessibleException) {}
1407                         catch (AssertionException exc) {throw  exc;}
1408                         catch (Exception exc)
1409                         {
1410                                 Assert.Fail("DRW124: Add. Wrong exception type. Got:" + exc);
1411                         }
1412                 }
1413
1414                 [Test]
1415                 public void GetChildRows_DataRelation()
1416                 {
1417                         DataRow dr;
1418                         DataRow[] drArrExcepted,drArrResult;
1419                         DataTable dtChild,dtParent;
1420                         DataSet ds = new DataSet();
1421
1422                         //Create tables
1423                         dtChild = DataProvider.CreateChildDataTable();
1424                         dtParent= DataProvider.CreateParentDataTable(); 
1425
1426                         //Add tables to dataset
1427                         ds.Tables.Add(dtChild);
1428                         ds.Tables.Add(dtParent);
1429                         dr = dtParent.Rows[0];
1430
1431                         //Add Relation
1432                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"]);
1433                         ds.Relations.Add(dRel);
1434                         //Get Excepted result
1435                         drArrExcepted = dtChild.Select("ParentId=" + dr["ParentId"]);
1436                         //Get Result
1437                         drArrResult = dr.GetChildRows(dRel);
1438                         
1439                         Assert.AreEqual(drArrExcepted, drArrResult, "DRW125");
1440                 }
1441
1442                 [Test]
1443                 public void GetParentRows_DataRelation_DataRowVersion()
1444                 {
1445                         DataRow drParent,drChild;
1446                         DataRow[] drArrExcepted,drArrResult;
1447                         DataTable dtChild,dtParent;
1448                         DataSet ds = new DataSet();
1449                         //Create tables
1450                         dtChild = DataProvider.CreateChildDataTable();
1451                         dtParent= DataProvider.CreateParentDataTable(); 
1452                         //Add tables to dataset
1453                         ds.Tables.Add(dtChild);
1454                         ds.Tables.Add(dtParent);
1455                                         
1456                         drParent = dtParent.Rows[0];
1457                         drChild = dtChild.Select("ParentId=" + drParent["ParentId"])[0];
1458
1459                         //Duplicate several rows in order to create Many to Many relation
1460                         dtParent.ImportRow(drParent); 
1461                         dtParent.ImportRow(drParent); 
1462                         dtParent.ImportRow(drParent);                           
1463                                         
1464                         //Add Relation
1465                         DataRelation dRel = new DataRelation("Parent-Child",dtParent.Columns["ParentId"],dtChild.Columns["ParentId"],false);
1466                         ds.Relations.Add(dRel);
1467
1468                         //Get Excepted result
1469                         drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows );
1470                         //Get Result DataRowVersion.Current
1471                         drArrResult = drChild.GetParentRows(dRel,DataRowVersion.Current);
1472                         Assert.AreEqual(drArrExcepted, drArrResult, "DRW126");
1473
1474                         //Get Excepted result
1475                         drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.OriginalRows );
1476                         //Get Result DataRowVersion.Current
1477                         drArrResult = drChild.GetParentRows(dRel,DataRowVersion.Original );
1478                         Assert.AreEqual(drArrExcepted, drArrResult, "DRW127");
1479
1480                         //Get Excepted result, in this case Current = Default
1481                         drArrExcepted = dtParent.Select("ParentId=" + drParent["ParentId"],"",DataViewRowState.CurrentRows);
1482                         //Get Result DataRowVersion.Current
1483                         drArrResult = drChild.GetParentRows(dRel,DataRowVersion.Default  );
1484                         Assert.AreEqual(drArrExcepted, drArrResult, "DRW128");
1485                         
1486                         try
1487                         {
1488                                 DataTable dtOtherParent = DataProvider.CreateParentDataTable();
1489                                 DataTable dtOtherChild = DataProvider.CreateChildDataTable();
1490
1491                                 DataRelation drl = new DataRelation("newRelation",dtOtherParent.Columns[0],dtOtherChild.Columns[0]);
1492                                 drChild.GetParentRows(drl,DataRowVersion.Current); 
1493                                 Assert.Fail("DRW129: failed to throw ArgumentException");
1494                         }
1495                         catch (ArgumentException) {}
1496                         catch (AssertionException exc) {throw  exc;}
1497                         catch (Exception exc)
1498                         {
1499                                 Assert.Fail("DRW130: Add. Wrong exception type. Got:" + exc);
1500                         }
1501                 }
1502
1503                 [Test]
1504                 public void ItemArray()
1505                 {
1506                         DataTable dt = GetDataTable();
1507                         DataRow dr = dt.Rows[0];
1508
1509                         Assert.AreEqual(1, (int)dr.ItemArray[0] , "DRW131" );
1510
1511                         Assert.AreEqual("Ofer", (string)dr.ItemArray[1] , "DRW132" );
1512
1513                         dt = GetDataTable();
1514
1515                         dr = dt.Rows[0];
1516                         
1517                         //Changing row via itemArray
1518
1519                         dt.Rows[0].ItemArray = new object[] {2,"Oren"};
1520
1521                         Assert.AreEqual(2, (Int32)dr.ItemArray[0] , "DRW133" );
1522                         Assert.AreEqual("Oren", (string)dr.ItemArray[1] , "DRW134" );
1523
1524                         try
1525                         {
1526                                 dt.Rows[0].ItemArray = new object[] {2,"Oren","some1else"};
1527                                 Assert.Fail("DRW135: failed to throw ArgumentException");
1528                         }
1529                         catch (ArgumentException) {}
1530                         catch (AssertionException exc) {throw  exc;}
1531                         catch (Exception exc)
1532                         {
1533                                 Assert.Fail("DRW136: Add. Wrong exception type. Got:" + exc);
1534                         }
1535                 }
1536
1537                 [Test]
1538                 public void ItemArray_NewTable ()
1539                 {
1540                         DataTable dt = new DataTable("Customers");
1541
1542                         dt.Columns.Add("name", typeof (string));
1543                         dt.Columns.Add("address", typeof (string));
1544                         dt.Columns.Add("phone", typeof (string));
1545
1546                         DataRow dr = dt.NewRow();
1547                         dr["name"] = "myName";
1548                         dr["address"] = "myAddress";
1549                         dr["phone"] = "myPhone";
1550
1551                         // Should not throw RowNotInTableException
1552                         object[] obj = dr.ItemArray;
1553                 }
1554
1555                 private DataTable GetDataTable()
1556                 {
1557                         DataTable dt = new DataTable("myTable"); 
1558                         dt.Columns.Add("Id",typeof(int));
1559                         dt.Columns.Add("Name",typeof(string));
1560
1561                         DataRow dr = dt.NewRow();
1562                         dr.ItemArray = new object[] {1,"Ofer"};
1563
1564                         dt.Rows.Add(dr);
1565
1566                         return dt;
1567                 }
1568
1569                 [Test]
1570                 public void RowError()
1571                 {
1572                         DataTable dt = new DataTable("myTable"); 
1573                         DataRow dr = dt.NewRow();
1574
1575                         Assert.AreEqual(string.Empty , dr.RowError, "DRW137");
1576
1577                         dr.RowError = "Err";
1578
1579                         Assert.AreEqual("Err", dr.RowError , "DRW138" );
1580
1581                         DataTable dt1 = DataProvider.CreateUniqueConstraint();
1582
1583                         try
1584                         {
1585                                 dt1.BeginLoadData();
1586
1587                                 dr = dt1.NewRow();
1588                                 dr[0] = 3;
1589                                 dt1.Rows.Add(dr);
1590                                 dt1.EndLoadData();
1591                                 Assert.Fail("DRW139: failed to throw ConstraintException");
1592                         }
1593                         catch (ConstraintException) 
1594                         {
1595                                 Assert.AreEqual(2,dt1.GetErrors().Length,"DRW141");
1596                                 Assert.AreEqual(true,dt1.GetErrors()[0].RowError.Length > 10,"DRW142");
1597                                 Assert.AreEqual(true,dt1.GetErrors()[1].RowError.Length > 10,"DRW143");
1598                         }
1599                         catch (AssertionException exc) {throw  exc;}
1600                         catch (Exception exc)
1601                         {
1602                                 Assert.Fail("DRW144: Wrong exception type. Got:" + exc);
1603                         }
1604
1605
1606                         DataSet ds=null;
1607                         try
1608                         {
1609                                 ds= DataProvider.CreateForigenConstraint();
1610                                 ds.Tables[0].BeginLoadData();
1611                                 ds.Tables[0].Rows[0][0] = 10; //Forigen constraint violation
1612                                 //ds.Tables[0].AcceptChanges();
1613                                 ds.Tables[0].EndLoadData();
1614                                 Assert.Fail("DRW139: failed to throw ConstraintException");
1615                         }
1616                         catch (ConstraintException) 
1617                         {
1618                                 Assert.AreEqual(3,ds.Tables[1].GetErrors().Length,"DRW145");
1619                                 for(int index=0;index<3;index++)
1620                                 {
1621                                         Assert.AreEqual(true,ds.Tables[1].GetErrors()[index].RowError.Length > 10,"RDW146");
1622                                 }
1623                         }
1624                         catch (AssertionException exc) {throw  exc;}
1625                         catch (Exception exc)
1626                         {
1627                                 Assert.Fail("DRW147: Wrong exception type. Got:" + exc);
1628                         }
1629                 }
1630
1631                 [Test]
1632                 public void bug78885 ()
1633                 {
1634                         DataSet ds = new DataSet ();
1635                         DataTable t = ds.Tables.Add ("table");
1636                         DataColumn id;
1637
1638                         id = t.Columns.Add ("userID", Type.GetType ("System.Int32"));
1639                         id.AutoIncrement = true;
1640                         t.Columns.Add ("name", Type.GetType ("System.String"));
1641                         t.Columns.Add ("address", Type.GetType ("System.String"));
1642                         t.Columns.Add ("zipcode", Type.GetType ("System.Int32"));
1643                         t.PrimaryKey = new DataColumn [] { id };
1644
1645                         DataRow tempRow;
1646                         tempRow = t.NewRow ();
1647                         tempRow ["name"] = "Joan";
1648                         tempRow ["address"] = "Balmes 152";
1649                         tempRow ["zipcode"] = "1";
1650                         t.Rows.Add (tempRow);
1651
1652                         t.RowChanged += new DataRowChangeEventHandler (RowChangedHandler);
1653
1654                         /* neither of the calls to EndEdit below generate a RowChangedHandler on MS.  the first one does on mono */
1655                         t.DefaultView [0].BeginEdit ();
1656                         t.DefaultView [0].EndEdit (); /* this generates a call to the row changed handler */
1657                         t.DefaultView [0].EndEdit (); /* this doesn't */
1658
1659                         Assert.IsFalse (_rowChanged);
1660                 }
1661
1662                 private void RowChangedHandler (object sender, DataRowChangeEventArgs e)
1663                 {
1664                         _rowChanged = true;
1665                 }
1666
1667 #if NET_2_0
1668                 string SetAddedModified_ErrMsg = "SetAdded and SetModified can only be called on DataRows with Unchanged DataRowState.";
1669                 [Test]
1670                 public void SetAdded_test()
1671                 {
1672                         DataTable table = new DataTable();
1673
1674                         DataRow row = table.NewRow();
1675                         try {
1676                                 row.SetAdded();
1677                                 Assert.Fail ("#1");
1678                         } catch (InvalidOperationException e) {
1679                                 Assert.AreEqual (SetAddedModified_ErrMsg, e.Message, "#2");
1680                         }
1681
1682                         table.Columns.Add("col1", typeof(int));
1683                         table.Columns.Add("col2", typeof(int));
1684                         table.Columns.Add("col3", typeof(int));
1685
1686                         row = table.Rows.Add(new object[] { 1, 2, 3 });
1687                         Assert.AreEqual(DataRowState.Added, row.RowState, "#1");
1688                         try {
1689                                 row.SetAdded();
1690                                 Assert.Fail ("#2");
1691                         } catch (InvalidOperationException e) {
1692                                 Assert.AreEqual (SetAddedModified_ErrMsg, e.Message, "#2");
1693                         }
1694                         Assert.AreEqual(DataRowState.Added, row.RowState, "#2");
1695
1696                         row.AcceptChanges();
1697                         row[0] = 10;
1698                         Assert.AreEqual(DataRowState.Modified, row.RowState, "#5");
1699                         try {
1700                                 row.SetAdded();
1701                                 Assert.Fail ("#3");
1702                         } catch (InvalidOperationException e) {
1703                                 Assert.AreEqual (SetAddedModified_ErrMsg, e.Message, "#2");
1704                         }
1705
1706                         row.AcceptChanges();
1707                         Assert.AreEqual(DataRowState.Unchanged, row.RowState, "#3");
1708                         row.SetAdded();
1709                         Assert.AreEqual(DataRowState.Added, row.RowState, "#4");
1710                 }
1711
1712                 [Test]
1713                 public void setAdded_testRollback ()
1714                 {
1715                         DataTable table = new DataTable ();
1716                         table.Columns.Add ("col1", typeof (int));
1717                         table.Columns.Add ("col2", typeof (int));
1718
1719                         table.Rows.Add (new object[] {1,1});
1720                         table.AcceptChanges ();
1721
1722                         table.Rows [0].SetAdded ();
1723                         table.RejectChanges ();
1724                         Assert.AreEqual (0, table.Rows.Count, "#1");
1725                 }
1726
1727                 [Test]
1728                 public void SetModified_test()
1729                 {
1730                         DataTable table = new DataTable();
1731
1732                         DataRow row = table.NewRow();
1733                         try {
1734                                 row.SetModified ();
1735                         } catch (InvalidOperationException) {}
1736
1737                         table.Columns.Add("col1", typeof(int));
1738                         table.Columns.Add("col2", typeof(int));
1739                         table.Columns.Add("col3", typeof(int));
1740
1741                         row = table.Rows.Add(new object[] { 1, 2, 3 });
1742                         Assert.AreEqual(DataRowState.Added, row.RowState, "#1");
1743                         try {
1744                                 row.SetModified();
1745                                 Assert.Fail ("#1");
1746                         } catch (InvalidOperationException e) {
1747                                 Assert.AreEqual (SetAddedModified_ErrMsg, e.Message, "#2");
1748                         }
1749
1750                         row.AcceptChanges();
1751                         row[0] = 10;
1752                         Assert.AreEqual(DataRowState.Modified, row.RowState, "#5");
1753                         try {
1754                                 row.SetModified ();
1755                                 Assert.Fail ("#2");
1756                         } catch (InvalidOperationException e) {
1757                                 Assert.AreEqual (SetAddedModified_ErrMsg, e.Message, "#2");
1758                         }
1759
1760                         row.AcceptChanges();
1761                         Assert.AreEqual(DataRowState.Unchanged, row.RowState, "#3");
1762                         row.SetModified ();
1763                         Assert.AreEqual(DataRowState.Modified, row.RowState, "#4");
1764                 }
1765
1766                 [Test]
1767                 public void setModified_testRollback()
1768                 {
1769                         DataTable table = new DataTable();
1770                         table.Columns.Add("col1", typeof(int));
1771                         table.Columns.Add("col2", typeof(int));
1772
1773                         DataRow row = table.Rows.Add(new object[] { 1, 1 });
1774                         table.AcceptChanges();
1775
1776                         row.SetModified ();
1777                         Assert.AreEqual(row.RowState, DataRowState.Modified, "#0");
1778                         Assert.AreEqual(1, row [0, DataRowVersion.Current], "#1");
1779                         Assert.AreEqual(1, row [0, DataRowVersion.Original], "#2");
1780                         table.RejectChanges ();
1781                         Assert.AreEqual(row.RowState, DataRowState.Unchanged, "#3");
1782                 }
1783 #endif
1784         }
1785 }