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