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.
31 using System.Data.Odbc;
32 using System.Data.OleDb;
34 using NUnit.Framework;
36 namespace MonoTests.System.Data.OleDb
39 public class OleDbDataAdapterTest
41 [Test] // OleDbDataAdapter ()
42 public void Constructor1 ()
44 OleDbDataAdapter da = new OleDbDataAdapter ();
45 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
46 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
47 Assert.IsNull (da.Container, "#3");
48 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
49 Assert.IsNull (da.DeleteCommand, "#5");
50 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
51 Assert.IsNull (da.InsertCommand, "#7");
52 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
53 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
54 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
55 Assert.IsNull (da.SelectCommand, "#11");
56 Assert.IsNull (da.Site, "#12");
57 Assert.IsNotNull (da.TableMappings, "#13");
58 Assert.AreEqual (0, da.TableMappings.Count, "#14");
59 Assert.AreEqual (1, da.UpdateBatchSize, "#15");
60 Assert.IsNull (da.UpdateCommand, "#16");
63 [Test] // OleDbDataAdapter (OleDbCommand)
64 public void Constructor2 ()
66 OleDbCommand cmd = new OleDbCommand ();
67 OleDbDataAdapter da = new OleDbDataAdapter (cmd);
68 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
69 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
70 Assert.IsNull (da.Container, "#3");
71 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
72 Assert.IsNull (da.DeleteCommand, "#5");
73 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
74 Assert.IsNull (da.InsertCommand, "#7");
75 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
76 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
77 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
78 Assert.IsNotNull (da.SelectCommand, "#11");
79 Assert.AreSame (cmd, da.SelectCommand, "#12");
80 Assert.IsNull (da.Site, "#13");
81 Assert.IsNotNull (da.TableMappings, "#14");
82 Assert.AreEqual (0, da.TableMappings.Count, "#15");
83 Assert.AreEqual (1, da.UpdateBatchSize, "#16");
84 Assert.IsNull (da.UpdateCommand, "#17");
87 [Test] // OleDbDataAdapter (OleDbCommand)
88 public void Constructor2_SelectCommand_Null ()
90 OleDbDataAdapter da = new OleDbDataAdapter ((OleDbCommand) null);
91 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
92 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
93 Assert.IsNull (da.Container, "#3");
94 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
95 Assert.IsNull (da.DeleteCommand, "#5");
96 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
97 Assert.IsNull (da.InsertCommand, "#7");
98 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
99 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
100 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
101 Assert.IsNull (da.SelectCommand, "#11");
102 Assert.IsNull (da.Site, "#12");
103 Assert.IsNotNull (da.TableMappings, "#13");
104 Assert.AreEqual (0, da.TableMappings.Count, "#14");
105 Assert.AreEqual (1, da.UpdateBatchSize, "#15");
106 Assert.IsNull (da.UpdateCommand, "#16");
109 [Test] // OleDbDataAdapter (string, OleDbCommand)
110 public void Constructor3 ()
112 string selectCommandText = "SELECT * FROM Authors";
113 OleDbConnection selectConnection = new OleDbConnection ();
115 OleDbDataAdapter da = new OleDbDataAdapter (selectCommandText,
117 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
118 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
119 Assert.IsNull (da.Container, "#3");
120 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
121 Assert.IsNull (da.DeleteCommand, "#5");
122 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
123 Assert.IsNull (da.InsertCommand, "#7");
124 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
125 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
126 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
127 Assert.IsNotNull (da.SelectCommand, "#11");
128 Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
129 Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#13");
130 Assert.IsNull (da.Site, "#14");
131 Assert.IsNotNull (da.TableMappings, "#15");
132 Assert.AreEqual (0, da.TableMappings.Count, "#16");
133 Assert.AreEqual (1, da.UpdateBatchSize, "#17");
134 Assert.IsNull (da.UpdateCommand, "#18");
137 [Test] // OleDbDataAdapter (string, OleDbConnection)
138 public void Constructor3_SelectCommandText_Null ()
140 OleDbConnection selectConnection = new OleDbConnection ();
142 OleDbDataAdapter da = new OleDbDataAdapter ((string) null,
144 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
145 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
146 Assert.IsNull (da.Container, "#3");
147 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
148 Assert.IsNull (da.DeleteCommand, "#5");
149 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
150 Assert.IsNull (da.InsertCommand, "#7");
151 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
152 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
153 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
154 Assert.IsNotNull (da.SelectCommand, "#11");
155 Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
156 Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
157 Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#14");
158 Assert.IsNull (da.Site, "#15");
159 Assert.IsNotNull (da.TableMappings, "#16");
160 Assert.AreEqual (0, da.TableMappings.Count, "#17");
161 Assert.AreEqual (1, da.UpdateBatchSize, "#18");
162 Assert.IsNull (da.UpdateCommand, "#19");
165 [Test] // OleDbDataAdapter (string, OleDbConnection)
166 public void Constructor3_SelectConnection_Null ()
168 string selectCommandText = "SELECT * FROM Authors";
170 OleDbDataAdapter da = new OleDbDataAdapter (selectCommandText,
171 (OleDbConnection) null);
172 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
173 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
174 Assert.IsNull (da.Container, "#3");
175 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
176 Assert.IsNull (da.DeleteCommand, "#5");
177 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
178 Assert.IsNull (da.InsertCommand, "#7");
179 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
180 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
181 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
182 Assert.IsNotNull (da.SelectCommand, "#11");
183 Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
184 Assert.IsNull (da.SelectCommand.Connection, "#13");
185 Assert.IsNull (da.Site, "#14");
186 Assert.IsNotNull (da.TableMappings, "#15");
187 Assert.AreEqual (0, da.TableMappings.Count, "#16");
188 Assert.AreEqual (1, da.UpdateBatchSize, "#17");
189 Assert.IsNull (da.UpdateCommand, "#18");
192 [Test] // OleDbDataAdapter (string, string)]
193 public void Constructor4 ()
195 string selectCommandText = "SELECT * FROM Authors";
196 string selectConnectionString = "Provider=SQLOLEDB;Data Source=SQLSRV;";
198 OleDbDataAdapter da = new OleDbDataAdapter (selectCommandText,
199 selectConnectionString);
200 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
201 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
202 Assert.IsNull (da.Container, "#3");
203 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
204 Assert.IsNull (da.DeleteCommand, "#5");
205 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
206 Assert.IsNull (da.InsertCommand, "#7");
207 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
208 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
209 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
210 Assert.IsNotNull (da.SelectCommand, "#11");
211 Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
212 Assert.IsNotNull (da.SelectCommand.Connection, "#13");
213 Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#14");
214 Assert.IsNull (da.Site, "#15");
215 Assert.IsNotNull (da.TableMappings, "#16");
216 Assert.AreEqual (0, da.TableMappings.Count, "#17");
217 Assert.AreEqual (1, da.UpdateBatchSize, "#18");
218 Assert.IsNull (da.UpdateCommand, "#19");
221 [Test] // OleDbDataAdapter (string, string)]
222 public void Constructor4_SelectCommandText_Null ()
224 string selectConnectionString = "Provider=SQLOLEDB;Data Source=SQLSRV;";
226 OleDbDataAdapter da = new OleDbDataAdapter ((string) null,
227 selectConnectionString);
228 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
229 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
230 Assert.IsNull (da.Container, "#3");
231 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
232 Assert.IsNull (da.DeleteCommand, "#5");
233 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
234 Assert.IsNull (da.InsertCommand, "#7");
235 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
236 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
237 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
238 Assert.IsNotNull (da.SelectCommand, "#11");
239 Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
240 Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
241 Assert.IsNotNull (da.SelectCommand.Connection, "#14");
242 Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#15");
243 Assert.IsNull (da.Site, "#16");
244 Assert.IsNotNull (da.TableMappings, "#17");
245 Assert.AreEqual (0, da.TableMappings.Count, "#18");
246 Assert.AreEqual (1, da.UpdateBatchSize, "#19");
247 Assert.IsNull (da.UpdateCommand, "#20");
250 [Test] // OleDbDataAdapter (string, string)]
251 public void Constructor4_SelectConnectionString_Null ()
253 string selectCommandText = "SELECT * FROM Authors";
255 OleDbDataAdapter da = new OleDbDataAdapter (selectCommandText,
257 Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
258 Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
259 Assert.IsNull (da.Container, "#3");
260 Assert.IsFalse (da.ContinueUpdateOnError, "#4");
261 Assert.IsNull (da.DeleteCommand, "#5");
262 Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
263 Assert.IsNull (da.InsertCommand, "#7");
264 Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
265 Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
266 Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
267 Assert.IsNotNull (da.SelectCommand, "#11");
268 Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
269 Assert.IsNotNull (da.SelectCommand.Connection, "#14");
270 Assert.AreEqual (string.Empty, da.SelectCommand.Connection.ConnectionString, "#15");
271 Assert.IsNull (da.Site, "#16");
272 Assert.IsNotNull (da.TableMappings, "#17");
273 Assert.AreEqual (0, da.TableMappings.Count, "#18");
274 Assert.AreEqual (1, da.UpdateBatchSize, "#19");
275 Assert.IsNull (da.UpdateCommand, "#20");
279 public void DeleteCommand ()
281 OleDbDataAdapter da = new OleDbDataAdapter ();
282 OleDbCommand cmd1 = new OleDbCommand ();
283 OleDbCommand cmd2 = new OleDbCommand ();
285 da.DeleteCommand = cmd1;
286 Assert.AreSame (cmd1, da.DeleteCommand, "#1");
287 da.DeleteCommand = cmd2;
288 Assert.AreSame (cmd2, da.DeleteCommand, "#2");
289 da.DeleteCommand = null;
290 Assert.IsNull (da.DeleteCommand, "#3");
294 public void DeleteCommand_IDbDataAdapter ()
296 IDbDataAdapter da = new OleDbDataAdapter ();
297 OleDbCommand cmd1 = new OleDbCommand ();
298 OleDbCommand cmd2 = new OleDbCommand ();
300 da.DeleteCommand = cmd1;
301 Assert.AreSame (cmd1, da.DeleteCommand, "#A1");
302 da.DeleteCommand = cmd2;
303 Assert.AreSame (cmd2, da.DeleteCommand, "#A2");
304 da.DeleteCommand = null;
305 Assert.IsNull (da.DeleteCommand, "#A3");
308 da.DeleteCommand = new OdbcCommand ();
310 } catch (InvalidCastException ex) {
311 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
312 Assert.IsNull (ex.InnerException, "#B3");
313 Assert.IsNotNull (ex.Message, "#B4");
318 public void Dispose ()
320 OleDbDataAdapter da = new OleDbDataAdapter ();
321 da.DeleteCommand = new OleDbCommand ();
322 da.InsertCommand = new OleDbCommand ();
323 da.SelectCommand = new OleDbCommand ();
324 da.UpdateCommand = new OleDbCommand ();
327 Assert.IsNull (da.DeleteCommand, "#1");
328 Assert.IsNull (da.InsertCommand, "#2");
329 Assert.IsNull (da.SelectCommand, "#3");
330 Assert.IsNotNull (da.TableMappings, "#4");
331 Assert.AreEqual (0, da.TableMappings.Count, "#5");
332 Assert.IsNull (da.UpdateCommand, "#6");
336 public void InsertCommand ()
338 OleDbDataAdapter da = new OleDbDataAdapter ();
339 OleDbCommand cmd1 = new OleDbCommand ();
340 OleDbCommand cmd2 = new OleDbCommand ();
342 da.InsertCommand = cmd1;
343 Assert.AreSame (cmd1, da.InsertCommand, "#1");
344 da.InsertCommand = cmd2;
345 Assert.AreSame (cmd2, da.InsertCommand, "#2");
346 da.InsertCommand = null;
347 Assert.IsNull (da.InsertCommand, "#3");
351 public void InsertCommand_IDbDataAdapter ()
353 IDbDataAdapter da = new OleDbDataAdapter ();
354 OleDbCommand cmd1 = new OleDbCommand ();
355 OleDbCommand cmd2 = new OleDbCommand ();
357 da.InsertCommand = cmd1;
358 Assert.AreSame (cmd1, da.InsertCommand, "#A1");
359 da.InsertCommand = cmd2;
360 Assert.AreSame (cmd2, da.InsertCommand, "#A2");
361 da.InsertCommand = null;
362 Assert.IsNull (da.InsertCommand, "#A3");
365 da.InsertCommand = new OdbcCommand ();
367 } catch (InvalidCastException ex) {
368 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
369 Assert.IsNull (ex.InnerException, "#B3");
370 Assert.IsNotNull (ex.Message, "#B4");
375 public void SelectCommand ()
377 OleDbDataAdapter da = new OleDbDataAdapter ();
378 OleDbCommand cmd1 = new OleDbCommand ();
379 OleDbCommand cmd2 = new OleDbCommand ();
381 da.SelectCommand = cmd1;
382 Assert.AreSame (cmd1, da.SelectCommand, "#1");
383 da.SelectCommand = cmd2;
384 Assert.AreSame (cmd2, da.SelectCommand, "#2");
385 da.SelectCommand = null;
386 Assert.IsNull (da.SelectCommand, "#3");
390 public void SelectCommand_IDbDataAdapter ()
392 IDbDataAdapter da = new OleDbDataAdapter ();
393 OleDbCommand cmd1 = new OleDbCommand ();
394 OleDbCommand cmd2 = new OleDbCommand ();
396 da.SelectCommand = cmd1;
397 Assert.AreSame (cmd1, da.SelectCommand, "#A1");
398 da.SelectCommand = cmd2;
399 Assert.AreSame (cmd2, da.SelectCommand, "#A2");
400 da.SelectCommand = null;
401 Assert.IsNull (da.SelectCommand, "#A3");
404 da.SelectCommand = new OdbcCommand ();
406 } catch (InvalidCastException ex) {
407 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
408 Assert.IsNull (ex.InnerException, "#B3");
409 Assert.IsNotNull (ex.Message, "#B4");
414 public void UpdateCommand ()
416 OleDbDataAdapter da = new OleDbDataAdapter ();
417 OleDbCommand cmd1 = new OleDbCommand ();
418 OleDbCommand cmd2 = new OleDbCommand ();
420 da.UpdateCommand = cmd1;
421 Assert.AreSame (cmd1, da.UpdateCommand, "#1");
422 da.UpdateCommand = cmd2;
423 Assert.AreSame (cmd2, da.UpdateCommand, "#2");
424 da.UpdateCommand = null;
425 Assert.IsNull (da.UpdateCommand, "#3");
429 public void UpdateCommand_IDbDataAdapter ()
431 IDbDataAdapter da = new OleDbDataAdapter ();
432 OleDbCommand cmd1 = new OleDbCommand ();
433 OleDbCommand cmd2 = new OleDbCommand ();
435 da.UpdateCommand = cmd1;
436 Assert.AreSame (cmd1, da.UpdateCommand, "#A1");
437 da.UpdateCommand = cmd2;
438 Assert.AreSame (cmd2, da.UpdateCommand, "#A2");
439 da.UpdateCommand = null;
440 Assert.IsNull (da.UpdateCommand, "#A3");
443 da.UpdateCommand = new OdbcCommand ();
445 } catch (InvalidCastException ex) {
446 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
447 Assert.IsNull (ex.InnerException, "#B3");
448 Assert.IsNotNull (ex.Message, "#B4");