301f62bf7f22efba750f3a3ac4cc9d7c46183bd3
[mono.git] / mcs / class / System.Data / Test / System.Data.SqlClient / SqlDataAdapterTest.cs
1 //
2 // SqlDataAdapterTest.cs - NUnit Test Cases for testing the
3 //                        SqlDataAdapter class
4 // Author:
5 //      Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // Copyright (c) 2007 Gert Driesen
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 System;
30 using System.Data;
31 using System.Data.SqlClient;
32 #if !MOBILE
33 using System.Data.Odbc;
34 #endif
35
36 using NUnit.Framework;
37
38 namespace MonoTests.System.Data.SqlClient
39 {
40         [TestFixture]
41         public class SqlDataAdapterTest
42         {
43                 [Test] // SqlDataAdapter ()
44                 public void Constructor1 ()
45                 {
46                         SqlDataAdapter da = new SqlDataAdapter ();
47                         Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
48                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
49                         Assert.IsNull (da.Container, "#3");
50                         Assert.IsFalse (da.ContinueUpdateOnError, "#4");
51                         Assert.IsNull (da.DeleteCommand, "#5");
52                         Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
53                         Assert.IsNull (da.InsertCommand, "#7");
54                         Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
55                         Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
56                         Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
57                         Assert.IsNull (da.SelectCommand, "#11");
58                         Assert.IsNull (da.Site, "#12");
59                         Assert.IsNotNull (da.TableMappings, "#13");
60                         Assert.AreEqual (0, da.TableMappings.Count, "#14");
61                         Assert.AreEqual (1, da.UpdateBatchSize, "#15");
62                         Assert.IsNull (da.UpdateCommand, "#16");
63                 }
64
65                 [Test] // SqlDataAdapter (SqlCommand)
66                 public void Constructor2 ()
67                 {
68                         SqlCommand cmd = new SqlCommand ();
69                         SqlDataAdapter da = new SqlDataAdapter (cmd);
70                         Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
71                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
72                         Assert.IsNull (da.Container, "#3");
73                         Assert.IsFalse (da.ContinueUpdateOnError, "#4");
74                         Assert.IsNull (da.DeleteCommand, "#5");
75                         Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
76                         Assert.IsNull (da.InsertCommand, "#7");
77                         Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
78                         Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
79                         Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
80                         Assert.IsNotNull (da.SelectCommand, "#11");
81                         Assert.AreSame (cmd, da.SelectCommand, "#12");
82                         Assert.IsNull (da.Site, "#13");
83                         Assert.IsNotNull (da.TableMappings, "#14");
84                         Assert.AreEqual (0, da.TableMappings.Count, "#15");
85                         Assert.AreEqual (1, da.UpdateBatchSize, "#16");
86                         Assert.IsNull (da.UpdateCommand, "#17");
87                 }
88
89                 [Test] // SqlDataAdapter (SqlCommand)
90                 public void Constructor2_SelectCommand_Null ()
91                 {
92                         SqlDataAdapter da = new SqlDataAdapter ((SqlCommand) null);
93                         Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
94                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
95                         Assert.IsNull (da.Container, "#3");
96                         Assert.IsFalse (da.ContinueUpdateOnError, "#4");
97                         Assert.IsNull (da.DeleteCommand, "#5");
98                         Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
99                         Assert.IsNull (da.InsertCommand, "#7");
100                         Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
101                         Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
102                         Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
103                         Assert.IsNull (da.SelectCommand, "#11");
104                         Assert.IsNull (da.Site, "#12");
105                         Assert.IsNotNull (da.TableMappings, "#13");
106                         Assert.AreEqual (0, da.TableMappings.Count, "#14");
107                         Assert.AreEqual (1, da.UpdateBatchSize, "#15");
108                         Assert.IsNull (da.UpdateCommand, "#16");
109                 }
110
111                 [Test] // SqlDataAdapter (string, SqlConnection)
112                 public void Constructor3 ()
113                 {
114                         string selectCommandText = "SELECT * FROM Authors";
115                         SqlConnection selectConnection = new SqlConnection ();
116
117                         SqlDataAdapter da = new SqlDataAdapter (selectCommandText,
118                                 selectConnection);
119                         Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
120                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
121                         Assert.IsNull (da.Container, "#3");
122                         Assert.IsFalse (da.ContinueUpdateOnError, "#4");
123                         Assert.IsNull (da.DeleteCommand, "#5");
124                         Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
125                         Assert.IsNull (da.InsertCommand, "#7");
126                         Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
127                         Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
128                         Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
129                         Assert.IsNotNull (da.SelectCommand, "#11");
130                         Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
131                         Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#13");
132                         Assert.IsNull (da.Site, "#14");
133                         Assert.IsNotNull (da.TableMappings, "#15");
134                         Assert.AreEqual (0, da.TableMappings.Count, "#16");
135                         Assert.AreEqual (1, da.UpdateBatchSize, "#17");
136                         Assert.IsNull (da.UpdateCommand, "#18");
137                 }
138
139                 [Test] // SqlDataAdapter (string, SqlConnection)
140                 public void Constructor3_SelectCommandText_Null ()
141                 {
142                         SqlConnection selectConnection = new SqlConnection ();
143
144                         SqlDataAdapter da = new SqlDataAdapter ((string) null,
145                                 selectConnection);
146                         Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
147                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
148                         Assert.IsNull (da.Container, "#3");
149                         Assert.IsFalse (da.ContinueUpdateOnError, "#4");
150                         Assert.IsNull (da.DeleteCommand, "#5");
151                         Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
152                         Assert.IsNull (da.InsertCommand, "#7");
153                         Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
154                         Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
155                         Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
156                         Assert.IsNotNull (da.SelectCommand, "#11");
157                         Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
158                         Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
159                         Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#14");
160                         Assert.IsNull (da.Site, "#15");
161                         Assert.IsNotNull (da.TableMappings, "#16");
162                         Assert.AreEqual (0, da.TableMappings.Count, "#17");
163                         Assert.AreEqual (1, da.UpdateBatchSize, "#18");
164                         Assert.IsNull (da.UpdateCommand, "#19");
165                 }
166
167                 [Test] // SqlDataAdapter (string, SqlConnection)
168                 public void Constructor3_SelectConnection_Null ()
169                 {
170                         string selectCommandText = "SELECT * FROM Authors";
171
172                         SqlDataAdapter da = new SqlDataAdapter (selectCommandText,
173                                 (SqlConnection) null);
174                         Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
175                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
176                         Assert.IsNull (da.Container, "#3");
177                         Assert.IsFalse (da.ContinueUpdateOnError, "#4");
178                         Assert.IsNull (da.DeleteCommand, "#5");
179                         Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
180                         Assert.IsNull (da.InsertCommand, "#7");
181                         Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
182                         Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
183                         Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
184                         Assert.IsNotNull (da.SelectCommand, "#11");
185                         Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
186                         Assert.IsNull (da.SelectCommand.Connection, "#13");
187                         Assert.IsNull (da.Site, "#14");
188                         Assert.IsNotNull (da.TableMappings, "#15");
189                         Assert.AreEqual (0, da.TableMappings.Count, "#16");
190                         Assert.AreEqual (1, da.UpdateBatchSize, "#17");
191                         Assert.IsNull (da.UpdateCommand, "#18");
192                 }
193
194                 [Test] // SqlDataAdapter (string, string)]
195                 public void Constructor4 ()
196                 {
197                         string selectCommandText = "SELECT * FROM Authors";
198                         string selectConnectionString = "server=SQLSRV;database=Mono";
199
200                         SqlDataAdapter da = new SqlDataAdapter (selectCommandText,
201                                 selectConnectionString);
202                         Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
203                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
204                         Assert.IsNull (da.Container, "#3");
205                         Assert.IsFalse (da.ContinueUpdateOnError, "#4");
206                         Assert.IsNull (da.DeleteCommand, "#5");
207                         Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
208                         Assert.IsNull (da.InsertCommand, "#7");
209                         Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
210                         Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
211                         Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
212                         Assert.IsNotNull (da.SelectCommand, "#11");
213                         Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
214                         Assert.IsNotNull (da.SelectCommand.Connection, "#13");
215                         Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#14");
216                         Assert.IsNull (da.Site, "#15");
217                         Assert.IsNotNull (da.TableMappings, "#16");
218                         Assert.AreEqual (0, da.TableMappings.Count, "#17");
219                         Assert.AreEqual (1, da.UpdateBatchSize, "#18");
220                         Assert.IsNull (da.UpdateCommand, "#19");
221                 }
222
223                 [Test] // SqlDataAdapter (string, string)]
224                 public void Constructor4_SelectCommandText_Null ()
225                 {
226                         string selectConnectionString = "server=SQLSRV;database=Mono";
227
228                         SqlDataAdapter da = new SqlDataAdapter ((string) null,
229                                 selectConnectionString);
230                         Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
231                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
232                         Assert.IsNull (da.Container, "#3");
233                         Assert.IsFalse (da.ContinueUpdateOnError, "#4");
234                         Assert.IsNull (da.DeleteCommand, "#5");
235                         Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
236                         Assert.IsNull (da.InsertCommand, "#7");
237                         Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
238                         Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
239                         Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
240                         Assert.IsNotNull (da.SelectCommand, "#11");
241                         Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
242                         Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
243                         Assert.IsNotNull (da.SelectCommand.Connection, "#14");
244                         Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#15");
245                         Assert.IsNull (da.Site, "#16");
246                         Assert.IsNotNull (da.TableMappings, "#17");
247                         Assert.AreEqual (0, da.TableMappings.Count, "#18");
248                         Assert.AreEqual (1, da.UpdateBatchSize, "#19");
249                         Assert.IsNull (da.UpdateCommand, "#20");
250                 }
251
252                 [Test] // SqlDataAdapter (string, string)]
253                 public void Constructor4_SelectConnectionString_Null ()
254                 {
255                         string selectCommandText = "SELECT * FROM Authors";
256
257                         SqlDataAdapter da = new SqlDataAdapter (selectCommandText,
258                                 (string) null);
259                         Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
260                         Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
261                         Assert.IsNull (da.Container, "#3");
262                         Assert.IsFalse (da.ContinueUpdateOnError, "#4");
263                         Assert.IsNull (da.DeleteCommand, "#5");
264                         Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
265                         Assert.IsNull (da.InsertCommand, "#7");
266                         Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
267                         Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
268                         Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
269                         Assert.IsNotNull (da.SelectCommand, "#11");
270                         Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
271                         Assert.IsNotNull (da.SelectCommand.Connection, "#14");
272                         Assert.AreEqual (string.Empty, da.SelectCommand.Connection.ConnectionString, "#15");
273                         Assert.IsNull (da.Site, "#16");
274                         Assert.IsNotNull (da.TableMappings, "#17");
275                         Assert.AreEqual (0, da.TableMappings.Count, "#18");
276                         Assert.AreEqual (1, da.UpdateBatchSize, "#19");
277                         Assert.IsNull (da.UpdateCommand, "#20");
278                 }
279
280                 [Test]
281                 public void DeleteCommand ()
282                 {
283                         SqlDataAdapter da = new SqlDataAdapter ();
284                         SqlCommand cmd1 = new SqlCommand ();
285                         SqlCommand cmd2 = new SqlCommand ();
286
287                         da.DeleteCommand = cmd1;
288                         Assert.AreSame (cmd1, da.DeleteCommand, "#1");
289                         da.DeleteCommand = cmd2;
290                         Assert.AreSame (cmd2, da.DeleteCommand, "#2");
291                         da.DeleteCommand = null;
292                         Assert.IsNull (da.DeleteCommand, "#3");
293                 }
294
295                 [Test]
296                 public void Dispose ()
297                 {
298                         SqlDataAdapter da = new SqlDataAdapter ();
299                         da.DeleteCommand = new SqlCommand ();
300                         da.InsertCommand = new SqlCommand ();
301                         da.SelectCommand = new SqlCommand ();
302                         da.UpdateCommand = new SqlCommand ();
303                         da.Dispose ();
304
305                         Assert.IsNull (da.DeleteCommand, "#1");
306                         Assert.IsNull (da.InsertCommand, "#2");
307                         Assert.IsNull (da.SelectCommand, "#3");
308                         Assert.IsNotNull (da.TableMappings, "#4");
309                         Assert.AreEqual (0, da.TableMappings.Count, "#5");
310                         Assert.IsNull (da.UpdateCommand, "#6");
311                 }
312
313                 [Test]
314                 public void InsertCommand ()
315                 {
316                         SqlDataAdapter da = new SqlDataAdapter ();
317                         SqlCommand cmd1 = new SqlCommand ();
318                         SqlCommand cmd2 = new SqlCommand ();
319
320                         da.InsertCommand = cmd1;
321                         Assert.AreSame (cmd1, da.InsertCommand, "#1");
322                         da.InsertCommand = cmd2;
323                         Assert.AreSame (cmd2, da.InsertCommand, "#2");
324                         da.InsertCommand = null;
325                         Assert.IsNull (da.InsertCommand, "#3");
326                 }
327
328                 [Test]
329                 public void SelectCommand ()
330                 {
331                         SqlDataAdapter da = new SqlDataAdapter ();
332                         SqlCommand cmd1 = new SqlCommand ();
333                         SqlCommand cmd2 = new SqlCommand ();
334
335                         da.SelectCommand = cmd1;
336                         Assert.AreSame (cmd1, da.SelectCommand, "#1");
337                         da.SelectCommand = cmd2;
338                         Assert.AreSame (cmd2, da.SelectCommand, "#2");
339                         da.SelectCommand = null;
340                         Assert.IsNull (da.SelectCommand, "#3");
341                 }
342
343                 [Test]
344                 public void UpdateBatchSize ()
345                 {
346                         SqlDataAdapter da = new SqlDataAdapter ();
347                         da.UpdateBatchSize = 0;
348                         Assert.AreEqual (0, da.UpdateBatchSize, "#1");
349                         da.UpdateBatchSize = int.MaxValue;
350                         Assert.AreEqual (int.MaxValue, da.UpdateBatchSize, "#2");
351                         da.UpdateBatchSize = 1;
352                         Assert.AreEqual (1, da.UpdateBatchSize, "#3");
353                 }
354                 
355                 [Test]
356                 public void UpdateBatchSize_Negative ()
357                 {
358                         SqlDataAdapter da = new SqlDataAdapter ();
359                         try {
360                                 da.UpdateBatchSize = -1;
361                                 Assert.Fail ("#1");
362                         } catch (ArgumentOutOfRangeException ex) {
363                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
364                                 Assert.IsNull (ex.InnerException, "#3");
365                                 Assert.IsNotNull (ex.Message, "#4");
366                                 Assert.IsNotNull (ex.ParamName, "#5");
367                                 Assert.AreEqual ("UpdateBatchSize", ex.ParamName, "#6");
368                         }
369                 }
370
371                 [Test]
372                 public void UpdateCommand ()
373                 {
374                         SqlDataAdapter da = new SqlDataAdapter ();
375                         SqlCommand cmd1 = new SqlCommand ();
376                         SqlCommand cmd2 = new SqlCommand ();
377
378                         da.UpdateCommand = cmd1;
379                         Assert.AreSame (cmd1, da.UpdateCommand, "#1");
380                         da.UpdateCommand = cmd2;
381                         Assert.AreSame (cmd2, da.UpdateCommand, "#2");
382                         da.UpdateCommand = null;
383                         Assert.IsNull (da.UpdateCommand, "#3");
384                 }
385
386 #if !MOBILE
387                 [Test]
388                 public void DeleteCommand_IDbDataAdapter ()
389                 {
390                         IDbDataAdapter da = new SqlDataAdapter ();
391                         SqlCommand cmd1 = new SqlCommand ();
392                         SqlCommand cmd2 = new SqlCommand ();
393                         
394                         da.DeleteCommand = cmd1;
395                         Assert.AreSame (cmd1, da.DeleteCommand, "#A1");
396                         da.DeleteCommand = cmd2;
397                         Assert.AreSame (cmd2, da.DeleteCommand, "#A2");
398                         da.DeleteCommand = null;
399                         Assert.IsNull (da.DeleteCommand, "#A3");
400                         
401                         try {
402                                 da.DeleteCommand = new OdbcCommand ();
403                                 Assert.Fail ("#B1");
404                         } catch (InvalidCastException ex) {
405                                 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
406                                 Assert.IsNull (ex.InnerException, "#B3");
407                                 Assert.IsNotNull (ex.Message, "#B4");
408                         }
409                 }
410
411                 
412                 [Test]
413                 public void InsertCommand_IDbDataAdapter ()
414                 {
415                         IDbDataAdapter da = new SqlDataAdapter ();
416                         SqlCommand cmd1 = new SqlCommand ();
417                         SqlCommand cmd2 = new SqlCommand ();
418                         
419                         da.InsertCommand = cmd1;
420                         Assert.AreSame (cmd1, da.InsertCommand, "#A1");
421                         da.InsertCommand = cmd2;
422                         Assert.AreSame (cmd2, da.InsertCommand, "#A2");
423                         da.InsertCommand = null;
424                         Assert.IsNull (da.InsertCommand, "#A3");
425                         
426                         try {
427                                 da.InsertCommand = new OdbcCommand ();
428                                 Assert.Fail ("#B1");
429                         } catch (InvalidCastException ex) {
430                                 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
431                                 Assert.IsNull (ex.InnerException, "#B3");
432                                 Assert.IsNotNull (ex.Message, "#B4");
433                         }
434                 }
435
436                 [Test]
437                 public void SelectCommand_IDbDataAdapter ()
438                 {
439                         IDbDataAdapter da = new SqlDataAdapter ();
440                         SqlCommand cmd1 = new SqlCommand ();
441                         SqlCommand cmd2 = new SqlCommand ();
442                         
443                         da.SelectCommand = cmd1;
444                         Assert.AreSame (cmd1, da.SelectCommand, "#A1");
445                         da.SelectCommand = cmd2;
446                         Assert.AreSame (cmd2, da.SelectCommand, "#A2");
447                         da.SelectCommand = null;
448                         Assert.IsNull (da.SelectCommand, "#A3");
449                         
450                         try {
451                                 da.SelectCommand = new OdbcCommand ();
452                                 Assert.Fail ("#B1");
453                         } catch (InvalidCastException ex) {
454                                 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
455                                 Assert.IsNull (ex.InnerException, "#B3");
456                                 Assert.IsNotNull (ex.Message, "#B4");
457                         }
458                 }
459
460                 [Test]
461                 public void UpdateCommand_IDbDataAdapter ()
462                 {
463                         IDbDataAdapter da = new SqlDataAdapter ();
464                         SqlCommand cmd1 = new SqlCommand ();
465                         SqlCommand cmd2 = new SqlCommand ();
466
467                         da.UpdateCommand = cmd1;
468                         Assert.AreSame (cmd1, da.UpdateCommand, "#A1");
469                         da.UpdateCommand = cmd2;
470                         Assert.AreSame (cmd2, da.UpdateCommand, "#A2");
471                         da.UpdateCommand = null;
472                         Assert.IsNull (da.UpdateCommand, "#A3");
473
474                         try {
475                                 da.UpdateCommand = new OdbcCommand ();
476                                 Assert.Fail ("#B1");
477                         } catch (InvalidCastException ex) {
478                                 Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
479                                 Assert.IsNull (ex.InnerException, "#B3");
480                                 Assert.IsNotNull (ex.Message, "#B4");
481                         }
482                 }
483 #endif
484         }
485 }