5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2005 Novell Inc,
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
34 using System.ComponentModel;
36 namespace MonoTests.System.Data
39 public class DataRowViewTest : Assertion
41 private DataView CreateTestView ()
43 DataTable dt1 = new DataTable ("table1");
44 DataColumn c1 = new DataColumn ("col");
46 dt1.Rows.Add (new object [] {"1"});
47 return new DataView (dt1);
51 [ExpectedException (typeof (ArgumentException))]
52 public void CreateChildViewNullStringArg ()
54 DataView dv = CreateTestView ();
55 DataRowView dvr = dv [0];
56 dvr.CreateChildView ((string) null);
60 [ExpectedException (typeof (ArgumentException))]
61 public void CreateChildViewNullDataRelationArg ()
63 DataView dv = CreateTestView ();
64 DataRowView dvr = dv [0];
65 dvr.CreateChildView ((DataRelation) null);
69 [ExpectedException (typeof (ArgumentException))]
70 public void CreateChildViewNonExistentName ()
72 DataView dv = CreateTestView ();
73 DataRowView dvr = dv [0];
74 dvr.CreateChildView ("nothing");
78 public void CreateChildViewSimple ()
80 DataSet ds = new DataSet ();
82 DataTable dt1 = new DataTable ("table1");
84 DataColumn c1 = new DataColumn ("col");
86 dt1.Rows.Add (new object [] {"1"});
88 DataTable dt2 = new DataTable ("table2");
90 DataColumn c2 = new DataColumn ("col");
92 dt2.Rows.Add (new object [] {"1"});
94 DataRelation dr = new DataRelation ("dr", c1, c2);
96 DataView dv = new DataView (dt1);
97 DataRowView dvr = dv [0];
98 DataView v = dvr.CreateChildView (dr);
99 AssertEquals ("RowFilter", "", v.RowFilter);
100 AssertEquals ("Sort", "", v.Sort);
104 public void IsEdit ()
106 DataTable dt = new DataTable ("table");
107 dt.Columns.Add ("col");
108 dt.Rows.Add ((new object [] {"val"}));
110 DataView dv = new DataView (dt);
111 DataRowView drv = dv [0];
112 dt.Rows [0].BeginEdit ();
113 AssertEquals ("DataView.Item", true, drv.IsEdit);
116 drv.Row ["col"] = "test";
117 drv.Row.CancelEdit ();
118 AssertEquals ("AddNew", false, drv.IsEdit);
124 DataTable dt = new DataTable ("table");
125 dt.Columns.Add ("col");
126 dt.Rows.Add ((new object [] {"val"}));
127 DataView dv = new DataView (dt);
128 DataRowView drv = dv [0];
129 dt.Rows [0].BeginEdit ();
130 AssertEquals ("DataView.Item", "val", drv ["col"]);
134 [ExpectedException (typeof (RowNotInTableException))]
135 // [NUnit.Framework.Category ("NotWorking")]
136 public void ItemException ()
138 DataTable dt = new DataTable ("table");
139 dt.Columns.Add ("col");
140 dt.Rows.Add ((new object [] {"val"}));
141 DataView dv = new DataView (dt);
142 DataRowView drv = dv.AddNew ();
143 drv.Row ["col"] = "test";
144 drv.Row.CancelEdit ();
145 object o = drv ["col"];
149 public void RowVersion1 ()
151 // I guess we could write better tests.
152 DataTable dt = new DataTable ("table");
153 dt.Columns.Add ("col");
154 dt.Rows.Add (new object [] {1});
155 DataView dv = new DataView (dt);
156 DataRowView drv = dv.AddNew ();
157 AssertEquals (DataRowVersion.Current, drv.RowVersion);
158 AssertEquals (DataRowVersion.Current, dv [0].RowVersion);
160 AssertEquals (DataRowVersion.Current, drv.RowVersion);
161 AssertEquals (DataRowVersion.Current, dv [0].RowVersion);
163 AssertEquals (DataRowVersion.Current, drv.RowVersion);
164 AssertEquals (DataRowVersion.Current, dv [0].RowVersion);
167 AssertEquals (DataRowVersion.Current, drv.RowVersion);
168 AssertEquals (DataRowVersion.Current, dv [0].RowVersion);