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