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
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 Assert.AreEqual ("", v.RowFilter, "RowFilter");
100 Assert.AreEqual ("", v.Sort, "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 Assert.AreEqual (true, drv.IsEdit, "DataView.Item");
116 drv.Row ["col"] = "test";
117 drv.Row.CancelEdit ();
118 Assert.AreEqual (false, drv.IsEdit, "AddNew");
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 Assert.AreEqual ("val", drv ["col"], "DataView.Item");
134 [ExpectedException (typeof (RowNotInTableException))]
135 public void ItemException ()
137 DataTable dt = new DataTable ("table");
138 dt.Columns.Add ("col");
139 dt.Rows.Add ((new object [] {"val"}));
140 DataView dv = new DataView (dt);
141 DataRowView drv = dv.AddNew ();
142 drv.Row ["col"] = "test";
143 drv.Row.CancelEdit ();
144 object o = drv ["col"];
148 public void RowVersion1 ()
150 // I guess we could write better tests.
151 DataTable dt = new DataTable ("table");
152 dt.Columns.Add ("col");
153 dt.Rows.Add (new object [] {1});
154 DataView dv = new DataView (dt);
155 DataRowView drv = dv.AddNew ();
156 Assert.AreEqual (DataRowVersion.Current, drv.RowVersion);
157 Assert.AreEqual (DataRowVersion.Current, dv [0].RowVersion);
159 Assert.AreEqual (DataRowVersion.Current, drv.RowVersion);
160 Assert.AreEqual (DataRowVersion.Current, dv [0].RowVersion);
162 Assert.AreEqual (DataRowVersion.Current, drv.RowVersion);
163 Assert.AreEqual (DataRowVersion.Current, dv [0].RowVersion);
166 Assert.AreEqual (DataRowVersion.Current, drv.RowVersion);
167 Assert.AreEqual (DataRowVersion.Current, dv [0].RowVersion);