2 // OleDbDataAdapterTest.cs - NUnit Test Cases for testing the
3 // OleDbDataAdapter class
5 // Gert Driesen (drieseng@users.sourceforge.net)
7 // Copyright (c) 2007 Gert Driesen
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
34 using System.Data.Odbc;
36 using System.Data.OleDb;
38 using NUnit.Framework;
40 namespace MonoTests.System.Data.OleDb
43 public class OleDbDataAdapterTest
45 [Test] // OleDbDataAdapter ()
46 public void Constructor1 ()
48 OleDbDataAdapter da = new OleDbDataAdapter ();
49 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
50 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
51 Assert.IsNull (da.Container, "#3");
52 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
53 Assert.IsNull (da.DeleteCommand, "#5");
54 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
55 Assert.IsNull (da.InsertCommand, "#7");
56 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
57 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
58 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
59 Assert.IsNull (da.SelectCommand, "#11");
60 Assert.IsNull (da.Site, "#12");
61 Assert.IsNotNull (da.TableMappings, "#13");
62 Assert.AreEqual (0, da.TableMappings.Count, "#14");
63 Assert.AreEqual (1, da.UpdateBatchSize, "#15");
64 Assert.IsNull (da.UpdateCommand, "#16");
67 [Test] // OleDbDataAdapter (OleDbCommand)
68 public void Constructor2 ()
70 OleDbCommand cmd = new OleDbCommand ();
71 OleDbDataAdapter da = new OleDbDataAdapter (cmd);
72 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
73 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
74 Assert.IsNull (da.Container, "#3");
75 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
76 Assert.IsNull (da.DeleteCommand, "#5");
77 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
78 Assert.IsNull (da.InsertCommand, "#7");
79 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
80 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
81 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
82 Assert.IsNotNull (da.SelectCommand, "#11");
83 Assert.AreSame (cmd, da.SelectCommand, "#12");
84 Assert.IsNull (da.Site, "#13");
85 Assert.IsNotNull (da.TableMappings, "#14");
86 Assert.AreEqual (0, da.TableMappings.Count, "#15");
87 Assert.AreEqual (1, da.UpdateBatchSize, "#16");
88 Assert.IsNull (da.UpdateCommand, "#17");
91 [Test] // OleDbDataAdapter (OleDbCommand)
92 public void Constructor2_SelectCommand_Null ()
94 OleDbDataAdapter da = new OleDbDataAdapter ((OleDbCommand) null);
95 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
96 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
97 Assert.IsNull (da.Container, "#3");
98 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
99 Assert.IsNull (da.DeleteCommand, "#5");
100 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
101 Assert.IsNull (da.InsertCommand, "#7");
102 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
103 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
104 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
105 Assert.IsNull (da.SelectCommand, "#11");
106 Assert.IsNull (da.Site, "#12");
107 Assert.IsNotNull (da.TableMappings, "#13");
108 Assert.AreEqual (0, da.TableMappings.Count, "#14");
109 Assert.AreEqual (1, da.UpdateBatchSize, "#15");
110 Assert.IsNull (da.UpdateCommand, "#16");
113 [Test] // OleDbDataAdapter (string, OleDbCommand)
114 public void Constructor3 ()
116 string selectCommandText = "SELECT * FROM Authors";
117 OleDbConnection selectConnection = new OleDbConnection ();
119 OleDbDataAdapter da = new OleDbDataAdapter (selectCommandText,
121 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
122 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
123 Assert.IsNull (da.Container, "#3");
124 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
125 Assert.IsNull (da.DeleteCommand, "#5");
126 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
127 Assert.IsNull (da.InsertCommand, "#7");
128 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
129 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
130 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
131 Assert.IsNotNull (da.SelectCommand, "#11");
132 Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
133 Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#13");
134 Assert.IsNull (da.Site, "#14");
135 Assert.IsNotNull (da.TableMappings, "#15");
136 Assert.AreEqual (0, da.TableMappings.Count, "#16");
137 Assert.AreEqual (1, da.UpdateBatchSize, "#17");
138 Assert.IsNull (da.UpdateCommand, "#18");
141 [Test] // OleDbDataAdapter (string, OleDbConnection)
142 public void Constructor3_SelectCommandText_Null ()
144 OleDbConnection selectConnection = new OleDbConnection ();
146 OleDbDataAdapter da = new OleDbDataAdapter ((string) null,
148 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
149 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
150 Assert.IsNull (da.Container, "#3");
151 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
152 Assert.IsNull (da.DeleteCommand, "#5");
153 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
154 Assert.IsNull (da.InsertCommand, "#7");
155 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
156 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
157 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
158 Assert.IsNotNull (da.SelectCommand, "#11");
159 Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
160 Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
161 Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#14");
162 Assert.IsNull (da.Site, "#15");
163 Assert.IsNotNull (da.TableMappings, "#16");
164 Assert.AreEqual (0, da.TableMappings.Count, "#17");
165 Assert.AreEqual (1, da.UpdateBatchSize, "#18");
166 Assert.IsNull (da.UpdateCommand, "#19");
169 [Test] // OleDbDataAdapter (string, OleDbConnection)
170 public void Constructor3_SelectConnection_Null ()
172 string selectCommandText = "SELECT * FROM Authors";
174 OleDbDataAdapter da = new OleDbDataAdapter (selectCommandText,
175 (OleDbConnection) null);
176 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
177 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
178 Assert.IsNull (da.Container, "#3");
179 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
180 Assert.IsNull (da.DeleteCommand, "#5");
181 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
182 Assert.IsNull (da.InsertCommand, "#7");
183 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
184 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
185 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
186 Assert.IsNotNull (da.SelectCommand, "#11");
187 Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
188 Assert.IsNull (da.SelectCommand.Connection, "#13");
189 Assert.IsNull (da.Site, "#14");
190 Assert.IsNotNull (da.TableMappings, "#15");
191 Assert.AreEqual (0, da.TableMappings.Count, "#16");
192 Assert.AreEqual (1, da.UpdateBatchSize, "#17");
193 Assert.IsNull (da.UpdateCommand, "#18");
196 [Test] // OleDbDataAdapter (string, string)]
197 public void Constructor4 ()
199 string selectCommandText = "SELECT * FROM Authors";
200 string selectConnectionString = "Provider=SQLOLEDB;Data Source=SQLSRV;";
202 OleDbDataAdapter da = new OleDbDataAdapter (selectCommandText,
203 selectConnectionString);
204 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
205 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
206 Assert.IsNull (da.Container, "#3");
207 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
208 Assert.IsNull (da.DeleteCommand, "#5");
209 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
210 Assert.IsNull (da.InsertCommand, "#7");
211 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
212 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
213 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
214 Assert.IsNotNull (da.SelectCommand, "#11");
215 Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
216 Assert.IsNotNull (da.SelectCommand.Connection, "#13");
217 Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#14");
218 Assert.IsNull (da.Site, "#15");
219 Assert.IsNotNull (da.TableMappings, "#16");
220 Assert.AreEqual (0, da.TableMappings.Count, "#17");
221 Assert.AreEqual (1, da.UpdateBatchSize, "#18");
222 Assert.IsNull (da.UpdateCommand, "#19");
225 [Test] // OleDbDataAdapter (string, string)]
226 public void Constructor4_SelectCommandText_Null ()
228 string selectConnectionString = "Provider=SQLOLEDB;Data Source=SQLSRV;";
230 OleDbDataAdapter da = new OleDbDataAdapter ((string) null,
231 selectConnectionString);
232 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
233 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
234 Assert.IsNull (da.Container, "#3");
235 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
236 Assert.IsNull (da.DeleteCommand, "#5");
237 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
238 Assert.IsNull (da.InsertCommand, "#7");
239 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
240 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
241 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
242 Assert.IsNotNull (da.SelectCommand, "#11");
243 Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
244 Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
245 Assert.IsNotNull (da.SelectCommand.Connection, "#14");
246 Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#15");
247 Assert.IsNull (da.Site, "#16");
248 Assert.IsNotNull (da.TableMappings, "#17");
249 Assert.AreEqual (0, da.TableMappings.Count, "#18");
250 Assert.AreEqual (1, da.UpdateBatchSize, "#19");
251 Assert.IsNull (da.UpdateCommand, "#20");
254 [Test] // OleDbDataAdapter (string, string)]
255 public void Constructor4_SelectConnectionString_Null ()
257 string selectCommandText = "SELECT * FROM Authors";
259 OleDbDataAdapter da = new OleDbDataAdapter (selectCommandText,
261 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
262 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
263 Assert.IsNull (da.Container, "#3");
264 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
265 Assert.IsNull (da.DeleteCommand, "#5");
266 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
267 Assert.IsNull (da.InsertCommand, "#7");
268 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
269 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
270 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
271 Assert.IsNotNull (da.SelectCommand, "#11");
272 Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
273 Assert.IsNotNull (da.SelectCommand.Connection, "#14");
274 Assert.AreEqual (string.Empty, da.SelectCommand.Connection.ConnectionString, "#15");
275 Assert.IsNull (da.Site, "#16");
276 Assert.IsNotNull (da.TableMappings, "#17");
277 Assert.AreEqual (0, da.TableMappings.Count, "#18");
278 Assert.AreEqual (1, da.UpdateBatchSize, "#19");
279 Assert.IsNull (da.UpdateCommand, "#20");
283 public void DeleteCommand ()
285 OleDbDataAdapter da = new OleDbDataAdapter ();
286 OleDbCommand cmd1 = new OleDbCommand ();
287 OleDbCommand cmd2 = new OleDbCommand ();
289 da.DeleteCommand = cmd1;
290 Assert.AreSame (cmd1, da.DeleteCommand, "#1");
291 da.DeleteCommand = cmd2;
292 Assert.AreSame (cmd2, da.DeleteCommand, "#2");
293 da.DeleteCommand = null;
294 Assert.IsNull (da.DeleteCommand, "#3");
298 public void DeleteCommand_IDbDataAdapter ()
300 IDbDataAdapter da = new OleDbDataAdapter ();
301 OleDbCommand cmd1 = new OleDbCommand ();
302 OleDbCommand cmd2 = new OleDbCommand ();
304 da.DeleteCommand = cmd1;
305 Assert.AreSame (cmd1, da.DeleteCommand, "#A1");
306 da.DeleteCommand = cmd2;
307 Assert.AreSame (cmd2, da.DeleteCommand, "#A2");
308 da.DeleteCommand = null;
309 Assert.IsNull (da.DeleteCommand, "#A3");
312 da.DeleteCommand = new OdbcCommand ();
314 } catch (InvalidCastException ex) {
315 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
316 Assert.IsNull (ex.InnerException, "#B3");
317 Assert.IsNotNull (ex.Message, "#B4");
322 public void Dispose ()
324 OleDbDataAdapter da = new OleDbDataAdapter ();
325 da.DeleteCommand = new OleDbCommand ();
326 da.InsertCommand = new OleDbCommand ();
327 da.SelectCommand = new OleDbCommand ();
328 da.UpdateCommand = new OleDbCommand ();
331 Assert.IsNull (da.DeleteCommand, "#1");
332 Assert.IsNull (da.InsertCommand, "#2");
333 Assert.IsNull (da.SelectCommand, "#3");
334 Assert.IsNotNull (da.TableMappings, "#4");
335 Assert.AreEqual (0, da.TableMappings.Count, "#5");
336 Assert.IsNull (da.UpdateCommand, "#6");
340 public void InsertCommand ()
342 OleDbDataAdapter da = new OleDbDataAdapter ();
343 OleDbCommand cmd1 = new OleDbCommand ();
344 OleDbCommand cmd2 = new OleDbCommand ();
346 da.InsertCommand = cmd1;
347 Assert.AreSame (cmd1, da.InsertCommand, "#1");
348 da.InsertCommand = cmd2;
349 Assert.AreSame (cmd2, da.InsertCommand, "#2");
350 da.InsertCommand = null;
351 Assert.IsNull (da.InsertCommand, "#3");
355 public void InsertCommand_IDbDataAdapter ()
357 IDbDataAdapter da = new OleDbDataAdapter ();
358 OleDbCommand cmd1 = new OleDbCommand ();
359 OleDbCommand cmd2 = new OleDbCommand ();
361 da.InsertCommand = cmd1;
362 Assert.AreSame (cmd1, da.InsertCommand, "#A1");
363 da.InsertCommand = cmd2;
364 Assert.AreSame (cmd2, da.InsertCommand, "#A2");
365 da.InsertCommand = null;
366 Assert.IsNull (da.InsertCommand, "#A3");
369 da.InsertCommand = new OdbcCommand ();
371 } catch (InvalidCastException ex) {
372 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
373 Assert.IsNull (ex.InnerException, "#B3");
374 Assert.IsNotNull (ex.Message, "#B4");
379 public void SelectCommand ()
381 OleDbDataAdapter da = new OleDbDataAdapter ();
382 OleDbCommand cmd1 = new OleDbCommand ();
383 OleDbCommand cmd2 = new OleDbCommand ();
385 da.SelectCommand = cmd1;
386 Assert.AreSame (cmd1, da.SelectCommand, "#1");
387 da.SelectCommand = cmd2;
388 Assert.AreSame (cmd2, da.SelectCommand, "#2");
389 da.SelectCommand = null;
390 Assert.IsNull (da.SelectCommand, "#3");
394 public void SelectCommand_IDbDataAdapter ()
396 IDbDataAdapter da = new OleDbDataAdapter ();
397 OleDbCommand cmd1 = new OleDbCommand ();
398 OleDbCommand cmd2 = new OleDbCommand ();
400 da.SelectCommand = cmd1;
401 Assert.AreSame (cmd1, da.SelectCommand, "#A1");
402 da.SelectCommand = cmd2;
403 Assert.AreSame (cmd2, da.SelectCommand, "#A2");
404 da.SelectCommand = null;
405 Assert.IsNull (da.SelectCommand, "#A3");
408 da.SelectCommand = new OdbcCommand ();
410 } catch (InvalidCastException ex) {
411 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
412 Assert.IsNull (ex.InnerException, "#B3");
413 Assert.IsNotNull (ex.Message, "#B4");
418 public void UpdateCommand ()
420 OleDbDataAdapter da = new OleDbDataAdapter ();
421 OleDbCommand cmd1 = new OleDbCommand ();
422 OleDbCommand cmd2 = new OleDbCommand ();
424 da.UpdateCommand = cmd1;
425 Assert.AreSame (cmd1, da.UpdateCommand, "#1");
426 da.UpdateCommand = cmd2;
427 Assert.AreSame (cmd2, da.UpdateCommand, "#2");
428 da.UpdateCommand = null;
429 Assert.IsNull (da.UpdateCommand, "#3");
433 public void UpdateCommand_IDbDataAdapter ()
435 IDbDataAdapter da = new OleDbDataAdapter ();
436 OleDbCommand cmd1 = new OleDbCommand ();
437 OleDbCommand cmd2 = new OleDbCommand ();
439 da.UpdateCommand = cmd1;
440 Assert.AreSame (cmd1, da.UpdateCommand, "#A1");
441 da.UpdateCommand = cmd2;
442 Assert.AreSame (cmd2, da.UpdateCommand, "#A2");
443 da.UpdateCommand = null;
444 Assert.IsNull (da.UpdateCommand, "#A3");
447 da.UpdateCommand = new OdbcCommand ();
449 } catch (InvalidCastException ex) {
450 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
451 Assert.IsNull (ex.InnerException, "#B3");
452 Assert.IsNotNull (ex.Message, "#B4");