Przeglądaj źródła

* System.Data_test.dll.sources: Added DbDataAdapterTest.cs,
OdbcCommandTest.cs, OdbcConnectionTest.cs, OdbcDataAdapterTest.cs,
OleDbCommandTest.cs, OleDbConnectionTest.cs, OleDbDataAdapterTest.cs,
SqlDataAdapterTest.cs.
* DbDataAdapter.cs: Implemented UpdateBatchSize setter.
* DataAdapter.cs: In FillLoadOption setter, ensure value is valid.
Modified MissingMappingAction and MissingSchemaAction setters to use
ExceptionHelper.CheckEnumValue to validate value. Spaces to tabs and
code formatting.
* ExceptionHelper.cs: Added CheckEnumValue method and modified
InvalidEnumValueException method to return AORE on 2.0 profile. Added
ConnectionClosed method that returns an InvalidOperationException.
* OleDbDataAdapter.cs: In default ctor, set SelectCommand to null.
Only initialize SelectCommand in ctors. Use direct assignment in
IDbDataAdapter implementation.
* OleDbCommand.cs: Added constant for default CommandTimeout, instead
of using a magic number. Avoid unnecessary initialization. Fixed
default value for DesignTimeVisible. Return zero-length string if
CommandText is null. Added implementation for UpdatedRowSource.
* OleDbConnection.cs: Moved initialization of gda to Open ().
Avoid unnecessary initialization. Return zero-length string if
ConnectionString is null. If getters to Database, DataSource and
Provider return zero-length string if the connection is closed.
In ServerVersion, BeginTransaction and GetSchema, throw an
InvalidOperationException if connection is closed.
* OdbcCommand.cs: Added constant for default CommandTimeout, instead
of using a magic number. Avoid unnecessary initialization. Fixed
default value for DesignTimeVisible. Return zero-length string if
CommandText is null. Spaces to tabs and code formatting.
* OdbcError.cs: Fixed typo in exception message.
* OdbcConnection.cs: Return zero-length string if ConnectionString is
null. In getters for Database, DataSource and Driver return a
zero-length string if connection is closed. In BeginTransaction and
GetSchema throw InvalidOperationException if connection is closed.
Added override for GetSchema (string, string []). Use string.Empty
instead of "".
* OdbcDataAdapter.cs: Avoid unnecessary initializations. Use direct
assignment in IDbDataAdapter implementation. In default ctor, set
SelectCommand to null.
* SqlCommand.cs: Added constant for default CommandTimeout, instead
of using a magic number. Avoid unnecessary initialization. Fixed
default value for DesignTimeVisible. Return zero-length string if
CommandText is null. Use ExceptionHelper.InvalidEnumValueException
to avoid code duplication. Spaces to tabs and code formatting.
* SqlConnection.cs: Use different default package size on 2.0 profile.
Added constants for default values, instead of using magic numbers.
Avoid unnecessary initialization. In PacketSize, return default or
configured packet size when connection is not open. Use
ExceptionHelper.ConnectionClosed instead of local method. Removed
use of some hardcoded values in SetDefaultConnectionParameters, and
use Environment.MachineName as default WorkstationId instead of
DNS host name. Code formatting.
* SqlDataAdapter.cs: In default ctor, set SelectCommand to null.
Avoid unnecessary initializations. Use direct assignment in
IDbDataAdapter implementation. Fixed exception message for negative
UpdateBatchSize. In Dispose override, make sure to invoke base
method.
* DbDataAdapterTest.cs: Added test for UpdateBatchSize.
* DataAdapterTest.cs: Added tests for AcceptChangesDuringFile,
AcceptChangesDuringUpdate, ContinueUpdateOnError, FillLoadOption,
MissingMappingAction, MissingSchemaAction and
ReturnProviderSpecificTypes.
* OdbcDataAdapterTest.cs: Added tests for ctors, DeleteCommand,
InsertCommand, SelectCommand, UpdateCommand and Dispose.
* OdbcDataReaderTest.cs: fixed line endings.
* OdbcCommandTest.cs: Added tests for ctors and CommantText.
* OdbcConnectionTest.cs: Removed original test that relied on MySQL.
Added ctor tests. Added tests for BeginTransaction, GetSchema and
ServerVersion with connection that is closed.
* OleDbDataAdapterTest.cs: Added tests for ctors, DeleteCommand,
InsertCommand, SelectCommand, UpdateCommand and Dispose.
* OleDbCommandTest.cs: Added tests for ctors and CommandText.
* OleDbConnectionTest.cs: Added tests for ctors and ConnectionString.
Added tests for BeginTransaction, GetSchema and ServerVersion with connection that is closed.
* SqlCommandTest.cs: Added tests for ctors and CommantText.
* SqlConnectionTest.cs: Added tests for ctors, ConnectionString and
ServerVersion.
* SqlDataAdapterTest.cs: Added tests for ctors, DeleteCommand,
InsertCommand, SelectCommand, UpdateCommand, UpdateBatchSize and
Dispose.

svn path=/trunk/mcs/; revision=87859

Gert Driesen 18 lat temu
rodzic
commit
3930b4b9cf
35 zmienionych plików z 3496 dodań i 456 usunięć
  1. 7 0
      mcs/class/System.Data/ChangeLog
  2. 11 0
      mcs/class/System.Data/System.Data.Common/ChangeLog
  3. 31 42
      mcs/class/System.Data/System.Data.Common/DataAdapter.cs
  4. 4 2
      mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs
  5. 18 0
      mcs/class/System.Data/System.Data.Common/ExceptionHelper.cs
  6. 17 0
      mcs/class/System.Data/System.Data.Odbc/ChangeLog
  7. 60 77
      mcs/class/System.Data/System.Data.Odbc/OdbcCommand.cs
  8. 28 16
      mcs/class/System.Data/System.Data.Odbc/OdbcConnection.cs
  9. 7 25
      mcs/class/System.Data/System.Data.Odbc/OdbcDataAdapter.cs
  10. 1 1
      mcs/class/System.Data/System.Data.Odbc/OdbcError.cs
  11. 16 0
      mcs/class/System.Data/System.Data.OleDb/ChangeLog
  12. 20 14
      mcs/class/System.Data/System.Data.OleDb/OleDbCommand.cs
  13. 24 25
      mcs/class/System.Data/System.Data.OleDb/OleDbConnection.cs
  14. 15 53
      mcs/class/System.Data/System.Data.OleDb/OleDbDataAdapter.cs
  15. 21 0
      mcs/class/System.Data/System.Data.SqlClient/ChangeLog
  16. 24 26
      mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs
  17. 57 60
      mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs
  18. 9 31
      mcs/class/System.Data/System.Data.SqlClient/SqlDataAdapter.cs
  19. 12 4
      mcs/class/System.Data/System.Data_test.dll.sources
  20. 8 0
      mcs/class/System.Data/Test/System.Data.Common/ChangeLog
  21. 207 11
      mcs/class/System.Data/Test/System.Data.Common/DataAdapterTest.cs
  22. 116 0
      mcs/class/System.Data/Test/System.Data.Common/DbDataAdapterTest.cs
  23. 10 0
      mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog
  24. 195 0
      mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs
  25. 233 53
      mcs/class/System.Data/Test/System.Data.Odbc/OdbcConnectionTest.cs
  26. 524 0
      mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataAdapterTest.cs
  27. 4 4
      mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataReaderTest.cs
  28. 9 0
      mcs/class/System.Data/Test/System.Data.OleDb/ChangeLog
  29. 195 0
      mcs/class/System.Data/Test/System.Data.OleDb/OleDbCommandTest.cs
  30. 233 0
      mcs/class/System.Data/Test/System.Data.OleDb/OleDbConnectionTest.cs
  31. 524 0
      mcs/class/System.Data/Test/System.Data.OleDb/OleDbDataAdapterTest.cs
  32. 9 0
      mcs/class/System.Data/Test/System.Data.SqlClient/ChangeLog
  33. 192 0
      mcs/class/System.Data/Test/System.Data.SqlClient/SqlCommandTest.cs
  34. 101 12
      mcs/class/System.Data/Test/System.Data.SqlClient/SqlConnectionTest.cs
  35. 554 0
      mcs/class/System.Data/Test/System.Data.SqlClient/SqlDataAdapterTest.cs

+ 7 - 0
mcs/class/System.Data/ChangeLog

@@ -1,3 +1,10 @@
+2007-10-20  Gert Driesen  <[email protected]>
+
+	* System.Data_test.dll.sources: Added DbDataAdapterTest.cs,
+	OdbcCommandTest.cs, OdbcConnectionTest.cs, OdbcDataAdapterTest.cs,
+	OleDbCommandTest.cs, OleDbConnectionTest.cs, OleDbDataAdapterTest.cs,
+	SqlDataAdapterTest.cs.
+
 2007-10-15  Gert Driesen  <[email protected]>
 
 	* System.Data_test.dll.sources: Added DbTransactionTest.cs.

+ 11 - 0
mcs/class/System.Data/System.Data.Common/ChangeLog

@@ -1,3 +1,14 @@
+2007-10-20  Gert Driesen  <[email protected]>
+
+	* DbDataAdapter.cs: Implemented UpdateBatchSize setter.
+	* DataAdapter.cs: In FillLoadOption setter, ensure value is valid.
+	Modified MissingMappingAction and MissingSchemaAction setters to use
+	ExceptionHelper.CheckEnumValue to validate value. Spaces to tabs and
+	code formatting.
+	* ExceptionHelper.cs: Added CheckEnumValue method and modified
+	InvalidEnumValueException method to return AORE on 2.0 profile. Added
+	ConnectionClosed method that returns an InvalidOperationException.
+
 2007-10-19  Gert Driesen  <[email protected]>
 
 	* DbTransaction.cs: Do not perform a rollback in Dispose (bool).

+ 31 - 42
mcs/class/System.Data/System.Data.Common/DataAdapter.cs

@@ -134,7 +134,10 @@ namespace System.Data.Common
 		[RefreshProperties (RefreshProperties.All)]
 		public LoadOption FillLoadOption {
 			get { return fillLoadOption; }
-			set { fillLoadOption = value; }
+			set {
+				ExceptionHelper.CheckEnumValue (typeof (LoadOption), value);
+				fillLoadOption = value;
+		}
 		}
 #endif
 
@@ -150,8 +153,7 @@ namespace System.Data.Common
 		public MissingMappingAction MissingMappingAction {
 			get { return missingMappingAction; }
 			set {
-				if (!Enum.IsDefined (typeof (MissingMappingAction), value))
-					throw ExceptionHelper.InvalidEnumValueException ("MissingMappingAction", value);
+				ExceptionHelper.CheckEnumValue (typeof (MissingMappingAction), value);
 				missingMappingAction = value;
 			}
 		}
@@ -163,9 +165,8 @@ namespace System.Data.Common
 		[DefaultValue (MissingSchemaAction.Add)]
 		public MissingSchemaAction MissingSchemaAction {
 			get { return missingSchemaAction; }
-			set { 
-				if (!Enum.IsDefined (typeof (MissingSchemaAction), value))
-					throw ExceptionHelper.InvalidEnumValueException ("MissingSchemaAction", value);
+			set {
+				ExceptionHelper.CheckEnumValue (typeof (MissingSchemaAction), value);
 				missingSchemaAction = value; 
 			}
 		}
@@ -200,9 +201,9 @@ namespace System.Data.Common
 		#region Methods
 
 #if !ONLY_1_0
-                [Obsolete ("Use the protected constructor instead", false)]
+		[Obsolete ("Use the protected constructor instead", false)]
 #endif
-                [MonoTODO]
+		[MonoTODO]
 		protected virtual DataAdapter CloneInternals ()
 		{
 			throw new NotImplementedException ();
@@ -255,14 +256,13 @@ namespace System.Data.Common
 		{
 			return BuildSchema (reader, table, schemaType, MissingSchemaAction,
 					    MissingMappingAction, TableMappings);
-                }
-
-                /// <summary>
-                ///     Creates or Modifies the schema of the given DataTable based on the schema of
-                ///     the reader and the arguments passed.
-                /// </summary>
-                internal static int[] BuildSchema (IDataReader reader,
-                                                   DataTable table,
+		}
+
+		/// <summary>
+		///     Creates or Modifies the schema of the given DataTable based on the schema of
+		///     the reader and the arguments passed.
+		/// </summary>
+		internal static int[] BuildSchema (IDataReader reader, DataTable table,
                                                    SchemaType schemaType,
                                                    MissingSchemaAction missingSchAction,
                                                    MissingMappingAction missingMapAction,
@@ -300,13 +300,12 @@ namespace System.Data.Common
 				    (string)schemaRow [ColumnNameCol] == String.Empty) {
 					sourceColumnName = DefaultSourceColumnName;
 					realSourceColumnName = DefaultSourceColumnName + "1";
-				}
-				else {
+				} else {
 					sourceColumnName = (string) schemaRow [ColumnNameCol];
 					realSourceColumnName = sourceColumnName;
 				}
 
-				for (int i = 1; sourceColumns.Contains (realSourceColumnName); i += 1) 
+				for (int i = 1; sourceColumns.Contains (realSourceColumnName); i += 1)
 					realSourceColumnName = String.Format ("{0}{1}", sourceColumnName, i);
 				sourceColumns.Add(realSourceColumnName);
 
@@ -318,13 +317,11 @@ namespace System.Data.Common
 				int index = dtMapping.IndexOfDataSetTable (table.TableName);
 				string srcTable = (index != -1 ? dtMapping[index].SourceTable : table.TableName);
 				tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction (dtMapping, srcTable, table.TableName, missingMapAction); 
-				if (tableMapping != null)
-				{
+				if (tableMapping != null) {
 					table.TableName = tableMapping.DataSetTable;
 					// check to see if the column mapping exists
 					DataColumnMapping columnMapping = DataColumnMappingCollection.GetColumnMappingBySchemaAction(tableMapping.ColumnMappings, realSourceColumnName, missingMapAction);
-					if (columnMapping != null)
-					{
+					if (columnMapping != null) {
 						Type columnType = (Type)schemaRow[DataTypeCol];
 						DataColumn col =
 							columnMapping.GetDataColumnBySchemaAction(
@@ -332,11 +329,9 @@ namespace System.Data.Common
 												  columnType,
 												  missingSchAction);
 
-						if (col != null)
-						{
+						if (col != null) {
 							// if the column is not in the table - add it.
-							if (table.Columns.IndexOf(col) == -1)
-							{
+							if (table.Columns.IndexOf(col) == -1) {
 								if (missingSchAction == MissingSchemaAction.Add 
 								    || missingSchAction == MissingSchemaAction.AddWithKey)
 									table.Columns.Add(col);
@@ -345,11 +340,9 @@ namespace System.Data.Common
 								Array.Copy(mapping,0,tmp,0,col.Ordinal);
 								Array.Copy(mapping,col.Ordinal,tmp,col.Ordinal + 1,mapping.Length - col.Ordinal);
 								mapping = tmp;
-							}				
-
+							}
 
 							if (missingSchAction == MissingSchemaAction.AddWithKey) {
-	                            
 								object value = (AllowDBNullCol != null) ? schemaRow[AllowDBNullCol] : null;
 								bool allowDBNull = value is bool ? (bool)value : true;
 
@@ -366,7 +359,7 @@ namespace System.Data.Common
 								bool isUnique = value is bool ? (bool)value : false;
 								
 								col.AllowDBNull = allowDBNull;
-								// fill woth key info								
+								// fill woth key info
 								if (isAutoIncrement && DataColumn.CanAutoIncrement(columnType)) {
 									col.AutoIncrement = true;
 									if (!allowDBNull)
@@ -425,7 +418,7 @@ namespace System.Data.Common
 				}
 			}
 			return mapping;
-                }
+		}
 
 		internal bool FillTable (DataTable dataTable, IDataReader dataReader, int startRecord, int maxRecords, ref int counter)
 		{
@@ -497,14 +490,12 @@ namespace System.Data.Common
 		{
 			DataTableMapping tableMapping = null;
 
-			if (schemaType == SchemaType.Mapped) 
-			{
+			if (schemaType == SchemaType.Mapped) {
 				tableMapping = DataTableMappingCollection.GetTableMappingBySchemaAction (TableMappings, sourceTableName, sourceTableName, MissingMappingAction);
 				if (tableMapping != null)
 					return tableMapping.DataSetTable;
 				return null;
-			}
-			else
+			} else
 				return sourceTableName;
 		}
 
@@ -531,7 +522,7 @@ namespace System.Data.Common
 						if (tableName != null) {
 							
 							// check if the table exists in the dataset
-							if (dataSet.Tables.Contains (tableName)) 
+							if (dataSet.Tables.Contains (tableName))
 								// get the table from the dataset
 								dataTable = dataSet.Tables [tableName];
 							else {
@@ -541,9 +532,8 @@ namespace System.Data.Common
 								dataTable = dataSet.Tables.Add (tableName);
 							}
 	
-							if (!FillTable (dataTable, dataReader, startRecord, maxRecords, ref count)) {
+							if (!FillTable (dataTable, dataReader, startRecord, maxRecords, ref count))
 								continue;
-							}
 	
 							tableName = String.Format ("{0}{1}", srcTable, ++resultIndex);
 	
@@ -552,12 +542,11 @@ namespace System.Data.Common
 						}
 					}
 				} while (dataReader.NextResult ());
-			} 
-			finally {
+			} finally {
 				dataReader.Close ();
 			}
 
-                        return count;
+			return count;
 		}
 
 #if NET_2_0

+ 4 - 2
mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs

@@ -133,8 +133,10 @@ namespace System.Data.Common {
 		[DefaultValue (1)]
 		public virtual int UpdateBatchSize {
 			get { return 1; }
-			[MonoTODO]
-			set { throw new NotSupportedException (); }
+			set {
+				if (value != 1)
+					throw new NotSupportedException ();
+			}
 		}
 #else
 		IDbCommand SelectCommand {

+ 18 - 0
mcs/class/System.Data/System.Data.Common/ExceptionHelper.cs

@@ -18,9 +18,22 @@ namespace System.Data.Common
 			return new ArgumentException  (GetExceptionMessage ("Invalid parameter Size value '{0}'. The value must be greater than or equal to 0.",args));
 		}
 
+		internal static void CheckEnumValue (Type enumType, object value)
+		{
+			if (!Enum.IsDefined (enumType, value))
+				throw InvalidEnumValueException (enumType.Name, value);
+		}
+
 		internal static ArgumentException InvalidEnumValueException (String enumeration, object value)
 		{
+#if NET_2_0
+			return new ArgumentOutOfRangeException (enumeration,
+				string.Format (CultureInfo.InvariantCulture,
+					"The {0} enumeration value, {1}, is " +
+					"invalid", enumeration, value));
+#else
 			return new ArgumentException (String.Format ("The {0} enumeration value, {1}, is invalid", enumeration, value));
+#endif
 		}
 
 		internal static ArgumentOutOfRangeException InvalidDataRowVersion (DataRowVersion value)
@@ -140,6 +153,11 @@ namespace System.Data.Common
 			return new InvalidOperationException (GetExceptionMessage ("The connection is already Open (state={0}).",args));
 		}
 
+		internal static InvalidOperationException ConnectionClosed ()
+		{
+			return new InvalidOperationException ("Invalid operation. The Connection is closed.");
+		}
+
 		internal static InvalidOperationException ConnectionStringNotInitialized ()
 		{
 			return new InvalidOperationException (GetExceptionMessage ("The ConnectionString property has not been initialized."));

+ 17 - 0
mcs/class/System.Data/System.Data.Odbc/ChangeLog

@@ -1,3 +1,20 @@
+2007-10-20  Gert Driesen  <[email protected]>
+
+	* OdbcCommand.cs: Added constant for default CommandTimeout, instead
+	of using a magic number. Avoid unnecessary initialization. Fixed
+	default value for DesignTimeVisible. Return zero-length string if
+	CommandText is null. Spaces to tabs and code formatting.
+	* OdbcError.cs: Fixed typo in exception message.
+	* OdbcConnection.cs: Return zero-length string if ConnectionString is
+	null. In getters for Database, DataSource and Driver return a
+	zero-length string if connection is closed. In BeginTransaction and
+	GetSchema throw InvalidOperationException if connection is closed.
+	Added override for GetSchema (string, string []). Use string.Empty
+	instead of "".
+	* OdbcDataAdapter.cs: Avoid unnecessary initializations. Use direct
+	assignment in IDbDataAdapter implementation. In default ctor, set
+	SelectCommand to null.
+
 2007-10-19  Gert Driesen  <[email protected]>
 
 	* OdbcTransaction.cs: Clear connection in Commit and Rollback.

+ 60 - 77
mcs/class/System.Data/System.Data.Odbc/OdbcCommand.cs

@@ -39,11 +39,11 @@ using System.Runtime.InteropServices;
 
 namespace System.Data.Odbc
 {
-        /// <summary>
+	/// <summary>
 	/// Represents an SQL statement or stored procedure to execute against a data source.
 	/// </summary>
 	[DesignerAttribute ("Microsoft.VSDesigner.Data.VS.OdbcCommandDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]
-        [ToolboxItemAttribute ("System.Drawing.Design.ToolboxItem, "+ Consts.AssemblySystem_Drawing)]
+	[ToolboxItemAttribute ("System.Drawing.Design.ToolboxItem, "+ Consts.AssemblySystem_Drawing)]
 #if NET_2_0
 	[DefaultEvent ("RecordsAffected")]
 	public sealed class OdbcCommand : DbCommand, ICloneable
@@ -53,20 +53,22 @@ namespace System.Data.Odbc
 	{
 		#region Fields
 
+		const int DEFAULT_COMMAND_TIMEOUT = 30;
+
 		string commandText;
 		int timeout;
 		CommandType commandType;
-		UpdateRowSource updateRowSource = UpdateRowSource.Both;
+		UpdateRowSource updateRowSource;
 
 		OdbcConnection connection;
 		OdbcTransaction transaction;
 		OdbcParameterCollection _parameters;
 
 		bool designTimeVisible;
-		bool prepared=false;
+		bool prepared;
 		IntPtr hstmt = IntPtr.Zero;
 
-		bool disposed = false;
+		bool disposed;
 		
 		#endregion // Fields
 
@@ -74,21 +76,16 @@ namespace System.Data.Odbc
 
 		public OdbcCommand ()
 		{
-			this.CommandText = String.Empty;
-			this.CommandTimeout = 30; // default timeout 
-			this.CommandType = CommandType.Text;
-			Connection = null;
+			timeout = DEFAULT_COMMAND_TIMEOUT;
+			commandType = CommandType.Text;
 			_parameters = new OdbcParameterCollection ();
-			Transaction = null;
-			designTimeVisible = false;
-#if ONLY_1_1
+			designTimeVisible = true;
 			updateRowSource = UpdateRowSource.Both;
-#endif // ONLY_1_1
 		}
 
 		public OdbcCommand (string cmdText) : this ()
 		{
-			CommandText = cmdText;
+			commandText = cmdText;
 		}
 
 		public OdbcCommand (string cmdText, OdbcConnection connection)
@@ -97,8 +94,7 @@ namespace System.Data.Odbc
 			Connection = connection;
 		}
 
-		public OdbcCommand (string cmdText,
-				    OdbcConnection connection,
+		public OdbcCommand (string cmdText, OdbcConnection connection,
 				    OdbcTransaction transaction) : this (cmdText, connection)
 		{
 			this.Transaction = transaction;
@@ -108,8 +104,7 @@ namespace System.Data.Odbc
 
 		#region Properties
 
-		internal IntPtr hStmt
-		{
+		internal IntPtr hStmt {
 			get { return hstmt; }
 		}
 		
@@ -119,24 +114,27 @@ namespace System.Data.Odbc
 		[OdbcDescriptionAttribute ("Command text to execute")]
 		[EditorAttribute ("Microsoft.VSDesigner.Data.Odbc.Design.OdbcCommandTextEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
 		[RefreshPropertiesAttribute (RefreshProperties.All)]
-		public 
+		public
 #if NET_2_0
 		override
 #endif
-		string CommandText 
-		{
-			get { return commandText; }
-			set { 
-				prepared=false;
+		string CommandText {
+			get {
+				if (commandText == null)
+					return string.Empty;
+				return commandText;
+			}
+			set {
+				prepared = false;
 				commandText = value;
 			}
 		}
 
 		[OdbcDescriptionAttribute ("Time to wait for command to execute")]
 #if NET_1_0 || ONLY_1_1
-                [DefaultValue (30)]
+		[DefaultValue (DEFAULT_COMMAND_TIMEOUT)]
 #endif
-		public 
+		public
 #if NET_2_0
 		override
 #endif
@@ -153,7 +151,7 @@ namespace System.Data.Odbc
 #if NET_2_0
 		override
 #endif
-		CommandType CommandType { 
+		CommandType CommandType {
 			get { return commandType; }
 			set { commandType = value; }
 		}
@@ -163,7 +161,7 @@ namespace System.Data.Odbc
 		[OdbcDescriptionAttribute ("Connection used by the command")]
 		[DefaultValue (null)]
 		[EditorAttribute ("Microsoft.VSDesigner.Data.Design.DbConnectionEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
-		public OdbcConnection Connection { 
+		public OdbcConnection Connection {
 			get {
 				return connection;
 			}
@@ -176,12 +174,10 @@ namespace System.Data.Odbc
 #if NET_2_0
 		[DefaultValue (null)]
 		[EditorAttribute ("Microsoft.VSDesigner.Data.Design.DbConnectionEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing )]
-		public new OdbcConnection Connection
-		{
+		public new OdbcConnection Connection {
 			get { return DbConnection as OdbcConnection; }
 			set { DbConnection = value; }
 		}
-                
 #endif // NET_2_0
 
 		[BrowsableAttribute (false)]
@@ -190,11 +186,11 @@ namespace System.Data.Odbc
 #if NET_2_0
 		[EditorBrowsable (EditorBrowsableState.Never)]
 #endif
-		public 
+		public
 #if NET_2_0
 		override
 #endif
-		bool DesignTimeVisible { 
+		bool DesignTimeVisible {
 			get {
 				return designTimeVisible;
 			}
@@ -209,9 +205,9 @@ namespace System.Data.Odbc
 		[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
 		public
 #if NET_2_0
-                new
+		new
 #endif // NET_2_0
-                OdbcParameterCollection Parameters {
+		OdbcParameterCollection Parameters {
 			get {
 #if ONLY_1_1
 				return _parameters;
@@ -226,9 +222,9 @@ namespace System.Data.Odbc
 		[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
 		public
 #if NET_2_0
-                new
+		new
 #endif // NET_2_0
-                OdbcTransaction Transaction {
+		OdbcTransaction Transaction {
 			get {
 				return transaction;
 			}
@@ -240,11 +236,11 @@ namespace System.Data.Odbc
 		[OdbcCategory ("Behavior")]
 		[DefaultValue (UpdateRowSource.Both)]
 		[OdbcDescriptionAttribute ("When used by a DataAdapter.Update, how command results are applied to the current DataRow")]
-		public 
+		public
 #if NET_2_0
 		override
 #endif
-		UpdateRowSource UpdatedRowSource { 
+		UpdateRowSource UpdatedRowSource {
 				get {
 					return updateRowSource;
 				}
@@ -254,16 +250,14 @@ namespace System.Data.Odbc
 		}
 
 #if NET_2_0
-		protected override DbConnection DbConnection 
-		{
+		protected override DbConnection DbConnection {
 			get { return connection; }
-			set { connection = (OdbcConnection) value;}                        
+			set { connection = (OdbcConnection) value;}
 		}
 
 #endif // NET_2_0
 
 #if ONLY_1_1
-
 		IDbConnection IDbCommand.Connection {
 			get {
 				return Connection;
@@ -273,21 +267,19 @@ namespace System.Data.Odbc
 			}
 		}
 
-		IDataParameterCollection IDbCommand.Parameters  {
+		IDataParameterCollection IDbCommand.Parameters {
 			get {
 				return Parameters;
 			}
 		}
 #else
-		protected override DbParameterCollection DbParameterCollection
-		{
+		protected override DbParameterCollection DbParameterCollection {
 			get { return _parameters as DbParameterCollection;}
 		}
-                
 #endif // NET_2_0
 
 #if ONLY_1_1
-		IDbTransaction IDbCommand.Transaction  {
+		IDbTransaction IDbCommand.Transaction {
 			get {
 				return (IDbTransaction) Transaction;
 			}
@@ -300,8 +292,7 @@ namespace System.Data.Odbc
 			}
 		}
 		#else
-		protected override DbTransaction DbTransaction 
-                {
+		protected override DbTransaction DbTransaction {
 			get { return transaction; }
 			set { transaction = (OdbcTransaction) value; }
 		}
@@ -338,7 +329,6 @@ namespace System.Data.Odbc
 		{
 			return CreateParameter ();
 		}
-                
 #endif // ONLY_1_1
 
 		public new OdbcParameter CreateParameter ()
@@ -387,7 +377,7 @@ namespace System.Data.Odbc
 			hstmt = IntPtr.Zero;
 		}
 		
-		private void ExecSQL(string sql)
+		private void ExecSQL (string sql)
 		{
 			OdbcReturn ret;
 			if (! prepared && Parameters.Count <= 0) {
@@ -418,9 +408,9 @@ namespace System.Data.Odbc
 
 		public
 #if NET_2_0
-                override
+		override
 #endif // NET_2_0
-                int ExecuteNonQuery ()
+		int ExecuteNonQuery ()
 		{
 			return ExecuteNonQuery (true);
 		}
@@ -437,17 +427,15 @@ namespace System.Data.Odbc
 			ExecSQL(CommandText);
 
 			// .NET documentation says that except for INSERT, UPDATE and
-                        // DELETE  where the return value is the number of rows affected
-                        // for the rest of the commands the return value is -1.
-                        if ((CommandText.ToUpper().IndexOf("UPDATE")!=-1) ||
+			// DELETE  where the return value is the number of rows affected
+			// for the rest of the commands the return value is -1.
+			if ((CommandText.ToUpper().IndexOf("UPDATE")!=-1) ||
 			    (CommandText.ToUpper().IndexOf("INSERT")!=-1) ||
 			    (CommandText.ToUpper().IndexOf("DELETE")!=-1)) {
-                                                                                                    
 				int numrows = 0;
 				OdbcReturn ret = libodbc.SQLRowCount(hstmt,ref numrows);
 				records = numrows;
-                        }
-                        else
+			} else
 				records = -1;
 
 			if (freeHandle && !prepared)
@@ -458,9 +446,9 @@ namespace System.Data.Odbc
 
 		public
 #if NET_2_0
-                override
+		override
 #endif // NET_2_0
-                void Prepare()
+		void Prepare()
 		{
 			ReAllocStatment ();
 			
@@ -482,12 +470,11 @@ namespace System.Data.Odbc
 			}
 		}
 
-
 		public
 #if NET_2_0
-			new
+		new
 #endif // NET_2_0
-				OdbcDataReader ExecuteReader ()
+		OdbcDataReader ExecuteReader ()
 		{
 			return ExecuteReader (CommandBehavior.Default);
 		}
@@ -497,19 +484,18 @@ namespace System.Data.Odbc
 		{
 			return ExecuteReader ();
 		}
-		#else
+#else
 		protected override DbDataReader ExecuteDbDataReader (CommandBehavior behavior)
 		{
 			return ExecuteReader (behavior);
 		}
-
 #endif // ONLY_1_1
 
 		public
 #if NET_2_0
-                new
+		new
 #endif // NET_2_0
-                OdbcDataReader ExecuteReader (CommandBehavior behavior)
+		OdbcDataReader ExecuteReader (CommandBehavior behavior)
 		{
 			int recordsAffected = ExecuteNonQuery(false);
 			OdbcDataReader dataReader=new OdbcDataReader(this, behavior, recordsAffected);
@@ -517,13 +503,13 @@ namespace System.Data.Odbc
 		}
 
 #if ONLY_1_1
-                IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
+		IDataReader IDbCommand.ExecuteReader (CommandBehavior behavior)
 		{
 			return ExecuteReader (behavior);
 		}
 #endif // ONLY_1_1
 
-		public 
+		public
 #if NET_2_0
 		override
 #endif
@@ -531,13 +517,10 @@ namespace System.Data.Odbc
 		{
 			object val = null;
 			OdbcDataReader reader=ExecuteReader();
-			try
-			{
+			try {
 				if (reader.Read ())
 					val=reader[0];
-			}
-			finally
-			{
+			} finally {
 				reader.Close();
 			}
 			return val;
@@ -559,7 +542,7 @@ namespace System.Data.Odbc
 
 		public void ResetCommandTimeout ()
 		{
-			CommandTimeout = 30;
+			CommandTimeout = DEFAULT_COMMAND_TIMEOUT;
 		}
 
 		#endregion

+ 28 - 16
mcs/class/System.Data/System.Data.Odbc/OdbcConnection.cs

@@ -74,8 +74,7 @@ namespace System.Data.Odbc
 
 		#region Properties
 
-		internal IntPtr hDbc
-		{
+		internal IntPtr hDbc {
 			get { return hdbc; }
 		}
 
@@ -91,11 +90,11 @@ namespace System.Data.Odbc
 #endif
 		string ConnectionString {
 			get {
+				if (connectionString == null)
+					return string.Empty;
 				return connectionString;
 			}
-			set {
-				connectionString = value;
-			}
+			set { connectionString = value; }
 		}
 		
 		[OdbcDescriptionAttribute ("Current connection timeout value, not settable  in the ConnectionString")]
@@ -126,6 +125,8 @@ namespace System.Data.Odbc
 #endif // NET_2_0
 		string Database {
 			get {
+				if (State == ConnectionState.Closed)
+					return string.Empty;
 				return GetInfo (OdbcInfo.DatabaseName);
 			}
 		}
@@ -139,9 +140,8 @@ namespace System.Data.Odbc
 #endif // NET_2_0
 		ConnectionState State {
 			get {
-				if (hdbc!=IntPtr.Zero) {
+				if (hdbc!=IntPtr.Zero)
 					return ConnectionState.Open;
-				}
 				else
 					return ConnectionState.Closed;
 			}
@@ -158,6 +158,8 @@ namespace System.Data.Odbc
 #endif // NET_2_0
 		string DataSource {
 			get {
+				if (State == ConnectionState.Closed)
+					return string.Empty;
 				return GetInfo (OdbcInfo.DataSourceName);
 			}
 		}
@@ -169,6 +171,8 @@ namespace System.Data.Odbc
 		[OdbcDescriptionAttribute ("Current ODBC Driver")]
 		public string Driver {
 			get {
+				if (State == ConnectionState.Closed)
+					return string.Empty;
 				return GetInfo (OdbcInfo.DriverName);
 			}
 		}
@@ -218,6 +222,9 @@ namespace System.Data.Odbc
 #endif // NET_2_0
 		OdbcTransaction BeginTransaction (IsolationLevel level)
 		{
+			if (State == ConnectionState.Closed)
+				throw ExceptionHelper.ConnectionClosed ();
+
 			if (transaction == null) {
 				transaction = new OdbcTransaction (this,level);
 				return transaction;
@@ -228,7 +235,7 @@ namespace System.Data.Odbc
 #if ONLY_1_1
 		IDbTransaction IDbConnection.BeginTransaction (IsolationLevel level)
 		{
-			return (IDbTransaction) BeginTransaction(level);
+			return (IDbTransaction) BeginTransaction (level);
 		}
 #endif // ONLY_1_1
 
@@ -257,7 +264,7 @@ namespace System.Data.Odbc
 #endif // NET_2_0
 		OdbcCommand CreateCommand ()
 		{
-			return new OdbcCommand ("", this, transaction);
+			return new OdbcCommand (string.Empty, this, transaction);
 		}
 
 		public
@@ -348,7 +355,7 @@ namespace System.Data.Odbc
 				// DSN connection
 				if (ConnectionString.ToLower ().IndexOf ("dsn=") >= 0)
 				{
-					string _uid = "", _pwd = "", _dsn = "";
+					string _uid = string.Empty, _pwd = string.Empty, _dsn = string.Empty;
 					string [] items = ConnectionString.Split (new char[1]{';'});
 					foreach (string item in items)
 					{
@@ -415,17 +422,22 @@ namespace System.Data.Odbc
 		}
 
 #if NET_2_0
-		public new DataTable GetSchema ()
+		public override DataTable GetSchema ()
 		{
-			if (State == ConnectionState.Open)
-				throw new InvalidOperationException ();
+			if (State == ConnectionState.Closed)
+				throw ExceptionHelper.ConnectionClosed ();
 			return MetaDataCollections.Instance;
 		}
 
-		public new DataTable GetSchema (string collectionName)
+		public override DataTable GetSchema (string collectionName)
 		{
-			if (State == ConnectionState.Open)
-				throw new InvalidOperationException ();
+			return GetSchema (collectionName, null);
+		}
+
+		public override DataTable GetSchema (string collectionName, string [] restrictionValues)
+		{
+			if (State == ConnectionState.Closed)
+				throw ExceptionHelper.ConnectionClosed ();
 			return GetSchema (collectionName, null);
 		}
 

+ 7 - 25
mcs/class/System.Data/System.Data.Odbc/OdbcDataAdapter.cs

@@ -47,7 +47,7 @@ namespace System.Data.Odbc {
 		#region Fields
 
 #if ONLY_1_1
-		bool disposed = false;
+		bool disposed;
 #endif
 		OdbcCommand deleteCommand;
 		OdbcCommand insertCommand;
@@ -58,16 +58,13 @@ namespace System.Data.Odbc {
 
 		#region Constructors
 		
-		public OdbcDataAdapter () : this (new OdbcCommand ())
+		public OdbcDataAdapter () : this ((OdbcCommand) null)
 		{
 		}
 
 		public OdbcDataAdapter (OdbcCommand selectCommand) 
 		{
-			DeleteCommand = null;
-			InsertCommand = null;
 			SelectCommand = selectCommand;
-			UpdateCommand = null;
 		}
 
 		public OdbcDataAdapter (string selectCommandText, OdbcConnection selectConnection) 
@@ -122,38 +119,22 @@ namespace System.Data.Odbc {
 
 		IDbCommand IDbDataAdapter.DeleteCommand {
 			get { return DeleteCommand; }
-			set { 
-				if (!(value is OdbcCommand)) 
-					throw new ArgumentException ();
-				DeleteCommand = (OdbcCommand)value;
-			}
+			set { DeleteCommand = (OdbcCommand) value; }
 		}
 
 		IDbCommand IDbDataAdapter.InsertCommand {
 			get { return InsertCommand; }
-			set { 
-				if (!(value is OdbcCommand)) 
-					throw new ArgumentException ();
-				InsertCommand = (OdbcCommand)value;
-			}
+			set { InsertCommand = (OdbcCommand) value; }
 		}
 
 		IDbCommand IDbDataAdapter.SelectCommand {
 			get { return SelectCommand; }
-			set { 
-				if (!(value is OdbcCommand)) 
-					throw new ArgumentException ();
-				SelectCommand = (OdbcCommand)value;
-			}
+			set { SelectCommand = (OdbcCommand) value; }
 		}
 
 		IDbCommand IDbDataAdapter.UpdateCommand {
 			get { return UpdateCommand; }
-			set { 
-				if (!(value is OdbcCommand)) 
-					throw new ArgumentException ();
-				UpdateCommand = (OdbcCommand)value;
-			}
+			set { UpdateCommand = (OdbcCommand) value; }
 		}
 
 
@@ -186,6 +167,7 @@ namespace System.Data.Odbc {
 				// Release unmanaged resources
 				disposed = true;
 			}
+			base.Dispose (true);
 		}
 #endif
 

+ 1 - 1
mcs/class/System.Data/System.Data.Odbc/OdbcError.cs

@@ -91,7 +91,7 @@ namespace System.Data.Odbc
 				{
 					_nativeerror = 1;
 					_source = Source;
-					_message = "Unable to retreive error information from ODBC driver manager";
+					_message = "Unable to retrieve error information from ODBC driver manager";
 					_state = "";
 				}
 				else

+ 16 - 0
mcs/class/System.Data/System.Data.OleDb/ChangeLog

@@ -1,3 +1,19 @@
+2007-10-20  Gert Driesen  <[email protected]>
+
+	* OleDbDataAdapter.cs: In default ctor, set SelectCommand to null.
+	Only initialize SelectCommand in ctors. Use direct assignment in
+	IDbDataAdapter implementation.
+	* OleDbCommand.cs: Added constant for default CommandTimeout, instead
+	of using a magic number. Avoid unnecessary initialization. Fixed
+	default value for DesignTimeVisible. Return zero-length string if
+	CommandText is null. Added implementation for UpdatedRowSource.
+	* OleDbConnection.cs: Moved initialization of gda to Open ().
+	Avoid unnecessary initialization. Return zero-length string if
+	ConnectionString is null. If getters to Database, DataSource and
+	Provider return zero-length string if the connection is closed.
+	In ServerVersion, BeginTransaction and GetSchema, throw an
+	InvalidOperationException if connection is closed.
+
 2007-10-19  Gert Driesen  <[email protected]>
 
 	* OleDbTransaction.cs: Clear connection in Commit and Rollback. In

+ 20 - 14
mcs/class/System.Data/System.Data.OleDb/OleDbCommand.cs

@@ -58,6 +58,8 @@ namespace System.Data.OleDb
 	{
 		#region Fields
 
+		const int DEFAULT_COMMAND_TIMEOUT = 30;
+
 		string commandText;
 		int timeout;
 		CommandType commandType;
@@ -68,8 +70,9 @@ namespace System.Data.OleDb
 		OleDbDataReader dataReader;
 		CommandBehavior behavior;
 		IntPtr gdaCommand;
+		UpdateRowSource updatedRowSource;
 
-		bool disposed = false;
+		bool disposed;
 		
 		#endregion // Fields
 
@@ -77,12 +80,13 @@ namespace System.Data.OleDb
 
 		public OleDbCommand ()
 		{
-			commandText = String.Empty;
-			timeout = 30; // default timeout per .NET
+			timeout = DEFAULT_COMMAND_TIMEOUT;
 			commandType = CommandType.Text;
 			parameters = new OleDbParameterCollection ();
 			behavior = CommandBehavior.Default;
 			gdaCommand = IntPtr.Zero;
+			designTimeVisible = true;
+			this.updatedRowSource = UpdateRowSource.Both;
 		}
 
 		public OleDbCommand (string cmdText) : this ()
@@ -117,9 +121,10 @@ namespace System.Data.OleDb
 #if NET_2_0
 		override
 #endif
-		string CommandText
-		{
+		string CommandText {
 			get {
+				if (commandText == null)
+					return string.Empty;
 				return commandText;
 			}
 			set {
@@ -129,7 +134,7 @@ namespace System.Data.OleDb
 
 #if !NET_2_0
 		[DataSysDescriptionAttribute ("Time to wait for command to execute.")]
-		[DefaultValue (30)]
+		[DefaultValue (DEFAULT_COMMAND_TIMEOUT)]
 #endif
 		public
 #if NET_2_0
@@ -232,11 +237,12 @@ namespace System.Data.OleDb
 		override
 #endif
 		UpdateRowSource UpdatedRowSource {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				throw new NotImplementedException ();
+			get { return updatedRowSource; }
+			set
+			{
+				if (!Enum.IsDefined (typeof (UpdateRowSource), value))
+					throw ExceptionHelper.InvalidEnumValueException ("UpdateRowSource", value);
+				updatedRowSource = value;
 			}
 		}
 
@@ -318,10 +324,10 @@ namespace System.Data.OleDb
 			}
 			
 			if (gdaCommand != IntPtr.Zero) {
-				libgda.gda_command_set_text (gdaCommand, commandText);
+				libgda.gda_command_set_text (gdaCommand, CommandText);
 				libgda.gda_command_set_command_type (gdaCommand, type);
 			} else {
-				gdaCommand = libgda.gda_command_new (commandText, type, 0);
+				gdaCommand = libgda.gda_command_new (CommandText, type, 0);
 			}
 
 			//libgda.gda_command_set_transaction 
@@ -456,7 +462,7 @@ namespace System.Data.OleDb
 
 		public void ResetCommandTimeout ()
 		{
-			timeout = 30;
+			timeout = DEFAULT_COMMAND_TIMEOUT;
 		}
 		
 #if NET_2_0

+ 24 - 25
mcs/class/System.Data/System.Data.OleDb/OleDbConnection.cs

@@ -61,10 +61,8 @@ namespace System.Data.OleDb
 		
 		public OleDbConnection ()
 		{
-			libgda.gda_init ("System.Data.OleDb", "1.0", 0, new string [0]);
 			gdaConnection = IntPtr.Zero;
 			connectionTimeout = 15;
-			connectionString = null;
 		}
 
 		public OleDbConnection (string connectionString) : this ()
@@ -90,6 +88,8 @@ namespace System.Data.OleDb
 #endif
 		string ConnectionString {
 			get {
+				if (connectionString == null)
+					return string.Empty;
 				return connectionString;
 			}
 			set {
@@ -126,7 +126,7 @@ namespace System.Data.OleDb
 					return libgda.gda_connection_get_database (gdaConnection);
 				}
 
-				return null;
+				return string.Empty;
 			}
 		}
 
@@ -147,7 +147,7 @@ namespace System.Data.OleDb
 					return libgda.gda_connection_get_dsn (gdaConnection);
 				}
 
-				return null;
+				return string.Empty;
 			}
 		}
 
@@ -164,7 +164,7 @@ namespace System.Data.OleDb
 					return libgda.gda_connection_get_provider (gdaConnection);
 				}
 
-				return null;
+				return string.Empty;
 			}
 		}
 
@@ -179,12 +179,9 @@ namespace System.Data.OleDb
 #endif
 		string ServerVersion {
 			get {
-				if (gdaConnection != IntPtr.Zero
-					&& libgda.gda_connection_is_open (gdaConnection)) {
-					return libgda.gda_connection_get_server_version (gdaConnection);
-				}
-
-				return null;
+				if (State == ConnectionState.Closed)
+					throw ExceptionHelper.ConnectionClosed ();
+				return libgda.gda_connection_get_server_version (gdaConnection);
 			}
 		}
 
@@ -220,18 +217,16 @@ namespace System.Data.OleDb
 	
 		public new OleDbTransaction BeginTransaction ()
 		{
-			if (gdaConnection != IntPtr.Zero)
-				return new OleDbTransaction (this);
-
-			return null;
+			if (State == ConnectionState.Closed)
+				throw ExceptionHelper.ConnectionClosed ();
+			return new OleDbTransaction (this);
 		}
 
 		public new OleDbTransaction BeginTransaction (IsolationLevel level)
 		{
-			if (gdaConnection != IntPtr.Zero)
-				return new OleDbTransaction (this, level);
-
-			return null;
+			if (State == ConnectionState.Closed)
+				throw ExceptionHelper.ConnectionClosed ();
+			return new OleDbTransaction (this, level);
 		}
 
 #if NET_2_0
@@ -267,8 +262,6 @@ namespace System.Data.OleDb
 #endif
 		void ChangeDatabase (string name)
 		{
-			if (gdaConnection == IntPtr.Zero)
-				throw new ArgumentException ();
 			if (State != ConnectionState.Open)
 				throw new InvalidOperationException ();
 
@@ -321,7 +314,7 @@ namespace System.Data.OleDb
 		void Open ()
 		{
 			string provider = "Default";
-			string gdaCncStr = "";
+			string gdaCncStr = string.Empty;
 			string[] args;
 			int len;
 			char [] separator = { ';' };
@@ -329,11 +322,13 @@ namespace System.Data.OleDb
 			if (State == ConnectionState.Open)
 				throw new InvalidOperationException ();
 
+			libgda.gda_init ("System.Data.OleDb", "1.0", 0, new string [0]);
+
 			gdaConnection = libgda.gda_client_open_connection (libgda.GdaClient,
-				connectionString, "", "", 0);
+				ConnectionString, string.Empty, string.Empty, 0);
 
-			if (gdaConnection==IntPtr.Zero)
-				throw new OleDbException (this);	
+			if (gdaConnection == IntPtr.Zero)
+				throw new OleDbException (this);
 			/* convert the connection string to its GDA equivalent */
 			//args = connectionString.Split (';');
 			//len = args.Length;
@@ -393,6 +388,8 @@ namespace System.Data.OleDb
 		[MonoTODO]
 		public override DataTable GetSchema ()
 		{
+			if (State == ConnectionState.Closed)
+				throw ExceptionHelper.ConnectionClosed ();
 			throw new NotImplementedException ();
 		}
 
@@ -405,6 +402,8 @@ namespace System.Data.OleDb
 		[MonoTODO]
 		public override DataTable GetSchema (String collectionName, string [] restrictionValues)
 		{
+			if (State == ConnectionState.Closed)
+				throw ExceptionHelper.ConnectionClosed ();
 			throw new NotImplementedException ();
 		}
 

+ 15 - 53
mcs/class/System.Data/System.Data.OleDb/OleDbDataAdapter.cs

@@ -57,17 +57,13 @@ namespace System.Data.OleDb
 
 		#region Constructors
 
-		public OleDbDataAdapter ()
-			: this (new OleDbCommand ())
+		public OleDbDataAdapter () : this ((OleDbCommand) null)
 		{
 		}
 
 		public OleDbDataAdapter (OleDbCommand selectCommand)
 		{
-			DeleteCommand = new OleDbCommand ();
-			InsertCommand = new OleDbCommand ();
 			SelectCommand = selectCommand;
-			UpdateCommand = new OleDbCommand ();
 		}
 
 		public OleDbDataAdapter (string selectCommandText, OleDbConnection selectConnection)
@@ -136,34 +132,18 @@ namespace System.Data.OleDb
 #endif
 		[EditorAttribute ("Microsoft.VSDesigner.Data.Design.DBCommandEditor, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.Drawing.Design.UITypeEditor, "+ Consts.AssemblySystem_Drawing)]
 		public new OleDbCommand UpdateCommand {
-			get {
-				return updateCommand;
-			}
-			set {
-				updateCommand = value;
-			}
+			get { return updateCommand; }
+			set { updateCommand = value; }
 		}
 
 		IDbCommand IDbDataAdapter.DeleteCommand {
-			get {
-				return DeleteCommand;
-			}
-			set { 
-				if (!(value is OleDbCommand))
-					throw new ArgumentException ();
-				DeleteCommand = (OleDbCommand)value;
-			}
+			get { return DeleteCommand; }
+			set { DeleteCommand = (OleDbCommand) value; }
 		}
 
 		IDbCommand IDbDataAdapter.InsertCommand {
-			get {
-				return InsertCommand;
-			}
-			set {
-				if (!(value is OleDbCommand))
-					throw new ArgumentException ();
-				InsertCommand = (OleDbCommand)value;
-			}
+			get { return InsertCommand; }
+			set { InsertCommand = (OleDbCommand) value; }
 		}
 
 		IDbCommand IDbDataAdapter.SelectCommand {
@@ -171,45 +151,27 @@ namespace System.Data.OleDb
 				return SelectCommand;
 			}
 			set {
-				if (!(value is OleDbCommand))
-					throw new ArgumentException ();
-				SelectCommand = (OleDbCommand)value;
+				SelectCommand = (OleDbCommand) value;
 			}
 		}
 
 		MissingMappingAction IDataAdapter.MissingMappingAction {
-			get {
-				return missingMappingAction;
-			}
-			set {
-				missingMappingAction = value;
-			}
+			get { return missingMappingAction; }
+			set { missingMappingAction = value; }
 		}
 
 		MissingSchemaAction IDataAdapter.MissingSchemaAction {
-			get {
-				return missingSchemaAction;
-			}
-			set {
-				missingSchemaAction = value;
-			}
+			get { return missingSchemaAction; }
+			set { missingSchemaAction = value; }
 		}
 		
 		IDbCommand IDbDataAdapter.UpdateCommand {
-			get {
-				return UpdateCommand;
-			}
-			set {
-				if (!(value is OleDbCommand))
-					throw new ArgumentException ();
-				UpdateCommand = (OleDbCommand)value;
-			}
+			get { return UpdateCommand; }
+			set { UpdateCommand = (OleDbCommand) value; }
 		}
 
 		ITableMappingCollection IDataAdapter.TableMappings {
-			get {
-				return TableMappings;
-			}
+			get { return TableMappings; }
 		}
 
 		#endregion // Properties

+ 21 - 0
mcs/class/System.Data/System.Data.SqlClient/ChangeLog

@@ -1,3 +1,24 @@
+2007-10-20  Gert Driesen  <[email protected]>
+
+	* SqlCommand.cs: Added constant for default CommandTimeout, instead
+	of using a magic number. Avoid unnecessary initialization. Fixed
+	default value for DesignTimeVisible. Return zero-length string if
+	CommandText is null. Use ExceptionHelper.InvalidEnumValueException
+	to avoid code duplication. Spaces to tabs and code formatting.
+	* SqlConnection.cs: Use different default package size on 2.0 profile.
+	Added constants for default values, instead of using magic numbers.
+	Avoid unnecessary initialization. In PacketSize, return default or
+	configured packet size when connection is not open. Use
+	ExceptionHelper.ConnectionClosed instead of local method. Removed
+	use of some hardcoded values in SetDefaultConnectionParameters, and
+	use Environment.MachineName as default WorkstationId instead of
+	DNS host name. Code formatting.
+	* SqlDataAdapter.cs: In default ctor, set SelectCommand to null.
+	Avoid unnecessary initializations. Use direct assignment in
+	IDbDataAdapter implementation. Fixed exception message for negative
+	UpdateBatchSize. In Dispose override, make sure to invoke base
+	method.
+
 2007-10-19  Gert Driesen  <[email protected]>
 
 	* SqlTransaction.cs: Clear connection in commit. In IsolationLevel,

+ 24 - 26
mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs

@@ -63,7 +63,9 @@ namespace System.Data.SqlClient {
 	{
 		#region Fields
 
-		bool disposed = false;
+		const int DEFAULT_COMMAND_TIMEOUT = 30;
+
+		bool disposed;
 		int commandTimeout;
 		bool designTimeVisible;
 		string commandText;
@@ -73,11 +75,11 @@ namespace System.Data.SqlClient {
 		UpdateRowSource updatedRowSource;
 		CommandBehavior behavior = CommandBehavior.Default;
 		SqlParameterCollection parameters;
-		string preparedStatement = null;
+		string preparedStatement;
 #if NET_2_0
 		SqlNotificationRequest notification;
-#endif
 		bool notificationAutoEnlist;
+#endif
 
 		#endregion // Fields
 
@@ -106,9 +108,11 @@ namespace System.Data.SqlClient {
 			this.commandType = CommandType.Text;
 			this.updatedRowSource = UpdateRowSource.Both;
 
-			this.designTimeVisible = false;
-			this.commandTimeout = 30;
+			this.commandTimeout = DEFAULT_COMMAND_TIMEOUT;
+#if NET_2_0
 			notificationAutoEnlist = true;
+#endif
+			designTimeVisible = true;
 			parameters = new SqlParameterCollection (this);
 		}
 
@@ -144,8 +148,12 @@ namespace System.Data.SqlClient {
 		override 
 #endif //NET_2_0
 		string CommandText {
-			get { return commandText; }
-			set { 
+			get {
+				if (commandText == null)
+					return string.Empty;
+				return commandText;
+			}
+			set {
 				if (value != commandText && preparedStatement != null)
 					Unprepare ();
 				commandText = value; 
@@ -154,7 +162,7 @@ namespace System.Data.SqlClient {
 
 #if !NET_2_0
 		[DataSysDescription ("Time to wait for command to execute.")]
-		[DefaultValue (30)]
+		[DefaultValue (DEFAULT_COMMAND_TIMEOUT)]
 #endif
 		public 
 #if NET_2_0
@@ -190,12 +198,7 @@ namespace System.Data.SqlClient {
 #endif
 
 				if (!Enum.IsDefined (typeof (CommandType), value))
-#if NET_2_0
-					throw new ArgumentOutOfRangeException (String.Format ("The CommandType enumeration value, {0}, is invalid",
-						value));
-#else
 					throw ExceptionHelper.InvalidEnumValueException ("CommandType", value);
-#endif
 				commandType = value; 
 			}
 		}
@@ -292,14 +295,9 @@ namespace System.Data.SqlClient {
 #endif // NET_2_0
 		UpdateRowSource UpdatedRowSource {
 			get { return updatedRowSource; }
-			set { 
+			set {
 				if (!Enum.IsDefined (typeof (UpdateRowSource), value))
-#if NET_2_0
-					throw new ArgumentOutOfRangeException (String.Format ("The UpdateRowSource enumeration value, {0}, is invalid",
-						value));
-#else
 					throw ExceptionHelper.InvalidEnumValueException ("UpdateRowSource", value);
-#endif
 				updatedRowSource = value;
 			}
 		}
@@ -307,14 +305,14 @@ namespace System.Data.SqlClient {
 #if NET_2_0
 		[Browsable (false)]
 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
-		public SqlNotificationRequest Notification { 
-			get { return notification; } 
+		public SqlNotificationRequest Notification {
+			get { return notification; }
 			set { notification = value; }
 		}
 
 		[DefaultValue (true)]
-		public bool NotificationAutoEnlist { 
-			get { return notificationAutoEnlist; } 
+		public bool NotificationAutoEnlist {
+			get { return notificationAutoEnlist; }
 			set { notificationAutoEnlist = value; }
 		}
 #endif
@@ -365,7 +363,7 @@ namespace System.Data.SqlClient {
 			ValidateCommand ("DeriveParameters");
 
 			SqlParameterCollection localParameters = new SqlParameterCollection (this);
-			localParameters.Add ("@procedure_name", SqlDbType.NVarChar, commandText.Length).Value = commandText;
+			localParameters.Add ("@procedure_name", SqlDbType.NVarChar, CommandText.Length).Value = CommandText;
 
 			string sql = "sp_procedure_params_rowset";
 
@@ -636,7 +634,7 @@ namespace System.Data.SqlClient {
 
 		public void ResetCommandTimeout ()
 		{
-			commandTimeout = 30;
+			commandTimeout = DEFAULT_COMMAND_TIMEOUT;
 		}
 
 		private void Unprepare ()
@@ -661,7 +659,7 @@ namespace System.Data.SqlClient {
 #else
 				throw new InvalidOperationException (String.Format ("ExecuteNonQuery requires an open Connection object to continue. This connection is closed.", method));
 #endif
-			if (commandText == String.Empty || commandText == null)
+			if (CommandText.Length == 0)
 				throw new InvalidOperationException ("The command text for this Command has not been set.");
 			if (Connection.DataReader != null)
 				throw new InvalidOperationException ("There is already an open DataReader associated with this Connection which must be closed first.");

+ 57 - 60
mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs

@@ -65,6 +65,15 @@ namespace System.Data.SqlClient {
 
 		// The set of SQL connection pools
 		static TdsConnectionPoolManager sqlConnectionPools = new TdsConnectionPoolManager (TdsVersion.tds70);
+#if NET_2_0
+		const int DEFAULT_PACKETSIZE = 8000;
+#else
+		const int DEFAULT_PACKETSIZE = 8192;
+#endif
+		const int DEFAULT_CONNECTIONTIMEOUT = 15;
+		const int DEFAULT_MAXPOOLSIZE = 100;
+		const int DEFAULT_MINPOOLSIZE = 0;
+		const int DEFAULT_PORT = 1433;
 
 		// The current connection pool
 		TdsConnectionPool pool;
@@ -86,15 +95,15 @@ namespace System.Data.SqlClient {
 		int minPoolSize;
 		int maxPoolSize;
 		int packetSize;
-		int port = 1433;
+		int port;
 		bool fireInfoMessageEventOnUserErrors;
 		bool statisticsEnabled;
 
 		// The current state
 		ConnectionState state = ConnectionState.Closed;
 
-		SqlDataReader dataReader = null;
-		XmlReader xmlReader = null;
+		SqlDataReader dataReader;
+		XmlReader xmlReader;
 
 		// The TDS object
 		ITds tds;
@@ -115,10 +124,11 @@ namespace System.Data.SqlClient {
 
 		private void Init (string connectionString)
 		{
-			connectionTimeout       = 15; // default timeout
-			dataSource              = string.Empty; // default datasource
-			packetSize              = 8192; // default packetsize
-			ConnectionString        = connectionString;
+			connectionTimeout = DEFAULT_CONNECTIONTIMEOUT;
+			dataSource = string.Empty;
+			packetSize = DEFAULT_PACKETSIZE;
+			port = DEFAULT_PORT;
+			ConnectionString = connectionString;
 		}
 
 		#endregion // Constructors
@@ -137,7 +147,11 @@ namespace System.Data.SqlClient {
 		override
 #endif // NET_2_0
 		string ConnectionString {
-			get { return connectionString; }
+			get {
+				if (connectionString == null)
+					return string.Empty;
+				return connectionString;
+			}
 			[MonoTODO("persist security info, encrypt, enlist keyword not implemented")]
 			set {
 				if (state == ConnectionState.Open)
@@ -199,9 +213,9 @@ namespace System.Data.SqlClient {
 		[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
 		public int PacketSize {
 			get {
-				if (State == ConnectionState.Open) 
-					return ((Tds)tds).PacketSize ;
-				return packetSize; 
+				if (State == ConnectionState.Open)
+					return ((Tds) tds).PacketSize;
+				return packetSize;
 			}
 		}
 
@@ -217,7 +231,7 @@ namespace System.Data.SqlClient {
 		string ServerVersion {
 			get {
 				if (state == ConnectionState.Closed)
-					throw CreateConnectionClosedException ();
+					throw ExceptionHelper.ConnectionClosed ();
 				else
 					return tds.ServerVersion; 
 			}
@@ -306,6 +320,7 @@ namespace System.Data.SqlClient {
 		{
 			if (connStringParameters == null || connStringParameters.Count == 0)
 				return string.Empty;
+
 			foreach (string key in keys) {
 				string value = connStringParameters [key];
 				if (value != null)
@@ -333,7 +348,7 @@ namespace System.Data.SqlClient {
 		public SqlTransaction BeginTransaction (IsolationLevel iso, string transactionName)
 		{
 			if (state == ConnectionState.Closed)
-				throw CreateConnectionClosedException ();
+				throw ExceptionHelper.ConnectionClosed ();
 			if (transaction != null)
 				throw new InvalidOperationException ("SqlConnection does not support parallel transactions.");
 
@@ -356,7 +371,7 @@ namespace System.Data.SqlClient {
 				isolevel = "SNAPSHOT";
 				break;
 			case IsolationLevel.Unspecified:
-				iso =  IsolationLevel.ReadCommitted;
+				iso = IsolationLevel.ReadCommitted;
 				isolevel = "READ COMMITTED";
 				break;
 			case IsolationLevel.Chaos:
@@ -571,7 +586,7 @@ namespace System.Data.SqlClient {
 			if (theDataSource == null)
 				throw new ArgumentException("Format of initialization string does not conform to specifications");
 
-			thePort = 1433; // default TCP port for SQL Server
+			thePort = DEFAULT_PORT; // default TCP port for SQL Server
 			bool success = true;
 
 			int idx = 0;
@@ -579,63 +594,56 @@ namespace System.Data.SqlClient {
 				theServerName = theDataSource.Substring (0, idx);
 				string p = theDataSource.Substring (idx + 1);
 				thePort = Int32.Parse (p);
-			}
-			else if ((idx = theDataSource.IndexOf ("\\")) > -1) {
+			} else if ((idx = theDataSource.IndexOf ("\\")) > -1) {
 				theServerName = theDataSource.Substring (0, idx);
 				theInstanceName = theDataSource.Substring (idx + 1);
 				// do port discovery via UDP port 1434
 				port = DiscoverTcpPortViaSqlMonitor (theServerName, theInstanceName);
 				if (port == -1)
 					success = false;
-			}
-			else if (theDataSource.Length == 0 || theDataSource == "(local)")
+			} else if (theDataSource.Length == 0 || theDataSource == "(local)")
 				theServerName = "localhost";
 			else
 				theServerName = theDataSource;
 
-			if ((idx = theServerName.IndexOf ("tcp:")) > -1) {
+			if ((idx = theServerName.IndexOf ("tcp:")) > -1)
 				theServerName = theServerName.Substring (idx + 4);
-			}
 
 			return success;
 		}
 
 		private bool ConvertIntegratedSecurity (string value)
 		{
-			if (value.ToUpper() == "SSPI") 
-			{
+			if (value.ToUpper() == "SSPI")
 				return true;
-			}
 
 			return ConvertToBoolean("integrated security", value);
 		}
 
-		private bool ConvertToBoolean(string key, string value)
+		private bool ConvertToBoolean (string key, string value)
 		{
-			string upperValue = value.ToUpper();
+			string upperValue = value.ToUpper ();
 
-			if (upperValue == "TRUE" ||upperValue == "YES") {
+			if (upperValue == "TRUE" || upperValue == "YES")
 				return true;
-			} else if (upperValue == "FALSE" || upperValue == "NO") {
+			else if (upperValue == "FALSE" || upperValue == "NO")
 				return false;
-			}
 
-			throw new ArgumentException(string.Format(CultureInfo.InvariantCulture,
+			throw new ArgumentException (string.Format (CultureInfo.InvariantCulture,
 				"Invalid value \"{0}\" for key '{1}'.", value, key));
 		}
 
-		private int ConvertToInt32(string key, string value)
+		private int ConvertToInt32 (string key, string value)
 		{
-			try
-			{
-				return int.Parse(value);
+			try {
+				return int.Parse (value);
 			} catch (Exception ex) {
-				throw new ArgumentException(string.Format(CultureInfo.InvariantCulture,
+				throw new ArgumentException (string.Format (CultureInfo.InvariantCulture,
 					"Invalid value \"{0}\" for key '{1}'.", value, key));
 			}
 		}
 
-		private int DiscoverTcpPortViaSqlMonitor(string ServerName, string InstanceName) 
+		private int DiscoverTcpPortViaSqlMonitor (string ServerName, string InstanceName) 
 		{
 			SqlMonitorSocket msock;
 			msock = new SqlMonitorSocket (ServerName, InstanceName);
@@ -746,27 +754,27 @@ namespace System.Data.SqlClient {
 		{
 			parms.Reset ();
 			dataSource = string.Empty;
-			connectionTimeout= 15;
+			connectionTimeout = DEFAULT_CONNECTIONTIMEOUT;
 			connectionReset = true;
 			pooling = true;
-			maxPoolSize = 100; 
-			minPoolSize = 0;
-			packetSize = 8192; 
+			maxPoolSize = DEFAULT_MAXPOOLSIZE;
+			minPoolSize = DEFAULT_MINPOOLSIZE;
+			packetSize = DEFAULT_PACKETSIZE;
 			
 			parameters["APPLICATION NAME"] = "Mono SqlClient Data Provider";
-			parameters["CONNECT TIMEOUT"] = "15";
+			parameters["CONNECT TIMEOUT"] = connectionTimeout.ToString (CultureInfo.InvariantCulture);
 			parameters["CONNECTION LIFETIME"] = "0";
 			parameters["CONNECTION RESET"] = "true";
 			parameters["ENLIST"] = "true";
 			parameters["INTEGRATED SECURITY"] = "false";
 			parameters["INITIAL CATALOG"] = string.Empty;
-			parameters["MAX POOL SIZE"] = "100";
-			parameters["MIN POOL SIZE"] = "0";
+			parameters["MAX POOL SIZE"] = maxPoolSize.ToString (CultureInfo.InvariantCulture);
+			parameters["MIN POOL SIZE"] = minPoolSize.ToString (CultureInfo.InvariantCulture);
 			parameters["NETWORK LIBRARY"] = "dbmssocn";
-			parameters["PACKET SIZE"] = "8192";
+			parameters["PACKET SIZE"] = packetSize.ToString (CultureInfo.InvariantCulture);
 			parameters["PERSIST SECURITY INFO"] = "false";
 			parameters["POOLING"] = "true";
-			parameters["WORKSTATION ID"] = Dns.GetHostName();
+			parameters["WORKSTATION ID"] = Environment.MachineName;
  #if NET_2_0
 			async = false;
 			parameters ["ASYNCHRONOUS PROCESSING"] = "false";
@@ -775,9 +783,7 @@ namespace System.Data.SqlClient {
 		
 		private void SetProperties (string name , string value)
 		{
-
-			switch (name) 
-			{
+			switch (name) {
 			case "APP" :
 			case "APPLICATION NAME" :
 				parms.ApplicationName = value;
@@ -814,19 +820,15 @@ namespace System.Data.SqlClient {
 				break;
 			case "ENCRYPT":
 				if (ConvertToBoolean("encrypt", value))
-				{
 					throw new NotImplementedException("SSL encryption for"
 						+ " data sent between client and server is not"
 						+ " implemented.");
-				}
 				break;
 			case "ENLIST" :
 				if (!ConvertToBoolean("enlist", value))
-				{
 					throw new NotImplementedException("Disabling the automatic"
 						+ " enlistment of connections in the thread's current"
 						+ " transaction context is not implemented.");
-				}
 				break;
 			case "INITIAL CATALOG" :
 			case "DATABASE" :
@@ -841,7 +843,7 @@ namespace System.Data.SqlClient {
 				if (tmpMaxPoolSize < 0)
 					throw new ArgumentException ("Invalid MAX POOL SIZE. Must be a intger >= 0");
 				else
-					maxPoolSize = tmpMaxPoolSize; 
+					maxPoolSize = tmpMaxPoolSize;
 				break;
 			case "MIN POOL SIZE" :
 				int tmpMinPoolSize = ConvertToInt32 ("min pool size" , value);
@@ -930,11 +932,6 @@ namespace System.Data.SqlClient {
 		}
 #endif
 
-		private static InvalidOperationException CreateConnectionClosedException ()
-		{
-			return new InvalidOperationException ("Invalid operation. The Connection is closed.");
-		}
-
 		private sealed class SqlMonitorSocket : UdpClient 
 		{
 			// UDP port that the SQL Monitor listens
@@ -1435,7 +1432,7 @@ namespace System.Data.SqlClient {
 		public override DataTable GetSchema ()
 		{
 			if (state == ConnectionState.Closed)
-				throw CreateConnectionClosedException ();
+				throw ExceptionHelper.ConnectionClosed ();
 
 			return MetaDataCollections.Instance;
 		}
@@ -1450,7 +1447,7 @@ namespace System.Data.SqlClient {
 			// LAMESPEC: In MS.NET, if collectionName is null, it throws ArgumentException.
 
 			if (state == ConnectionState.Closed)
-				throw CreateConnectionClosedException ();
+				throw ExceptionHelper.ConnectionClosed ();
 
 			String cName = null;
 			DataTable schemaTable = MetaDataCollections.Instance;

+ 9 - 31
mcs/class/System.Data/System.Data.SqlClient/SqlDataAdapter.cs

@@ -8,8 +8,6 @@
 //
 // (C) Ximian, Inc 2002
 // Copyright (C) 2002 Tim Coleman
-//
-
 //
 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
 //
@@ -60,17 +58,13 @@ namespace System.Data.SqlClient {
 
 		#region Constructors
 		
-		public SqlDataAdapter () 
-			: this (new SqlCommand ())
+		public SqlDataAdapter () : this ((SqlCommand) null)
 		{
 		}
 
 		public SqlDataAdapter (SqlCommand selectCommand) 
 		{
-			DeleteCommand = null;
-			InsertCommand = null;
 			SelectCommand = selectCommand;
-			UpdateCommand = null;
 #if NET_2_0
 			UpdateBatchSize = 1;
 #endif
@@ -78,7 +72,7 @@ namespace System.Data.SqlClient {
 
 		public SqlDataAdapter (string selectCommandText, SqlConnection selectConnection) 
 			: this (new SqlCommand (selectCommandText, selectConnection))
-		{ 
+		{
 		}
 
 		public SqlDataAdapter (string selectCommandText, string selectConnectionString)
@@ -132,38 +126,22 @@ namespace System.Data.SqlClient {
 
 		IDbCommand IDbDataAdapter.DeleteCommand {
 			get { return DeleteCommand; }
-			set { 
-				if (!(value is SqlCommand)) 
-					throw new ArgumentException ();
-				DeleteCommand = (SqlCommand)value;
-			}
+			set { DeleteCommand = (SqlCommand) value; }
 		}
 
 		IDbCommand IDbDataAdapter.InsertCommand {
 			get { return InsertCommand; }
-			set { 
-				if (!(value is SqlCommand)) 
-					throw new ArgumentException ();
-				InsertCommand = (SqlCommand)value;
-			}
+			set { InsertCommand = (SqlCommand) value; }
 		}
 
 		IDbCommand IDbDataAdapter.SelectCommand {
 			get { return SelectCommand; }
-			set {
-				if (!(value is SqlCommand)) 
-					throw new ArgumentException ();
-				SelectCommand = (SqlCommand)value;
-			}
+			set { SelectCommand = (SqlCommand) value; }
 		}
 
 		IDbCommand IDbDataAdapter.UpdateCommand {
 			get { return UpdateCommand; }
-			set { 
-				if (!(value is SqlCommand)) 
-					throw new ArgumentException ();
-				UpdateCommand = (SqlCommand)value;
-			}
+			set {  UpdateCommand = (SqlCommand) value; }
 		}
 
 		ITableMappingCollection IDataAdapter.TableMappings {
@@ -171,11 +149,11 @@ namespace System.Data.SqlClient {
 		}
 
 #if NET_2_0
-		public override int UpdateBatchSize { 
+		public override int UpdateBatchSize {
 			get { return updateBatchSize; }
 			set { 
 				if (value < 0)
-					throw new ArgumentOutOfRangeException ();
+					throw new ArgumentOutOfRangeException ("UpdateBatchSize");
 				updateBatchSize = value; 
 			}
 		}
@@ -206,6 +184,7 @@ namespace System.Data.SqlClient {
 				// Release unmanaged resources
 				disposed = true;
 			}
+			base.Dispose (disposing);
 		}
 #endif
 
@@ -282,6 +261,5 @@ namespace System.Data.SqlClient {
 		public event SqlRowUpdatingEventHandler RowUpdating;
 
 		#endregion // Events and Delegates
-
 	}
 }

+ 12 - 4
mcs/class/System.Data/System.Data_test.dll.sources

@@ -76,19 +76,26 @@ System.Data/RowNotInTableExceptionTest.cs
 System.Data/VersionNotFoundException.cs
 System.Data/XmlDataLoaderTest.cs
 System.Data/XmlDataReaderTest.cs
-System.Data.Common/DbProviderFactoriesConfigurationHandlerTest.cs
 System.Data.Common/ConnectionStringsSectionTest.cs
+System.Data.Common/DataAdapterTest.cs
 System.Data.Common/DataColumnMappingCollectionTest.cs
 System.Data.Common/DataTableMappingCollectionTest.cs
 System.Data.Common/DBDataPermissionAttributeTest.cs
 System.Data.Common/DBDataPermissionTest.cs
 System.Data.Common/DbConnectionStringBuilderTest.cs
+System.Data.Common/DbDataAdapterTest.cs
+System.Data.Common/DbProviderFactoriesConfigurationHandlerTest.cs
 System.Data.Common/DbTransactionTest.cs
-System.Data.Common/DataAdapterTest.cs
+System.Data.Odbc/OdbcCommandTest.cs
+System.Data.Odbc/OdbcConnectionTest.cs
+System.Data.Odbc/OdbcDataAdapterTest.cs
+System.Data.Odbc/OdbcParameterCollectionTest.cs
+System.Data.Odbc/OdbcParameterTest.cs
 System.Data.Odbc/OdbcPermissionAttributeTest.cs
 System.Data.Odbc/OdbcPermissionTest.cs
-System.Data.Odbc/OdbcParameterTest.cs
-System.Data.Odbc/OdbcParameterCollectionTest.cs
+System.Data.OleDb/OleDbCommandTest.cs
+System.Data.OleDb/OleDbConnectionTest.cs
+System.Data.OleDb/OleDbDataAdapterTest.cs
 System.Data.OleDb/OleDbParameterCollectionTest.cs
 System.Data.OleDb/OleDbPermissionAttributeTest.cs
 System.Data.OleDb/OleDbPermissionTest.cs
@@ -97,4 +104,5 @@ System.Data.SqlClient/SqlConnectionTest.cs
 System.Data.SqlClient/SqlConnectionStringBuilderTest.cs
 System.Data.SqlClient/SqlClientPermissionAttributeTest.cs
 System.Data.SqlClient/SqlClientPermissionTest.cs
+System.Data.SqlClient/SqlDataAdapterTest.cs
 Mono.Data.SqlExpressions/DataColumnExpressionTest.cs

+ 8 - 0
mcs/class/System.Data/Test/System.Data.Common/ChangeLog

@@ -1,3 +1,11 @@
+2007-10-20  Gert Driesen  <[email protected]>
+
+	* DbDataAdapterTest.cs: Added test for UpdateBatchSize.
+	* DataAdapterTest.cs: Added tests for AcceptChangesDuringFile,
+	AcceptChangesDuringUpdate, ContinueUpdateOnError, FillLoadOption,
+	MissingMappingAction, MissingSchemaAction and
+	ReturnProviderSpecificTypes.
+
 2007-10-19  Gert Driesen  <[email protected]>
 
 	* DbTransactionTest.cs: Enabled test for bug #325397.

+ 207 - 11
mcs/class/System.Data/Test/System.Data.Common/DataAdapterTest.cs

@@ -3,6 +3,7 @@
 //
 // Author:
 //      Miguel de Icaza ([email protected])
+//      Gert Driesen ([email protected])
 //
 // Copyright (c) 2006 Novell Inc., and the individuals listed
 // on the ChangeLog entries.
@@ -35,24 +36,219 @@ using NUnit.Framework;
 
 namespace MonoTests.System.Data.Common
 {
+	[TestFixture]
+	public class DataAdapterTest
+	{
+		[Test]
+		public void AcceptChangesDuringFill ()
+		{
+			DataAdapter da = new MyAdapter ();
+			da.AcceptChangesDuringFill = true;
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+			da.AcceptChangesDuringFill = false;
+			Assert.IsFalse (da.AcceptChangesDuringFill, "#2");
+			da.AcceptChangesDuringFill = true;
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#3");
+		}
 
 #if NET_2_0
+		[Test]
+		public void AcceptChangesDuringUpdate ()
+		{
+			DataAdapter da = new MyAdapter ();
+			da.AcceptChangesDuringUpdate = true;
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#1");
+			da.AcceptChangesDuringUpdate = false;
+			Assert.IsFalse (da.AcceptChangesDuringUpdate, "#2");
+			da.AcceptChangesDuringUpdate = true;
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#3");
+		}
+#endif
 
-	class MyAdapter : DataAdapter {
-		
-	}
+		[Test]
+		public void ContinueUpdateOnError ()
+		{
+			DataAdapter da = new MyAdapter ();
+			da.ContinueUpdateOnError = true;
+			Assert.IsTrue (da.ContinueUpdateOnError, "#1");
+			da.ContinueUpdateOnError = false;
+			Assert.IsFalse (da.ContinueUpdateOnError, "#2");
+			da.ContinueUpdateOnError = true;
+			Assert.IsTrue (da.ContinueUpdateOnError, "#3");
+		}
 
-	[TestFixture]
-	public class DataAdapterTest {
-		
-		[Test] [ExpectedException(typeof (NotSupportedException))]
-	  	public void TestFillDirect ()
+#if NET_2_0
+		[Test]
+		public void Fill_Direct ()
 		{
-			MyAdapter m = new MyAdapter ();
+			DataAdapter da = new MyAdapter ();
 			DataSet ds = new DataSet ();
-			
-			m.Fill (ds);
+			try {
+				da.Fill (ds);
+				Assert.Fail ("#1");
+			} catch (NotSupportedException ex) {
+				// Specified method is not supported
+				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+			}
+		}
+
+		[Test]
+		public void FillLoadOption ()
+		{
+			DataAdapter da = new MyAdapter ();
+			da.FillLoadOption = LoadOption.PreserveChanges;
+			Assert.AreEqual (LoadOption.PreserveChanges, da.FillLoadOption, "#1");
+			da.FillLoadOption = LoadOption.OverwriteChanges;
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#2");
+			da.FillLoadOption = LoadOption.Upsert;
+			Assert.AreEqual (LoadOption.Upsert, da.FillLoadOption, "#3");
+		}
+
+		[Test]
+		public void FillLoadOption_Invalid ()
+		{
+			DataAdapter da = new MyAdapter ();
+			try {
+				da.FillLoadOption = (LoadOption) 666;
+				Assert.Fail ("#1");
+			} catch (ArgumentOutOfRangeException ex) {
+				// The LoadOption enumeration value, 666, is invalid
+				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsTrue (ex.Message.IndexOf ("LoadOption") != -1, "#5");
+				Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
+				Assert.IsNotNull (ex.ParamName, "#7");
+				Assert.AreEqual ("LoadOption", ex.ParamName, "#8");
+			}
+		}
+#endif
+
+		[Test]
+		public void MissingMappingAction_Valid ()
+		{
+			DataAdapter da = new MyAdapter ();
+			da.MissingMappingAction = MissingMappingAction.Passthrough;
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#1");
+			da.MissingMappingAction = MissingMappingAction.Ignore;
+			Assert.AreEqual (MissingMappingAction.Ignore, da.MissingMappingAction, "#2");
+			da.MissingMappingAction = MissingMappingAction.Error;
+			Assert.AreEqual (MissingMappingAction.Error, da.MissingMappingAction, "#3");
+		}
+
+		[Test]
+		public void MissingMappingAction_Invalid ()
+		{
+			DataAdapter da = new MyAdapter ();
+			try {
+				da.MissingMappingAction = (MissingMappingAction) 666;
+				Assert.Fail ("#1");
+#if NET_2_0
+			} catch (ArgumentOutOfRangeException ex) {
+				// The MissingMappingAction enumeration value, 666, is invalid
+				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsTrue (ex.Message.IndexOf ("MissingMappingAction") != -1, "#5");
+				Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
+				Assert.IsNotNull (ex.ParamName, "#7");
+				Assert.AreEqual ("MissingMappingAction", ex.ParamName, "#8");
+			}
+#else
+			} catch (ArgumentException ex) {
+				// The MissingMappingAction enumeration value, 666, is invalid
+				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsTrue (ex.Message.IndexOf ("MissingMappingAction") != -1, "#5");
+				Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
+				Assert.IsNull (ex.ParamName, "#7");
+			}
+#endif
 		}
+
+		[Test]
+		public void MissingSchemaAction_Valid ()
+		{
+			DataAdapter da = new MyAdapter ();
+			da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
+			Assert.AreEqual (MissingSchemaAction.AddWithKey, da.MissingSchemaAction, "#1");
+			da.MissingSchemaAction = MissingSchemaAction.Ignore;
+			Assert.AreEqual (MissingSchemaAction.Ignore, da.MissingSchemaAction, "#2");
+			da.MissingSchemaAction = MissingSchemaAction.Error;
+			Assert.AreEqual (MissingSchemaAction.Error, da.MissingSchemaAction, "#3");
+		}
+
+		[Test]
+		public void MissingSchemaAction_Invalid ()
+		{
+			DataAdapter da = new MyAdapter ();
+			try {
+				da.MissingSchemaAction = (MissingSchemaAction) 666;
+				Assert.Fail ("#1");
+#if NET_2_0
+			} catch (ArgumentOutOfRangeException ex) {
+				// The MissingSchemaAction enumeration value, 666, is invalid
+				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsTrue (ex.Message.IndexOf ("MissingSchemaAction") != -1, "#5");
+				Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
+				Assert.IsNotNull (ex.ParamName, "#7");
+				Assert.AreEqual ("MissingSchemaAction", ex.ParamName, "#8");
+			}
+#else
+			} catch (ArgumentException ex) {
+				// The MissingSchemaAction enumeration value, 666, is invalid
+				Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsTrue (ex.Message.IndexOf ("MissingSchemaAction") != -1, "#5");
+				Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
+				Assert.IsNull (ex.ParamName, "#7");
+			}
+#endif
+		}
+
+#if NET_2_0
+		[Test]
+		public void ReturnProviderSpecificTypes ()
+		{
+			DataAdapter da = new MyAdapter ();
+			da.ReturnProviderSpecificTypes = true;
+			Assert.IsTrue (da.ReturnProviderSpecificTypes, "#1");
+			da.ReturnProviderSpecificTypes = false;
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#2");
+			da.ReturnProviderSpecificTypes = true;
+			Assert.IsTrue (da.ReturnProviderSpecificTypes, "#3");
+		}
+#endif
 	}
+
+	class MyAdapter : DataAdapter
+	{
+#if ONLY_1_1
+		public override int Fill (DataSet dataSet)
+		{
+			throw new NotImplementedException ();
+		}
+
+		public override DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType)
+		{
+			throw new NotImplementedException ();
+		}
+
+		public override IDataParameter[] GetFillParameters ()
+		{
+			throw new NotImplementedException ();
+		}
+
+		public override int Update (DataSet dataSet)
+		{
+			throw new NotImplementedException ();
+		}
 #endif
+	}
 }

+ 116 - 0
mcs/class/System.Data/Test/System.Data.Common/DbDataAdapterTest.cs

@@ -0,0 +1,116 @@
+//
+// DbDataAdapterTest.cs - NUnit Test Cases for testing the DbDataAdapter class
+//
+// Author:
+//      Gert Driesen ([email protected])
+//
+// Copyright (c) 2007 Gert Driesen
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Data;
+using System.Data.Common;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Data.Common
+{
+	[TestFixture]
+	public class DbDataAdapterTest
+	{
+#if NET_2_0
+		[Test]
+		public void UpdateBatchSize ()
+		{
+			MyAdapter da = new MyAdapter ();
+			try {
+				da.UpdateBatchSize = 0;
+				Assert.Fail ("#A1");
+			} catch (NotSupportedException ex) {
+				// Specified method is not supported
+				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#A2");
+				Assert.IsNull (ex.InnerException, "#A3");
+				Assert.IsNotNull (ex.Message, "#A4");
+			}
+			Assert.AreEqual (1, da.UpdateBatchSize, "#A5");
+
+			try {
+				da.UpdateBatchSize = int.MaxValue;
+				Assert.Fail ("#B1");
+			} catch (NotSupportedException ex) {
+				// Specified method is not supported
+				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+			Assert.AreEqual (1, da.UpdateBatchSize, "#B5");
+
+			da.UpdateBatchSize = 1;
+			Assert.AreEqual (1, da.UpdateBatchSize, "#C");
+		}
+
+		[Test]
+		public void UpdateBatchSize_Negative ()
+		{
+			MyAdapter da = new MyAdapter ();
+			try {
+				da.UpdateBatchSize = -1;
+				Assert.Fail ("#1");
+			} catch (NotSupportedException ex) {
+				// Specified method is not supported
+				Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+			}
+		}
+#endif
+
+		class MyAdapter : DbDataAdapter
+		{
+#if ONLY_1_1
+			protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command,
+										     StatementType statementType,
+										     DataTableMapping tableMapping)
+			{
+				throw new NotImplementedException ();
+			}
+
+			protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command,
+										       StatementType statementType,
+										       DataTableMapping tableMapping)
+			{
+				throw new NotImplementedException ();
+			}
+
+			protected override void OnRowUpdated (RowUpdatedEventArgs value)
+			{
+				throw new NotImplementedException ();
+			}
+
+			protected override void OnRowUpdating (RowUpdatingEventArgs value)
+			{
+				throw new NotImplementedException ();
+			}
+#endif
+		}
+	}
+}

+ 10 - 0
mcs/class/System.Data/Test/System.Data.Odbc/ChangeLog

@@ -1,3 +1,13 @@
+2007-10-21  Gert Driesen  <[email protected]>
+
+	* OdbcDataAdapterTest.cs: Added tests for ctors, DeleteCommand,
+	InsertCommand, SelectCommand, UpdateCommand and Dispose.
+	* OdbcDataReaderTest.cs: fixed line endings.
+	* OdbcCommandTest.cs: Added tests for ctors and CommantText.
+	* OdbcConnectionTest.cs: Removed original test that relied on MySQL.
+	Added ctor tests. Added tests for BeginTransaction, GetSchema and
+	ServerVersion with connection that is closed.
+
 2007-06-08  Nagappan A  <[email protected]>
 
 	* OdbcParameterTest.cs (OdbcTypeTest): The default data type of

+ 195 - 0
mcs/class/System.Data/Test/System.Data.Odbc/OdbcCommandTest.cs

@@ -0,0 +1,195 @@
+//
+// OdbcCommandTest.cs - NUnit Test Cases for testing
+// System.Data.Odbc.OdbcCommand
+// 
+// Author:
+// 	Gert Driesen ([email protected])
+//
+// Copyright (c) 2007 Gert Driesen
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.Data;
+using System.Data.Odbc;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Data.Odbc
+{
+	[TestFixture]
+	public class OdbcCommandTest
+	{
+		const string COMMAND_TEXT = "SELECT * FROM Authors";
+
+		[Test] // OdbcCommand ()
+		public void Constructor1 ()
+		{
+			OdbcCommand cmd = new OdbcCommand ();
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#3");
+			Assert.IsNull (cmd.Connection, "#4");
+			Assert.IsNull (cmd.Container, "#5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#6");
+			Assert.IsNotNull (cmd.Parameters, "#7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#8");
+			Assert.IsNull (cmd.Site, "#9");
+			Assert.IsNull (cmd.Transaction, "#10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#11");
+		}
+
+		[Test] // OdbcCommand (string)
+		public void Constructor2 ()
+		{
+			OdbcCommand cmd = new OdbcCommand (COMMAND_TEXT);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
+			Assert.IsNull (cmd.Connection, "#A4");
+			Assert.IsNull (cmd.Container, "#A5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
+			Assert.IsNotNull (cmd.Parameters, "#A7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#A8");
+			Assert.IsNull (cmd.Site, "#A9");
+			Assert.IsNull (cmd.Transaction, "#A10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A11");
+
+			cmd = new OdbcCommand ((string) null);
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
+			Assert.IsNull (cmd.Connection, "#B4");
+			Assert.IsNull (cmd.Container, "#B5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
+			Assert.IsNotNull (cmd.Parameters, "#B7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#B8");
+			Assert.IsNull (cmd.Site, "#B9");
+			Assert.IsNull (cmd.Transaction, "#B10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B11");
+		}
+
+		[Test] // OdbcCommand (string, OdbcConnection)
+		public void Constructor3 ()
+		{
+			OdbcConnection conn = new OdbcConnection ();
+			OdbcCommand cmd;
+
+			cmd = new OdbcCommand (COMMAND_TEXT, conn);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
+			Assert.AreSame (conn, cmd.Connection, "#A4");
+			Assert.IsNull (cmd.Container, "#A5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
+			Assert.IsNotNull (cmd.Parameters, "#A7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#A8");
+			Assert.IsNull (cmd.Site, "#A9");
+			Assert.IsNull (cmd.Transaction, "#A10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A11");
+
+			cmd = new OdbcCommand ((string) null, conn);
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
+			Assert.AreSame (conn, cmd.Connection, "#B4");
+			Assert.IsNull (cmd.Container, "#B5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
+			Assert.IsNotNull (cmd.Parameters, "#B7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#B8");
+			Assert.IsNull (cmd.Site, "#B9");
+			Assert.IsNull (cmd.Transaction, "#B10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B11");
+
+			cmd = new OdbcCommand (COMMAND_TEXT, (OdbcConnection) null);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#C2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
+			Assert.IsNull (cmd.Connection, "#C4");
+			Assert.IsNull (cmd.Container, "#C5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
+			Assert.IsNotNull (cmd.Parameters, "#C7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#C8");
+			Assert.IsNull (cmd.Site, "#C9");
+			Assert.IsNull (cmd.Transaction, "#C10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C11");
+		}
+
+		[Test] // OdbcCommand (string, OdbcConnection, OdbcTransaction)
+		public void Constructor4 ()
+		{
+			OdbcConnection conn = new OdbcConnection ();
+			OdbcCommand cmd;
+
+			cmd = new OdbcCommand (COMMAND_TEXT, conn, (OdbcTransaction) null);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
+			Assert.AreSame (conn, cmd.Connection, "#A4");
+			Assert.IsNull (cmd.Container, "#A5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
+			Assert.IsNotNull (cmd.Parameters, "#A7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#A8");
+			Assert.IsNull (cmd.Site, "#A9");
+			Assert.IsNull (cmd.Transaction, "#A10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A11");
+
+			cmd = new OdbcCommand ((string) null, conn, (OdbcTransaction) null);
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
+			Assert.AreSame (conn, cmd.Connection, "#B4");
+			Assert.IsNull (cmd.Container, "#B5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
+			Assert.IsNotNull (cmd.Parameters, "#B7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#B8");
+			Assert.IsNull (cmd.Site, "#B9");
+			Assert.IsNull (cmd.Transaction, "#B10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B11");
+
+			cmd = new OdbcCommand (COMMAND_TEXT, (OdbcConnection) null, (OdbcTransaction) null);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#C2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
+			Assert.IsNull (cmd.Connection, "#C4");
+			Assert.IsNull (cmd.Container, "#C5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
+			Assert.IsNotNull (cmd.Parameters, "#C7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#C8");
+			Assert.IsNull (cmd.Site, "#C9");
+			Assert.IsNull (cmd.Transaction, "#C10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C11");
+		}
+
+		[Test]
+		public void CommandText ()
+		{
+			OdbcCommand cmd = new OdbcCommand ();
+			cmd.CommandText = COMMAND_TEXT;
+			Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#1");
+			cmd.CommandText = null;
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#2");
+			cmd.CommandText = COMMAND_TEXT;
+			Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#3");
+			cmd.CommandText = string.Empty;
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#4");
+		}
+	}
+}

+ 233 - 53
mcs/class/System.Data/Test/System.Data.Odbc/OdbcConnectionTest.cs

@@ -1,53 +1,233 @@
-//
-// OdbcConnectionTest.cs - NUnit Test Cases for testing the
-//                          OdbcConnectionTest class
-// Author:
-//      Sureshkumar T ([email protected])
-//
-// Copyright (c) 2004 Novell Inc., and the individuals listed
-// on the ChangeLog entries.
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using System;
-using System.Data;
-using System.Data.Odbc;
-
-using NUnit.Framework;
-
-namespace MonoTests.System.Data.Odbc
-{
-
-  [TestFixture]
-  public class OdbcConnectionTest : MySqlOdbcBaseClient 
-  {
-          [Test]
-          public void MaximumConnectionsLeakTest () {
-	  	OdbcConnection conn = new OdbcConnection (connectionString);
-		// if your db allows a maximum no. of simultaneous connections
-		// below 200, this test will work. Otherwise, change this limit
-		for (int i=0; i < 200; i++) {
-			conn.Open ();
-			conn.Close ();
-		}
-          }
-    }
-}
+//
+// OdbcConnectionTest.cs - NUnit Test Cases for testing the
+//                          OdbcConnectionTest class
+// Author:
+//      Gert Driesen ([email protected])
+//
+// Copyright (c) 2007 Gert Driesen
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Data;
+using System.Data.Odbc;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Data.Odbc
+{
+	[TestFixture]
+	public class OdbcConnectionTest
+	{
+		const string CONNECTION_STRING = "Driver={SQL Server};Server=SQLSRV;Database=Mono;";
+
+		[Test] // OdbcConnection ()
+		public void Constructor1 ()
+		{
+			OdbcConnection cn = new OdbcConnection ();
+
+			Assert.AreEqual (string.Empty, cn.ConnectionString, "#1");
+			Assert.AreEqual (15, cn.ConnectionTimeout, "#2");
+			Assert.IsNull (cn.Container, "#3");
+			Assert.AreEqual (string.Empty, cn.Database, "#4");
+			Assert.AreEqual (string.Empty, cn.DataSource, "#5");
+			Assert.AreEqual (string.Empty, cn.Driver, "#6");
+			Assert.IsNull (cn.Site, "#7");
+			Assert.AreEqual (ConnectionState.Closed, cn.State, "#8");
+		}
+
+		[Test] // OdbcConnection (string)
+		public void Constructor2 ()
+		{
+			OdbcConnection cn = new OdbcConnection (CONNECTION_STRING);
+			Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#A1");
+			Assert.AreEqual (15, cn.ConnectionTimeout, "#A2");
+			Assert.IsNull (cn.Container, "#A3");
+			Assert.AreEqual (string.Empty, cn.Database, "#A4");
+			Assert.AreEqual (string.Empty, cn.DataSource, "#A5");
+			Assert.AreEqual (string.Empty, cn.Driver, "#A6");
+			Assert.IsNull (cn.Site, "#A7");
+			Assert.AreEqual (ConnectionState.Closed, cn.State, "#A8");
+
+			cn = new OdbcConnection ((string) null);
+			Assert.AreEqual (string.Empty, cn.ConnectionString, "#B1");
+			Assert.AreEqual (15, cn.ConnectionTimeout, "#B2");
+			Assert.IsNull (cn.Container, "#B3");
+			Assert.AreEqual (string.Empty, cn.Database, "#B4");
+			Assert.AreEqual (string.Empty, cn.DataSource, "#B5");
+			Assert.AreEqual (string.Empty, cn.Driver, "#B6");
+			Assert.IsNull (cn.Site, "#B7");
+			Assert.AreEqual (ConnectionState.Closed, cn.State, "#B8");
+		}
+
+		[Test]
+		public void BeginTransaction_Connection_Closed ()
+		{
+			OdbcConnection cn = new OdbcConnection ();
+
+			try {
+				cn.BeginTransaction ();
+				Assert.Fail ("#A1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
+				Assert.IsNull (ex.InnerException, "#A3");
+				Assert.IsNotNull (ex.Message, "#A4");
+			}
+
+			try {
+				cn.BeginTransaction ((IsolationLevel) 666);
+				Assert.Fail ("#B1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+
+			try {
+				cn.BeginTransaction (IsolationLevel.Serializable);
+				Assert.Fail ("#C1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
+				Assert.IsNull (ex.InnerException, "#C3");
+				Assert.IsNotNull (ex.Message, "#C4");
+			}
+		}
+
+		[Test]
+		public void ConnectionString ()
+		{
+			OdbcConnection cn = new OdbcConnection ();
+			cn.ConnectionString = CONNECTION_STRING;
+			Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#1");
+			cn.ConnectionString = null;
+			Assert.AreEqual (string.Empty, cn.ConnectionString, "#2");
+			cn.ConnectionString = CONNECTION_STRING;
+			Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#3");
+			cn.ConnectionString = string.Empty;
+			Assert.AreEqual (string.Empty, cn.ConnectionString, "#4");
+		}
+
+#if NET_2_0
+		[Test]
+		public void GetSchema_Connection_Closed ()
+		{
+			OdbcConnection cn = new OdbcConnection ();
+
+			try {
+				cn.GetSchema ();
+				Assert.Fail ("#A1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+
+			try {
+				cn.GetSchema ("Tables");
+				Assert.Fail ("#B1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+
+			try {
+				cn.GetSchema ((string) null);
+				Assert.Fail ("#C1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
+				Assert.IsNull (ex.InnerException, "#C3");
+				Assert.IsNotNull (ex.Message, "#C4");
+			}
+
+			try {
+				cn.GetSchema ("Tables", new string [] { "master" });
+				Assert.Fail ("#D1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
+				Assert.IsNull (ex.InnerException, "#D3");
+				Assert.IsNotNull (ex.Message, "#D4");
+			}
+
+			try {
+				cn.GetSchema ((string) null, new string [] { "master" });
+				Assert.Fail ("#E1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
+				Assert.IsNull (ex.InnerException, "#E3");
+				Assert.IsNotNull (ex.Message, "#E4");
+			}
+
+			try {
+				cn.GetSchema ("Tables", (string []) null);
+				Assert.Fail ("#F1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
+				Assert.IsNull (ex.InnerException, "#F3");
+				Assert.IsNotNull (ex.Message, "#F4");
+			}
+
+			try {
+				cn.GetSchema ((string) null, (string []) null);
+				Assert.Fail ("#G1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#G2");
+				Assert.IsNull (ex.InnerException, "#G3");
+				Assert.IsNotNull (ex.Message, "#G4");
+			}
+		}
+#endif
+
+		[Test]
+		public void ServerVersion_Connection_Closed ()
+		{
+			OdbcConnection cn = new OdbcConnection ();
+			try {
+				Assert.Fail ("#A1:" + cn.ServerVersion);
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
+				Assert.IsNull (ex.InnerException, "#A3");
+				Assert.IsNotNull (ex.Message, "#A4");
+			}
+
+			cn = new OdbcConnection (CONNECTION_STRING);
+			try {
+				Assert.Fail ("#B1:" + cn.ServerVersion);
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+	}
+}

+ 524 - 0
mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataAdapterTest.cs

@@ -0,0 +1,524 @@
+//
+// OdbcDataAdapterTest.cs - NUnit Test Cases for testing the
+//                        OdbcDataAdapter class
+// Author:
+//      Gert Driesen ([email protected])
+//
+// Copyright (c) 2007 Gert Driesen
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Data;
+using System.Data.Odbc;
+using System.Data.OleDb;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Data.Odbc
+{
+	[TestFixture]
+	public class OdbcDataAdapterTest
+	{
+		[Test] // OdbcDataAdapter ()
+		public void Constructor1 ()
+		{
+			OdbcDataAdapter da = new OdbcDataAdapter ();
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNull (da.SelectCommand, "#11");
+			Assert.IsNull (da.Site, "#12");
+			Assert.IsNotNull (da.TableMappings, "#13");
+			Assert.AreEqual (0, da.TableMappings.Count, "#14");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#15");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#16");
+		}
+
+		[Test] // OdbcDataAdapter (OdbcCommand)
+		public void Constructor2 ()
+		{
+			OdbcCommand cmd = new OdbcCommand ();
+			OdbcDataAdapter da = new OdbcDataAdapter (cmd);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (cmd, da.SelectCommand, "#12");
+			Assert.IsNull (da.Site, "#13");
+			Assert.IsNotNull (da.TableMappings, "#14");
+			Assert.AreEqual (0, da.TableMappings.Count, "#15");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#16");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#17");
+		}
+
+		[Test] // OdbcDataAdapter (OdbcCommand)
+		public void Constructor2_SelectCommand_Null ()
+		{
+			OdbcDataAdapter da = new OdbcDataAdapter ((OdbcCommand) null);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNull (da.SelectCommand, "#11");
+			Assert.IsNull (da.Site, "#12");
+			Assert.IsNotNull (da.TableMappings, "#13");
+			Assert.AreEqual (0, da.TableMappings.Count, "#14");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#15");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#16");
+		}
+
+		[Test] // OdbcDataAdapter (string, OdbcCommand)
+		public void Constructor3 ()
+		{
+			string selectCommandText = "SELECT * FROM Authors";
+			OdbcConnection selectConnection = new OdbcConnection ();
+
+			OdbcDataAdapter da = new OdbcDataAdapter (selectCommandText,
+				selectConnection);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
+			Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#13");
+			Assert.IsNull (da.Site, "#14");
+			Assert.IsNotNull (da.TableMappings, "#15");
+			Assert.AreEqual (0, da.TableMappings.Count, "#16");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#17");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#18");
+		}
+
+		[Test] // OdbcDataAdapter (string, OdbcConnection)
+		public void Constructor3_SelectCommandText_Null ()
+		{
+			OdbcConnection selectConnection = new OdbcConnection ();
+
+			OdbcDataAdapter da = new OdbcDataAdapter ((string) null,
+				selectConnection);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
+			Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
+			Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#14");
+			Assert.IsNull (da.Site, "#15");
+			Assert.IsNotNull (da.TableMappings, "#16");
+			Assert.AreEqual (0, da.TableMappings.Count, "#17");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#18");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#19");
+		}
+
+		[Test] // OdbcDataAdapter (string, OdbcConnection)
+		public void Constructor3_SelectConnection_Null ()
+		{
+			string selectCommandText = "SELECT * FROM Authors";
+
+			OdbcDataAdapter da = new OdbcDataAdapter (selectCommandText,
+				(OdbcConnection) null);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
+			Assert.IsNull (da.SelectCommand.Connection, "#13");
+			Assert.IsNull (da.Site, "#14");
+			Assert.IsNotNull (da.TableMappings, "#15");
+			Assert.AreEqual (0, da.TableMappings.Count, "#16");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#17");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#18");
+		}
+
+		[Test] // OdbcDataAdapter (string, string)]
+		public void Constructor4 ()
+		{
+			string selectCommandText = "SELECT * FROM Authors";
+			string selectConnectionString = "Provider=SQLOLEDB;Data Source=SQLSRV;";
+
+			OdbcDataAdapter da = new OdbcDataAdapter (selectCommandText,
+				selectConnectionString);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
+			Assert.IsNotNull (da.SelectCommand.Connection, "#13");
+			Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#14");
+			Assert.IsNull (da.Site, "#15");
+			Assert.IsNotNull (da.TableMappings, "#16");
+			Assert.AreEqual (0, da.TableMappings.Count, "#17");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#18");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#19");
+		}
+
+		[Test] // OdbcDataAdapter (string, string)]
+		public void Constructor4_SelectCommandText_Null ()
+		{
+			string selectConnectionString = "Provider=SQLOLEDB;Data Source=SQLSRV;";
+
+			OdbcDataAdapter da = new OdbcDataAdapter ((string) null,
+				selectConnectionString);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
+			Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
+			Assert.IsNotNull (da.SelectCommand.Connection, "#14");
+			Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#15");
+			Assert.IsNull (da.Site, "#16");
+			Assert.IsNotNull (da.TableMappings, "#17");
+			Assert.AreEqual (0, da.TableMappings.Count, "#18");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#19");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#20");
+		}
+
+		[Test] // OdbcDataAdapter (string, string)]
+		public void Constructor4_SelectConnectionString_Null ()
+		{
+			string selectCommandText = "SELECT * FROM Authors";
+
+			OdbcDataAdapter da = new OdbcDataAdapter (selectCommandText,
+				(string) null);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
+			Assert.IsNotNull (da.SelectCommand.Connection, "#14");
+			Assert.AreEqual (string.Empty, da.SelectCommand.Connection.ConnectionString, "#15");
+			Assert.IsNull (da.Site, "#16");
+			Assert.IsNotNull (da.TableMappings, "#17");
+			Assert.AreEqual (0, da.TableMappings.Count, "#18");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#19");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#20");
+		}
+
+		[Test]
+		public void DeleteCommand ()
+		{
+			OdbcDataAdapter da = new OdbcDataAdapter ();
+			OdbcCommand cmd1 = new OdbcCommand ();
+			OdbcCommand cmd2 = new OdbcCommand ();
+
+			da.DeleteCommand = cmd1;
+			Assert.AreSame (cmd1, da.DeleteCommand, "#1");
+			da.DeleteCommand = cmd2;
+			Assert.AreSame (cmd2, da.DeleteCommand, "#2");
+			da.DeleteCommand = null;
+			Assert.IsNull (da.DeleteCommand, "#3");
+		}
+
+		[Test]
+		public void DeleteCommand_IDbDataAdapter ()
+		{
+			IDbDataAdapter da = new OdbcDataAdapter ();
+			OdbcCommand cmd1 = new OdbcCommand ();
+			OdbcCommand cmd2 = new OdbcCommand ();
+
+			da.DeleteCommand = cmd1;
+			Assert.AreSame (cmd1, da.DeleteCommand, "#A1");
+			da.DeleteCommand = cmd2;
+			Assert.AreSame (cmd2, da.DeleteCommand, "#A2");
+			da.DeleteCommand = null;
+			Assert.IsNull (da.DeleteCommand, "#A3");
+
+			try {
+				da.DeleteCommand = new OleDbCommand ();
+				Assert.Fail ("#B1");
+			} catch (InvalidCastException ex) {
+				Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+
+		[Test]
+		public void Dispose ()
+		{
+			OdbcDataAdapter da = new OdbcDataAdapter ();
+			da.DeleteCommand = new OdbcCommand ();
+			da.InsertCommand = new OdbcCommand ();
+			da.SelectCommand = new OdbcCommand ();
+			da.UpdateCommand = new OdbcCommand ();
+			da.Dispose ();
+
+			Assert.IsNull (da.DeleteCommand, "#1");
+			Assert.IsNull (da.InsertCommand, "#2");
+			Assert.IsNull (da.SelectCommand, "#3");
+			Assert.IsNotNull (da.TableMappings, "#4");
+			Assert.AreEqual (0, da.TableMappings.Count, "#5");
+			Assert.IsNull (da.UpdateCommand, "#6");
+		}
+
+		[Test]
+		public void InsertCommand ()
+		{
+			OdbcDataAdapter da = new OdbcDataAdapter ();
+			OdbcCommand cmd1 = new OdbcCommand ();
+			OdbcCommand cmd2 = new OdbcCommand ();
+
+			da.InsertCommand = cmd1;
+			Assert.AreSame (cmd1, da.InsertCommand, "#1");
+			da.InsertCommand = cmd2;
+			Assert.AreSame (cmd2, da.InsertCommand, "#2");
+			da.InsertCommand = null;
+			Assert.IsNull (da.InsertCommand, "#3");
+		}
+
+		[Test]
+		public void InsertCommand_IDbDataAdapter ()
+		{
+			IDbDataAdapter da = new OdbcDataAdapter ();
+			OdbcCommand cmd1 = new OdbcCommand ();
+			OdbcCommand cmd2 = new OdbcCommand ();
+
+			da.InsertCommand = cmd1;
+			Assert.AreSame (cmd1, da.InsertCommand, "#A1");
+			da.InsertCommand = cmd2;
+			Assert.AreSame (cmd2, da.InsertCommand, "#A2");
+			da.InsertCommand = null;
+			Assert.IsNull (da.InsertCommand, "#A3");
+
+			try {
+				da.InsertCommand = new OleDbCommand ();
+				Assert.Fail ("#B1");
+			} catch (InvalidCastException ex) {
+				Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+
+		[Test]
+		public void SelectCommand ()
+		{
+			OdbcDataAdapter da = new OdbcDataAdapter ();
+			OdbcCommand cmd1 = new OdbcCommand ();
+			OdbcCommand cmd2 = new OdbcCommand ();
+
+			da.SelectCommand = cmd1;
+			Assert.AreSame (cmd1, da.SelectCommand, "#1");
+			da.SelectCommand = cmd2;
+			Assert.AreSame (cmd2, da.SelectCommand, "#2");
+			da.SelectCommand = null;
+			Assert.IsNull (da.SelectCommand, "#3");
+		}
+
+		[Test]
+		public void SelectCommand_IDbDataAdapter ()
+		{
+			IDbDataAdapter da = new OdbcDataAdapter ();
+			OdbcCommand cmd1 = new OdbcCommand ();
+			OdbcCommand cmd2 = new OdbcCommand ();
+
+			da.SelectCommand = cmd1;
+			Assert.AreSame (cmd1, da.SelectCommand, "#A1");
+			da.SelectCommand = cmd2;
+			Assert.AreSame (cmd2, da.SelectCommand, "#A2");
+			da.SelectCommand = null;
+			Assert.IsNull (da.SelectCommand, "#A3");
+
+			try {
+				da.SelectCommand = new OleDbCommand ();
+				Assert.Fail ("#B1");
+			} catch (InvalidCastException ex) {
+				Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+
+		[Test]
+		public void UpdateCommand ()
+		{
+			OdbcDataAdapter da = new OdbcDataAdapter ();
+			OdbcCommand cmd1 = new OdbcCommand ();
+			OdbcCommand cmd2 = new OdbcCommand ();
+
+			da.UpdateCommand = cmd1;
+			Assert.AreSame (cmd1, da.UpdateCommand, "#1");
+			da.UpdateCommand = cmd2;
+			Assert.AreSame (cmd2, da.UpdateCommand, "#2");
+			da.UpdateCommand = null;
+			Assert.IsNull (da.UpdateCommand, "#3");
+		}
+
+		[Test]
+		public void UpdateCommand_IDbDataAdapter ()
+		{
+			IDbDataAdapter da = new OdbcDataAdapter ();
+			OdbcCommand cmd1 = new OdbcCommand ();
+			OdbcCommand cmd2 = new OdbcCommand ();
+
+			da.UpdateCommand = cmd1;
+			Assert.AreSame (cmd1, da.UpdateCommand, "#A1");
+			da.UpdateCommand = cmd2;
+			Assert.AreSame (cmd2, da.UpdateCommand, "#A2");
+			da.UpdateCommand = null;
+			Assert.IsNull (da.UpdateCommand, "#A3");
+
+			try {
+				da.UpdateCommand = new OleDbCommand ();
+				Assert.Fail ("#B1");
+			} catch (InvalidCastException ex) {
+				Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+	}
+}

+ 4 - 4
mcs/class/System.Data/Test/System.Data.Odbc/OdbcDataReaderTest.cs

@@ -30,7 +30,7 @@
 
 
 using System;
-using System.Text;
+using System.Text;
 using System.Data;
 using System.Data.Odbc;
 
@@ -271,7 +271,7 @@ namespace MonoTests.System.Data.Odbc
                 }
       }
 
-
+
 		
       [Test]
       public void NumericTest()
@@ -304,7 +304,7 @@ namespace MonoTests.System.Data.Odbc
 		dbCommand.ExecuteNonQuery();
 	   }	
      }
-
+
 
       /// <summary>
       /// This test for the return type &amp; value for GetValue
@@ -335,6 +335,6 @@ namespace MonoTests.System.Data.Odbc
                 }
       }
 
-
+
   }
 }

+ 9 - 0
mcs/class/System.Data/Test/System.Data.OleDb/ChangeLog

@@ -1,3 +1,12 @@
+2007-10-21  Gert Driesen  <[email protected]>
+
+	* OleDbDataAdapterTest.cs: Added tests for ctors, DeleteCommand,
+	InsertCommand, SelectCommand, UpdateCommand and Dispose.
+	* OleDbCommandTest.cs: Added tests for ctors and CommandText.
+	* OleDbConnectionTest.cs: Added tests for ctors and ConnectionString.
+	Added tests for BeginTransaction, GetSchema and ServerVersion with
+	connection that is closed.
+
 2007-02-22  Raja R Harinath  <[email protected]>
 
 	* OleDbParameterCollectionTest.cs: Fix compile error in 1.1 profile.

+ 195 - 0
mcs/class/System.Data/Test/System.Data.OleDb/OleDbCommandTest.cs

@@ -0,0 +1,195 @@
+//
+// OleDbCommandTest.cs - NUnit Test Cases for testing
+// System.Data.OleDb.OleDbCommand
+// 
+// Author:
+// 	Gert Driesen ([email protected])
+//
+// Copyright (c) 2007 Gert Driesen
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.Data;
+using System.Data.OleDb;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Data.OleDb
+{
+	[TestFixture]
+	public class OleDbCommandTest
+	{
+		const string COMMAND_TEXT = "SELECT * FROM Authors";
+
+		[Test] // OleDbCommand ()
+		public void Constructor1 ()
+		{
+			OleDbCommand cmd = new OleDbCommand ();
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#3");
+			Assert.IsNull (cmd.Connection, "#4");
+			Assert.IsNull (cmd.Container, "#5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#6");
+			Assert.IsNotNull (cmd.Parameters, "#7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#8");
+			Assert.IsNull (cmd.Site, "#9");
+			Assert.IsNull (cmd.Transaction, "#10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#11");
+		}
+
+		[Test] // OleDbCommand (string)
+		public void Constructor2 ()
+		{
+			OleDbCommand cmd = new OleDbCommand (COMMAND_TEXT);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
+			Assert.IsNull (cmd.Connection, "#A4");
+			Assert.IsNull (cmd.Container, "#A5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
+			Assert.IsNotNull (cmd.Parameters, "#A7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#A8");
+			Assert.IsNull (cmd.Site, "#A9");
+			Assert.IsNull (cmd.Transaction, "#A10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A11");
+
+			cmd = new OleDbCommand ((string) null);
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
+			Assert.IsNull (cmd.Connection, "#B4");
+			Assert.IsNull (cmd.Container, "#B5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
+			Assert.IsNotNull (cmd.Parameters, "#B7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#B8");
+			Assert.IsNull (cmd.Site, "#B9");
+			Assert.IsNull (cmd.Transaction, "#B10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B11");
+		}
+
+		[Test] // OleDbCommand (string, OleDbConnection)
+		public void Constructor3 ()
+		{
+			OleDbConnection conn = new OleDbConnection ();
+			OleDbCommand cmd;
+
+			cmd = new OleDbCommand (COMMAND_TEXT, conn);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
+			Assert.AreSame (conn, cmd.Connection, "#A4");
+			Assert.IsNull (cmd.Container, "#A5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
+			Assert.IsNotNull (cmd.Parameters, "#A7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#A8");
+			Assert.IsNull (cmd.Site, "#A9");
+			Assert.IsNull (cmd.Transaction, "#A10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A11");
+
+			cmd = new OleDbCommand ((string) null, conn);
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
+			Assert.AreSame (conn, cmd.Connection, "#B4");
+			Assert.IsNull (cmd.Container, "#B5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
+			Assert.IsNotNull (cmd.Parameters, "#B7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#B8");
+			Assert.IsNull (cmd.Site, "#B9");
+			Assert.IsNull (cmd.Transaction, "#B10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B11");
+
+			cmd = new OleDbCommand (COMMAND_TEXT, (OleDbConnection) null);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#C2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
+			Assert.IsNull (cmd.Connection, "#C4");
+			Assert.IsNull (cmd.Container, "#C5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
+			Assert.IsNotNull (cmd.Parameters, "#C7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#C8");
+			Assert.IsNull (cmd.Site, "#C9");
+			Assert.IsNull (cmd.Transaction, "#C10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C11");
+		}
+
+		[Test] // OleDbCommand (string, OleDbConnection, OleDbTransaction)
+		public void Constructor4 ()
+		{
+			OleDbConnection conn = new OleDbConnection ();
+			OleDbCommand cmd;
+
+			cmd = new OleDbCommand (COMMAND_TEXT, conn, (OleDbTransaction) null);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
+			Assert.AreSame (conn, cmd.Connection, "#A4");
+			Assert.IsNull (cmd.Container, "#A5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
+			Assert.IsNotNull (cmd.Parameters, "#A7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#A8");
+			Assert.IsNull (cmd.Site, "#A9");
+			Assert.IsNull (cmd.Transaction, "#A10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A11");
+
+			cmd = new OleDbCommand ((string) null, conn, (OleDbTransaction) null);
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
+			Assert.AreSame (conn, cmd.Connection, "#B4");
+			Assert.IsNull (cmd.Container, "#B5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
+			Assert.IsNotNull (cmd.Parameters, "#B7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#B8");
+			Assert.IsNull (cmd.Site, "#B9");
+			Assert.IsNull (cmd.Transaction, "#B10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B11");
+
+			cmd = new OleDbCommand (COMMAND_TEXT, (OleDbConnection) null, (OleDbTransaction) null);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#C2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
+			Assert.IsNull (cmd.Connection, "#C4");
+			Assert.IsNull (cmd.Container, "#C5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
+			Assert.IsNotNull (cmd.Parameters, "#C7");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#C8");
+			Assert.IsNull (cmd.Site, "#C9");
+			Assert.IsNull (cmd.Transaction, "#C10");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C11");
+		}
+
+		[Test]
+		public void CommandText ()
+		{
+			OleDbCommand cmd = new OleDbCommand ();
+			cmd.CommandText = COMMAND_TEXT;
+			Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#1");
+			cmd.CommandText = null;
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#2");
+			cmd.CommandText = COMMAND_TEXT;
+			Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#3");
+			cmd.CommandText = string.Empty;
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#4");
+		}
+	}
+}

+ 233 - 0
mcs/class/System.Data/Test/System.Data.OleDb/OleDbConnectionTest.cs

@@ -0,0 +1,233 @@
+//
+// OleDbConnectionTest.cs - NUnit Test Cases for testing the
+//                          OleDbConnectionTest class
+// Author:
+//      Gert Driesen ([email protected])
+//
+// Copyright (c) 2007 Gert Driesen
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Data;
+using System.Data.OleDb;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Data.OleDb
+{
+	[TestFixture]
+	public class OleDbConnectionTest
+	{
+		const string CONNECTION_STRING = "Provider=sqloledb;Data Source=SQLSRV;Initial Catalog=Mono;";
+
+		[Test] // OleDbConnection ()
+		public void Constructor1 ()
+		{
+			OleDbConnection cn = new OleDbConnection ();
+
+			Assert.AreEqual (string.Empty, cn.ConnectionString, "#1");
+			Assert.AreEqual (15, cn.ConnectionTimeout, "#2");
+			Assert.IsNull (cn.Container, "#3");
+			Assert.AreEqual (string.Empty, cn.Database, "#4");
+			Assert.AreEqual (string.Empty, cn.DataSource, "#5");
+			Assert.AreEqual (string.Empty, cn.Provider, "#6");
+			Assert.IsNull (cn.Site, "#7");
+			Assert.AreEqual (ConnectionState.Closed, cn.State, "#8");
+		}
+
+		[Test] // OleDbConnection (string)
+		public void Constructor2 ()
+		{
+			OleDbConnection cn = new OleDbConnection (CONNECTION_STRING);
+			Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#A1");
+			Assert.AreEqual (15, cn.ConnectionTimeout, "#A2");
+			Assert.IsNull (cn.Container, "#A3");
+			//Assert.AreEqual ("Mono", cn.Database, "#A4");
+			//Assert.AreEqual ("SQLSRV", cn.DataSource, "#A5");
+			//Assert.AreEqual ("sqloledb", cn.Provider, "#A6");
+			Assert.IsNull (cn.Site, "#A7");
+			Assert.AreEqual (ConnectionState.Closed, cn.State, "#A8");
+
+			cn = new OleDbConnection ((string) null);
+			Assert.AreEqual (string.Empty, cn.ConnectionString, "#B1");
+			Assert.AreEqual (15, cn.ConnectionTimeout, "#B2");
+			Assert.IsNull (cn.Container, "#B3");
+			Assert.AreEqual (string.Empty, cn.Database, "#B4");
+			Assert.AreEqual (string.Empty, cn.DataSource, "#B5");
+			Assert.AreEqual (string.Empty, cn.Provider, "#B6");
+			Assert.IsNull (cn.Site, "#B7");
+			Assert.AreEqual (ConnectionState.Closed, cn.State, "#B8");
+		}
+
+		[Test]
+		public void BeginTransaction_Connection_Closed ()
+		{
+			OleDbConnection cn = new OleDbConnection ();
+
+			try {
+				cn.BeginTransaction ();
+				Assert.Fail ("#A1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
+				Assert.IsNull (ex.InnerException, "#A3");
+				Assert.IsNotNull (ex.Message, "#A4");
+			}
+
+			try {
+				cn.BeginTransaction ((IsolationLevel) 666);
+				Assert.Fail ("#B1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+
+			try {
+				cn.BeginTransaction (IsolationLevel.Serializable);
+				Assert.Fail ("#C1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
+				Assert.IsNull (ex.InnerException, "#C3");
+				Assert.IsNotNull (ex.Message, "#C4");
+			}
+		}
+
+		[Test]
+		public void ConnectionString ()
+		{
+			OleDbConnection cn = new OleDbConnection ();
+			cn.ConnectionString = CONNECTION_STRING;
+			Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#1");
+			cn.ConnectionString = null;
+			Assert.AreEqual (string.Empty, cn.ConnectionString, "#2");
+			cn.ConnectionString = CONNECTION_STRING;
+			Assert.AreEqual (CONNECTION_STRING, cn.ConnectionString, "#3");
+			cn.ConnectionString = string.Empty;
+			Assert.AreEqual (string.Empty, cn.ConnectionString, "#4");
+		}
+
+#if NET_2_0
+		[Test]
+		public void GetSchema_Connection_Closed ()
+		{
+			OleDbConnection cn = new OleDbConnection ();
+
+			try {
+				cn.GetSchema ();
+				Assert.Fail ("#A1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+
+			try {
+				cn.GetSchema ("Tables");
+				Assert.Fail ("#B1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+
+			try {
+				cn.GetSchema ((string) null);
+				Assert.Fail ("#C1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
+				Assert.IsNull (ex.InnerException, "#C3");
+				Assert.IsNotNull (ex.Message, "#C4");
+			}
+
+			try {
+				cn.GetSchema ("Tables", new string [] { "master" });
+				Assert.Fail ("#D1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
+				Assert.IsNull (ex.InnerException, "#D3");
+				Assert.IsNotNull (ex.Message, "#D4");
+			}
+
+			try {
+				cn.GetSchema ((string) null, new string [] { "master" });
+				Assert.Fail ("#E1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
+				Assert.IsNull (ex.InnerException, "#E3");
+				Assert.IsNotNull (ex.Message, "#E4");
+			}
+
+			try {
+				cn.GetSchema ("Tables", (string []) null);
+				Assert.Fail ("#F1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
+				Assert.IsNull (ex.InnerException, "#F3");
+				Assert.IsNotNull (ex.Message, "#F4");
+			}
+
+			try {
+				cn.GetSchema ((string) null, (string []) null);
+				Assert.Fail ("#G1");
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#G2");
+				Assert.IsNull (ex.InnerException, "#G3");
+				Assert.IsNotNull (ex.Message, "#G4");
+			}
+		}
+#endif
+
+		[Test]
+		public void ServerVersion_Connection_Closed ()
+		{
+			OleDbConnection cn = new OleDbConnection ();
+			try {
+				Assert.Fail ("#A1:" + cn.ServerVersion);
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
+				Assert.IsNull (ex.InnerException, "#A3");
+				Assert.IsNotNull (ex.Message, "#A4");
+			}
+
+			cn = new OleDbConnection (CONNECTION_STRING);
+			try {
+				Assert.Fail ("#B1:" + cn.ServerVersion);
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+	}
+}

+ 524 - 0
mcs/class/System.Data/Test/System.Data.OleDb/OleDbDataAdapterTest.cs

@@ -0,0 +1,524 @@
+//
+// OleDbDataAdapterTest.cs - NUnit Test Cases for testing the
+//                        OleDbDataAdapter class
+// Author:
+//      Gert Driesen ([email protected])
+//
+// Copyright (c) 2007 Gert Driesen
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Data;
+using System.Data.Odbc;
+using System.Data.OleDb;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Data.OleDb
+{
+	[TestFixture]
+	public class OleDbDataAdapterTest
+	{
+		[Test] // OleDbDataAdapter ()
+		public void Constructor1 ()
+		{
+			OleDbDataAdapter da = new OleDbDataAdapter ();
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNull (da.SelectCommand, "#11");
+			Assert.IsNull (da.Site, "#12");
+			Assert.IsNotNull (da.TableMappings, "#13");
+			Assert.AreEqual (0, da.TableMappings.Count, "#14");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#15");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#16");
+		}
+
+		[Test] // OleDbDataAdapter (OleDbCommand)
+		public void Constructor2 ()
+		{
+			OleDbCommand cmd = new OleDbCommand ();
+			OleDbDataAdapter da = new OleDbDataAdapter (cmd);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (cmd, da.SelectCommand, "#12");
+			Assert.IsNull (da.Site, "#13");
+			Assert.IsNotNull (da.TableMappings, "#14");
+			Assert.AreEqual (0, da.TableMappings.Count, "#15");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#16");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#17");
+		}
+
+		[Test] // OleDbDataAdapter (OleDbCommand)
+		public void Constructor2_SelectCommand_Null ()
+		{
+			OleDbDataAdapter da = new OleDbDataAdapter ((OleDbCommand) null);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNull (da.SelectCommand, "#11");
+			Assert.IsNull (da.Site, "#12");
+			Assert.IsNotNull (da.TableMappings, "#13");
+			Assert.AreEqual (0, da.TableMappings.Count, "#14");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#15");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#16");
+		}
+
+		[Test] // OleDbDataAdapter (string, OleDbCommand)
+		public void Constructor3 ()
+		{
+			string selectCommandText = "SELECT * FROM Authors";
+			OleDbConnection selectConnection = new OleDbConnection ();
+
+			OleDbDataAdapter da = new OleDbDataAdapter (selectCommandText,
+				selectConnection);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
+			Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#13");
+			Assert.IsNull (da.Site, "#14");
+			Assert.IsNotNull (da.TableMappings, "#15");
+			Assert.AreEqual (0, da.TableMappings.Count, "#16");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#17");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#18");
+		}
+
+		[Test] // OleDbDataAdapter (string, OleDbConnection)
+		public void Constructor3_SelectCommandText_Null ()
+		{
+			OleDbConnection selectConnection = new OleDbConnection ();
+
+			OleDbDataAdapter da = new OleDbDataAdapter ((string) null,
+				selectConnection);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
+			Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
+			Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#14");
+			Assert.IsNull (da.Site, "#15");
+			Assert.IsNotNull (da.TableMappings, "#16");
+			Assert.AreEqual (0, da.TableMappings.Count, "#17");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#18");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#19");
+		}
+
+		[Test] // OleDbDataAdapter (string, OleDbConnection)
+		public void Constructor3_SelectConnection_Null ()
+		{
+			string selectCommandText = "SELECT * FROM Authors";
+
+			OleDbDataAdapter da = new OleDbDataAdapter (selectCommandText,
+				(OleDbConnection) null);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
+			Assert.IsNull (da.SelectCommand.Connection, "#13");
+			Assert.IsNull (da.Site, "#14");
+			Assert.IsNotNull (da.TableMappings, "#15");
+			Assert.AreEqual (0, da.TableMappings.Count, "#16");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#17");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#18");
+		}
+
+		[Test] // OleDbDataAdapter (string, string)]
+		public void Constructor4 ()
+		{
+			string selectCommandText = "SELECT * FROM Authors";
+			string selectConnectionString = "Provider=SQLOLEDB;Data Source=SQLSRV;";
+
+			OleDbDataAdapter da = new OleDbDataAdapter (selectCommandText,
+				selectConnectionString);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
+			Assert.IsNotNull (da.SelectCommand.Connection, "#13");
+			Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#14");
+			Assert.IsNull (da.Site, "#15");
+			Assert.IsNotNull (da.TableMappings, "#16");
+			Assert.AreEqual (0, da.TableMappings.Count, "#17");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#18");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#19");
+		}
+
+		[Test] // OleDbDataAdapter (string, string)]
+		public void Constructor4_SelectCommandText_Null ()
+		{
+			string selectConnectionString = "Provider=SQLOLEDB;Data Source=SQLSRV;";
+
+			OleDbDataAdapter da = new OleDbDataAdapter ((string) null,
+				selectConnectionString);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
+			Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
+			Assert.IsNotNull (da.SelectCommand.Connection, "#14");
+			Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#15");
+			Assert.IsNull (da.Site, "#16");
+			Assert.IsNotNull (da.TableMappings, "#17");
+			Assert.AreEqual (0, da.TableMappings.Count, "#18");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#19");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#20");
+		}
+
+		[Test] // OleDbDataAdapter (string, string)]
+		public void Constructor4_SelectConnectionString_Null ()
+		{
+			string selectCommandText = "SELECT * FROM Authors";
+
+			OleDbDataAdapter da = new OleDbDataAdapter (selectCommandText,
+				(string) null);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
+			Assert.IsNotNull (da.SelectCommand.Connection, "#14");
+			Assert.AreEqual (string.Empty, da.SelectCommand.Connection.ConnectionString, "#15");
+			Assert.IsNull (da.Site, "#16");
+			Assert.IsNotNull (da.TableMappings, "#17");
+			Assert.AreEqual (0, da.TableMappings.Count, "#18");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#19");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#20");
+		}
+
+		[Test]
+		public void DeleteCommand ()
+		{
+			OleDbDataAdapter da = new OleDbDataAdapter ();
+			OleDbCommand cmd1 = new OleDbCommand ();
+			OleDbCommand cmd2 = new OleDbCommand ();
+
+			da.DeleteCommand = cmd1;
+			Assert.AreSame (cmd1, da.DeleteCommand, "#1");
+			da.DeleteCommand = cmd2;
+			Assert.AreSame (cmd2, da.DeleteCommand, "#2");
+			da.DeleteCommand = null;
+			Assert.IsNull (da.DeleteCommand, "#3");
+		}
+
+		[Test]
+		public void DeleteCommand_IDbDataAdapter ()
+		{
+			IDbDataAdapter da = new OleDbDataAdapter ();
+			OleDbCommand cmd1 = new OleDbCommand ();
+			OleDbCommand cmd2 = new OleDbCommand ();
+
+			da.DeleteCommand = cmd1;
+			Assert.AreSame (cmd1, da.DeleteCommand, "#A1");
+			da.DeleteCommand = cmd2;
+			Assert.AreSame (cmd2, da.DeleteCommand, "#A2");
+			da.DeleteCommand = null;
+			Assert.IsNull (da.DeleteCommand, "#A3");
+
+			try {
+				da.DeleteCommand = new OdbcCommand ();
+				Assert.Fail ("#B1");
+			} catch (InvalidCastException ex) {
+				Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+
+		[Test]
+		public void Dispose ()
+		{
+			OleDbDataAdapter da = new OleDbDataAdapter ();
+			da.DeleteCommand = new OleDbCommand ();
+			da.InsertCommand = new OleDbCommand ();
+			da.SelectCommand = new OleDbCommand ();
+			da.UpdateCommand = new OleDbCommand ();
+			da.Dispose ();
+
+			Assert.IsNull (da.DeleteCommand, "#1");
+			Assert.IsNull (da.InsertCommand, "#2");
+			Assert.IsNull (da.SelectCommand, "#3");
+			Assert.IsNotNull (da.TableMappings, "#4");
+			Assert.AreEqual (0, da.TableMappings.Count, "#5");
+			Assert.IsNull (da.UpdateCommand, "#6");
+		}
+
+		[Test]
+		public void InsertCommand ()
+		{
+			OleDbDataAdapter da = new OleDbDataAdapter ();
+			OleDbCommand cmd1 = new OleDbCommand ();
+			OleDbCommand cmd2 = new OleDbCommand ();
+
+			da.InsertCommand = cmd1;
+			Assert.AreSame (cmd1, da.InsertCommand, "#1");
+			da.InsertCommand = cmd2;
+			Assert.AreSame (cmd2, da.InsertCommand, "#2");
+			da.InsertCommand = null;
+			Assert.IsNull (da.InsertCommand, "#3");
+		}
+
+		[Test]
+		public void InsertCommand_IDbDataAdapter ()
+		{
+			IDbDataAdapter da = new OleDbDataAdapter ();
+			OleDbCommand cmd1 = new OleDbCommand ();
+			OleDbCommand cmd2 = new OleDbCommand ();
+
+			da.InsertCommand = cmd1;
+			Assert.AreSame (cmd1, da.InsertCommand, "#A1");
+			da.InsertCommand = cmd2;
+			Assert.AreSame (cmd2, da.InsertCommand, "#A2");
+			da.InsertCommand = null;
+			Assert.IsNull (da.InsertCommand, "#A3");
+
+			try {
+				da.InsertCommand = new OdbcCommand ();
+				Assert.Fail ("#B1");
+			} catch (InvalidCastException ex) {
+				Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+
+		[Test]
+		public void SelectCommand ()
+		{
+			OleDbDataAdapter da = new OleDbDataAdapter ();
+			OleDbCommand cmd1 = new OleDbCommand ();
+			OleDbCommand cmd2 = new OleDbCommand ();
+
+			da.SelectCommand = cmd1;
+			Assert.AreSame (cmd1, da.SelectCommand, "#1");
+			da.SelectCommand = cmd2;
+			Assert.AreSame (cmd2, da.SelectCommand, "#2");
+			da.SelectCommand = null;
+			Assert.IsNull (da.SelectCommand, "#3");
+		}
+
+		[Test]
+		public void SelectCommand_IDbDataAdapter ()
+		{
+			IDbDataAdapter da = new OleDbDataAdapter ();
+			OleDbCommand cmd1 = new OleDbCommand ();
+			OleDbCommand cmd2 = new OleDbCommand ();
+
+			da.SelectCommand = cmd1;
+			Assert.AreSame (cmd1, da.SelectCommand, "#A1");
+			da.SelectCommand = cmd2;
+			Assert.AreSame (cmd2, da.SelectCommand, "#A2");
+			da.SelectCommand = null;
+			Assert.IsNull (da.SelectCommand, "#A3");
+
+			try {
+				da.SelectCommand = new OdbcCommand ();
+				Assert.Fail ("#B1");
+			} catch (InvalidCastException ex) {
+				Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+
+		[Test]
+		public void UpdateCommand ()
+		{
+			OleDbDataAdapter da = new OleDbDataAdapter ();
+			OleDbCommand cmd1 = new OleDbCommand ();
+			OleDbCommand cmd2 = new OleDbCommand ();
+
+			da.UpdateCommand = cmd1;
+			Assert.AreSame (cmd1, da.UpdateCommand, "#1");
+			da.UpdateCommand = cmd2;
+			Assert.AreSame (cmd2, da.UpdateCommand, "#2");
+			da.UpdateCommand = null;
+			Assert.IsNull (da.UpdateCommand, "#3");
+		}
+
+		[Test]
+		public void UpdateCommand_IDbDataAdapter ()
+		{
+			IDbDataAdapter da = new OleDbDataAdapter ();
+			OleDbCommand cmd1 = new OleDbCommand ();
+			OleDbCommand cmd2 = new OleDbCommand ();
+
+			da.UpdateCommand = cmd1;
+			Assert.AreSame (cmd1, da.UpdateCommand, "#A1");
+			da.UpdateCommand = cmd2;
+			Assert.AreSame (cmd2, da.UpdateCommand, "#A2");
+			da.UpdateCommand = null;
+			Assert.IsNull (da.UpdateCommand, "#A3");
+
+			try {
+				da.UpdateCommand = new OdbcCommand ();
+				Assert.Fail ("#B1");
+			} catch (InvalidCastException ex) {
+				Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+	}
+}

+ 9 - 0
mcs/class/System.Data/Test/System.Data.SqlClient/ChangeLog

@@ -1,3 +1,12 @@
+2007-10-21  Gert Driesen  <[email protected]>
+
+	* SqlCommandTest.cs: Added tests for ctors and CommantText.
+	* SqlConnectionTest.cs: Added tests for ctors, ConnectionString and
+	ServerVersion.
+	* SqlDataAdapterTest.cs: Added tests for ctors, DeleteCommand,
+	InsertCommand, SelectCommand, UpdateCommand, UpdateBatchSize and
+	Dispose.
+
 2007-10-18  Gert Driesen  <[email protected]>
 
 	* SqlConnectionTest.cs: Added tests for BeginTransaction and GetSchema

+ 192 - 0
mcs/class/System.Data/Test/System.Data.SqlClient/SqlCommandTest.cs

@@ -27,6 +27,7 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Data;
 using System.Data.SqlClient;
 
 using NUnit.Framework;
@@ -36,6 +37,183 @@ namespace MonoTests.System.Data.SqlClient
 	[TestFixture]
 	public class SqlCommandTest
 	{
+		const string COMMAND_TEXT = "SELECT * FROM Authors";
+
+		[Test] // SqlCommand ()
+		public void Constructor1 ()
+		{
+			SqlCommand cmd = new SqlCommand ();
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#3");
+			Assert.IsNull (cmd.Connection, "#4");
+			Assert.IsNull (cmd.Container, "#5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#6");
+#if NET_2_0
+			Assert.IsNull (cmd.Notification, "#7");
+			Assert.IsTrue (cmd.NotificationAutoEnlist, "#8");
+#endif
+			Assert.IsNotNull (cmd.Parameters, "#9");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#10");
+			Assert.IsNull (cmd.Site, "#11");
+			Assert.IsNull (cmd.Transaction, "#11");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#12");
+		}
+
+		[Test] // SqlCommand (string)
+		public void Constructor2 ()
+		{
+			SqlCommand cmd = new SqlCommand (COMMAND_TEXT);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
+			Assert.IsNull (cmd.Connection, "#A4");
+			Assert.IsNull (cmd.Container, "#A5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
+#if NET_2_0
+			Assert.IsNull (cmd.Notification, "#A7");
+			Assert.IsTrue (cmd.NotificationAutoEnlist, "#A8");
+#endif
+			Assert.IsNotNull (cmd.Parameters, "#A9");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#A10");
+			Assert.IsNull (cmd.Site, "#A11");
+			Assert.IsNull (cmd.Transaction, "#A12");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A13");
+
+			cmd = new SqlCommand ((string) null);
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
+			Assert.IsNull (cmd.Connection, "#B4");
+			Assert.IsNull (cmd.Container, "#B5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
+#if NET_2_0
+			Assert.IsNull (cmd.Notification, "#B7");
+			Assert.IsTrue (cmd.NotificationAutoEnlist, "#B8");
+#endif
+			Assert.IsNotNull (cmd.Parameters, "#B9");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#B10");
+			Assert.IsNull (cmd.Site, "#B11");
+			Assert.IsNull (cmd.Transaction, "#B12");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B13");
+		}
+
+		[Test] // SqlCommand (string, SqlConnection)
+		public void Constructor3 ()
+		{
+			SqlConnection conn = new SqlConnection ();
+			SqlCommand cmd;
+
+			cmd = new SqlCommand (COMMAND_TEXT, conn);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
+			Assert.AreSame (conn, cmd.Connection, "#A4");
+			Assert.IsNull (cmd.Container, "#A5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
+#if NET_2_0
+			Assert.IsNull (cmd.Notification, "#A7");
+			Assert.IsTrue (cmd.NotificationAutoEnlist, "#A8");
+#endif
+			Assert.IsNotNull (cmd.Parameters, "#A9");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#A10");
+			Assert.IsNull (cmd.Site, "#A11");
+			Assert.IsNull (cmd.Transaction, "#A12");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A13");
+
+			cmd = new SqlCommand ((string) null, conn);
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
+			Assert.AreSame (conn, cmd.Connection, "#B4");
+			Assert.IsNull (cmd.Container, "#B5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
+#if NET_2_0
+			Assert.IsNull (cmd.Notification, "#B7");
+			Assert.IsTrue (cmd.NotificationAutoEnlist, "#B8");
+#endif
+			Assert.IsNotNull (cmd.Parameters, "#B9");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#B10");
+			Assert.IsNull (cmd.Site, "#B11");
+			Assert.IsNull (cmd.Transaction, "#B12");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B13");
+
+			cmd = new SqlCommand (COMMAND_TEXT, (SqlConnection) null);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#C2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
+			Assert.IsNull (cmd.Connection, "#C4");
+			Assert.IsNull (cmd.Container, "#C5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
+#if NET_2_0
+			Assert.IsNull (cmd.Notification, "#C7");
+			Assert.IsTrue (cmd.NotificationAutoEnlist, "#C8");
+#endif
+			Assert.IsNotNull (cmd.Parameters, "#C9");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#C10");
+			Assert.IsNull (cmd.Site, "#C11");
+			Assert.IsNull (cmd.Transaction, "#C12");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C13");
+		}
+
+		[Test] // SqlCommand (string, SqlConnection, SqlTransaction)
+		public void Constructor4 ()
+		{
+			SqlConnection conn = new SqlConnection ();
+			SqlCommand cmd;
+
+			cmd = new SqlCommand (COMMAND_TEXT, conn, (SqlTransaction) null);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#A1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#A2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#A3");
+			Assert.AreSame (conn, cmd.Connection, "#A4");
+			Assert.IsNull (cmd.Container, "#A5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#A6");
+#if NET_2_0
+			Assert.IsNull (cmd.Notification, "#A7");
+			Assert.IsTrue (cmd.NotificationAutoEnlist, "#A8");
+#endif
+			Assert.IsNotNull (cmd.Parameters, "#A9");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#A10");
+			Assert.IsNull (cmd.Site, "#A11");
+			Assert.IsNull (cmd.Transaction, "#A12");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#A13");
+
+			cmd = new SqlCommand ((string) null, conn, (SqlTransaction) null);
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#B1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#B2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#B3");
+			Assert.AreSame (conn, cmd.Connection, "#B4");
+			Assert.IsNull (cmd.Container, "#B5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#B6");
+#if NET_2_0
+			Assert.IsNull (cmd.Notification, "#B7");
+			Assert.IsTrue (cmd.NotificationAutoEnlist, "#B8");
+#endif
+			Assert.IsNotNull (cmd.Parameters, "#B9");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#B10");
+			Assert.IsNull (cmd.Site, "#B11");
+			Assert.IsNull (cmd.Transaction, "#B12");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#B13");
+
+			cmd = new SqlCommand (COMMAND_TEXT, (SqlConnection) null, (SqlTransaction) null);
+			Assert.AreEqual (COMMAND_TEXT, cmd.CommandText, "#C1");
+			Assert.AreEqual (30, cmd.CommandTimeout, "#C2");
+			Assert.AreEqual (CommandType.Text, cmd.CommandType, "#C3");
+			Assert.IsNull (cmd.Connection, "#C4");
+			Assert.IsNull (cmd.Container, "#C5");
+			Assert.IsTrue (cmd.DesignTimeVisible, "#C6");
+#if NET_2_0
+			Assert.IsNull (cmd.Notification, "#C7");
+			Assert.IsTrue (cmd.NotificationAutoEnlist, "#C8");
+#endif
+			Assert.IsNotNull (cmd.Parameters, "#C9");
+			Assert.AreEqual (0, cmd.Parameters.Count, "#C10");
+			Assert.IsNull (cmd.Site, "#C11");
+			Assert.IsNull (cmd.Transaction, "#C12");
+			Assert.AreEqual (UpdateRowSource.Both, cmd.UpdatedRowSource, "#C13");
+		}
+
 		[Test] // bug #81710
 		public void Dispose ()
 		{
@@ -46,5 +224,19 @@ namespace MonoTests.System.Data.SqlClient
 			command.Dispose ();
 			Assert.AreEqual (connectionString, connection.ConnectionString);
 		}
+
+		[Test]
+		public void CommandText ()
+		{
+			SqlCommand cmd = new SqlCommand ();
+			cmd.CommandText = COMMAND_TEXT;
+			Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#1");
+			cmd.CommandText = null;
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#2");
+			cmd.CommandText = COMMAND_TEXT;
+			Assert.AreSame (COMMAND_TEXT, cmd.CommandText, "#3");
+			cmd.CommandText = string.Empty;
+			Assert.AreEqual (string.Empty, cmd.CommandText, "#4");
+		}
 	}
 }

+ 101 - 12
mcs/class/System.Data/Test/System.Data.SqlClient/SqlConnectionTest.cs

@@ -38,21 +38,72 @@ namespace MonoTests.System.Data.SqlClient
 	[TestFixture]
 	public class SqlConnectionTest
 	{
-		[Test]
-		public void DefaultConnectionValues()
+		[Test] // SqlConnection ()
+		public void Constructor1 ()
 		{
 			SqlConnection cn = new SqlConnection ();
 
-			Assert.AreEqual (15, cn.ConnectionTimeout, 
-				"Default connection timeout should be 15 seconds");
-			Assert.AreEqual (string.Empty, cn.Database, 
-				"Default database name should be empty string");
-			Assert.AreEqual (string.Empty, cn.DataSource,
-				"Default data source should be empty string");
-			Assert.AreEqual (8192, cn.PacketSize,
-				"Default packet size should be 8192 bytes");
-			Assert.AreEqual (ConnectionState.Closed, cn.State,
-				"Default connection state should be closed");
+			Assert.AreEqual (string.Empty, cn.ConnectionString, "#1");
+			Assert.AreEqual (15, cn.ConnectionTimeout, "#2");
+			Assert.IsNull (cn.Container, "#3");
+			Assert.AreEqual (string.Empty, cn.Database, "#4");
+			Assert.AreEqual (string.Empty, cn.DataSource, "#5");
+#if NET_2_0
+			Assert.IsFalse (cn.FireInfoMessageEventOnUserErrors, "#6");
+			Assert.AreEqual (8000, cn.PacketSize, "#7");
+#else
+			Assert.AreEqual (8192, cn.PacketSize, "#7");
+#endif
+			Assert.IsNull (cn.Site, "#8");
+			Assert.AreEqual (ConnectionState.Closed, cn.State, "#9");
+#if NET_2_0
+			Assert.IsFalse (cn.StatisticsEnabled, "#10");
+#endif
+			Assert.AreEqual (Environment.MachineName, cn.WorkstationId, "#11");
+		}
+
+		[Test] // SqlConnection (string)
+		public void Constructor2 ()
+		{
+			string connectionString = "server=SQLSRV; database=Mono;";
+
+			SqlConnection cn = new SqlConnection (connectionString);
+			Assert.AreEqual (connectionString, cn.ConnectionString, "#A1");
+			Assert.AreEqual (15, cn.ConnectionTimeout, "#A2");
+			Assert.IsNull (cn.Container, "#A3");
+			Assert.AreEqual ("Mono", cn.Database, "#A4");
+			Assert.AreEqual ("SQLSRV", cn.DataSource, "#A5");
+#if NET_2_0
+			Assert.IsFalse (cn.FireInfoMessageEventOnUserErrors, "#A6");
+			Assert.AreEqual (8000, cn.PacketSize, "#A7");
+#else
+			Assert.AreEqual (8192, cn.PacketSize, "#A7");
+#endif
+			Assert.IsNull (cn.Site, "#A8");
+			Assert.AreEqual (ConnectionState.Closed, cn.State, "#A9");
+#if NET_2_0
+			Assert.IsFalse (cn.StatisticsEnabled, "#A10");
+#endif
+			Assert.AreEqual (Environment.MachineName, cn.WorkstationId, "#A11");
+
+			cn = new SqlConnection ((string) null);
+			Assert.AreEqual (string.Empty, cn.ConnectionString, "#B1");
+			Assert.AreEqual (15, cn.ConnectionTimeout, "#B2");
+			Assert.IsNull (cn.Container, "#B3");
+			Assert.AreEqual (string.Empty, cn.Database, "#B4");
+			Assert.AreEqual (string.Empty, cn.DataSource, "#B5");
+#if NET_2_0
+			Assert.IsFalse (cn.FireInfoMessageEventOnUserErrors, "#B6");
+			Assert.AreEqual (8000, cn.PacketSize, "#B7");
+#else
+			Assert.AreEqual (8192, cn.PacketSize, "#B7");
+#endif
+			Assert.IsNull (cn.Site, "#B8");
+			Assert.AreEqual (ConnectionState.Closed, cn.State, "#B9");
+#if NET_2_0
+			Assert.IsFalse (cn.StatisticsEnabled, "#B10");
+#endif
+			Assert.AreEqual (Environment.MachineName, cn.WorkstationId, "#B11");
 		}
 
 		[Test]
@@ -121,6 +172,20 @@ namespace MonoTests.System.Data.SqlClient
 			}
 		}
 
+		[Test]
+		public void ConnectionString ()
+		{
+			SqlConnection cn = new SqlConnection ();
+			cn.ConnectionString = "server=SQLSRV";
+			Assert.AreEqual ("server=SQLSRV", cn.ConnectionString, "#1");
+			cn.ConnectionString = null;
+			Assert.AreEqual (string.Empty, cn.ConnectionString, "#2");
+			cn.ConnectionString = "server=SQLSRV";
+			Assert.AreEqual ("server=SQLSRV", cn.ConnectionString, "#3");
+			cn.ConnectionString = string.Empty;
+			Assert.AreEqual (string.Empty, cn.ConnectionString, "#4");
+		}
+
 		[Test]
 		public void ConnectionTimeoutSynonyms()
 		{
@@ -301,5 +366,29 @@ namespace MonoTests.System.Data.SqlClient
 			cn.ConnectionString = "initial file name=dunno";
 			*/
 		}
+
+		[Test]
+		public void ServerVersion_Connection_Closed ()
+		{
+			SqlConnection cn = new SqlConnection ();
+			try {
+				Assert.Fail ("#A1:" + cn.ServerVersion);
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
+				Assert.IsNull (ex.InnerException, "#A3");
+				Assert.IsNotNull (ex.Message, "#A4");
+			}
+
+			cn = new SqlConnection ("server=SQLSRV; database=Mono;");
+			try {
+				Assert.Fail ("#B1:" + cn.ServerVersion);
+			} catch (InvalidOperationException ex) {
+				// Invalid operation. The connection is closed
+				Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
 	}
 }

+ 554 - 0
mcs/class/System.Data/Test/System.Data.SqlClient/SqlDataAdapterTest.cs

@@ -0,0 +1,554 @@
+//
+// SqlDataAdapterTest.cs - NUnit Test Cases for testing the
+//                        SqlDataAdapter class
+// Author:
+//      Gert Driesen ([email protected])
+//
+// Copyright (c) 2007 Gert Driesen
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Data;
+using System.Data.Odbc;
+using System.Data.SqlClient;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Data.SqlClient
+{
+	[TestFixture]
+	public class SqlDataAdapterTest
+	{
+		[Test] // SqlDataAdapter ()
+		public void Constructor1 ()
+		{
+			SqlDataAdapter da = new SqlDataAdapter ();
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNull (da.SelectCommand, "#11");
+			Assert.IsNull (da.Site, "#12");
+			Assert.IsNotNull (da.TableMappings, "#13");
+			Assert.AreEqual (0, da.TableMappings.Count, "#14");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#15");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#16");
+		}
+
+		[Test] // SqlDataAdapter (SqlCommand)
+		public void Constructor2 ()
+		{
+			SqlCommand cmd = new SqlCommand ();
+			SqlDataAdapter da = new SqlDataAdapter (cmd);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (cmd, da.SelectCommand, "#12");
+			Assert.IsNull (da.Site, "#13");
+			Assert.IsNotNull (da.TableMappings, "#14");
+			Assert.AreEqual (0, da.TableMappings.Count, "#15");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#16");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#17");
+		}
+
+		[Test] // SqlDataAdapter (SqlCommand)
+		public void Constructor2_SelectCommand_Null ()
+		{
+			SqlDataAdapter da = new SqlDataAdapter ((SqlCommand) null);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNull (da.SelectCommand, "#11");
+			Assert.IsNull (da.Site, "#12");
+			Assert.IsNotNull (da.TableMappings, "#13");
+			Assert.AreEqual (0, da.TableMappings.Count, "#14");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#15");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#16");
+		}
+
+		[Test] // SqlDataAdapter (string, SqlConnection)
+		public void Constructor3 ()
+		{
+			string selectCommandText = "SELECT * FROM Authors";
+			SqlConnection selectConnection = new SqlConnection ();
+
+			SqlDataAdapter da = new SqlDataAdapter (selectCommandText,
+				selectConnection);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
+			Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#13");
+			Assert.IsNull (da.Site, "#14");
+			Assert.IsNotNull (da.TableMappings, "#15");
+			Assert.AreEqual (0, da.TableMappings.Count, "#16");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#17");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#18");
+		}
+
+		[Test] // SqlDataAdapter (string, SqlConnection)
+		public void Constructor3_SelectCommandText_Null ()
+		{
+			SqlConnection selectConnection = new SqlConnection ();
+
+			SqlDataAdapter da = new SqlDataAdapter ((string) null,
+				selectConnection);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
+			Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
+			Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#14");
+			Assert.IsNull (da.Site, "#15");
+			Assert.IsNotNull (da.TableMappings, "#16");
+			Assert.AreEqual (0, da.TableMappings.Count, "#17");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#18");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#19");
+		}
+
+		[Test] // SqlDataAdapter (string, SqlConnection)
+		public void Constructor3_SelectConnection_Null ()
+		{
+			string selectCommandText = "SELECT * FROM Authors";
+
+			SqlDataAdapter da = new SqlDataAdapter (selectCommandText,
+				(SqlConnection) null);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
+			Assert.IsNull (da.SelectCommand.Connection, "#13");
+			Assert.IsNull (da.Site, "#14");
+			Assert.IsNotNull (da.TableMappings, "#15");
+			Assert.AreEqual (0, da.TableMappings.Count, "#16");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#17");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#18");
+		}
+
+		[Test] // SqlDataAdapter (string, string)]
+		public void Constructor4 ()
+		{
+			string selectCommandText = "SELECT * FROM Authors";
+			string selectConnectionString = "server=SQLSRV;database=Mono";
+
+			SqlDataAdapter da = new SqlDataAdapter (selectCommandText,
+				selectConnectionString);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
+			Assert.IsNotNull (da.SelectCommand.Connection, "#13");
+			Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#14");
+			Assert.IsNull (da.Site, "#15");
+			Assert.IsNotNull (da.TableMappings, "#16");
+			Assert.AreEqual (0, da.TableMappings.Count, "#17");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#18");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#19");
+		}
+
+		[Test] // SqlDataAdapter (string, string)]
+		public void Constructor4_SelectCommandText_Null ()
+		{
+			string selectConnectionString = "server=SQLSRV;database=Mono";
+
+			SqlDataAdapter da = new SqlDataAdapter ((string) null,
+				selectConnectionString);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
+			Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
+			Assert.IsNotNull (da.SelectCommand.Connection, "#14");
+			Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#15");
+			Assert.IsNull (da.Site, "#16");
+			Assert.IsNotNull (da.TableMappings, "#17");
+			Assert.AreEqual (0, da.TableMappings.Count, "#18");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#19");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#20");
+		}
+
+		[Test] // SqlDataAdapter (string, string)]
+		public void Constructor4_SelectConnectionString_Null ()
+		{
+			string selectCommandText = "SELECT * FROM Authors";
+
+			SqlDataAdapter da = new SqlDataAdapter (selectCommandText,
+				(string) null);
+			Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
+#if NET_2_0
+			Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
+#endif
+			Assert.IsNull (da.Container, "#3");
+			Assert.IsFalse (da.ContinueUpdateOnError, "#4");
+			Assert.IsNull (da.DeleteCommand, "#5");
+#if NET_2_0
+			Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
+#endif
+			Assert.IsNull (da.InsertCommand, "#7");
+			Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
+			Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
+#if NET_2_0
+			Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
+#endif
+			Assert.IsNotNull (da.SelectCommand, "#11");
+			Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
+			Assert.IsNotNull (da.SelectCommand.Connection, "#14");
+			Assert.AreEqual (string.Empty, da.SelectCommand.Connection.ConnectionString, "#15");
+			Assert.IsNull (da.Site, "#16");
+			Assert.IsNotNull (da.TableMappings, "#17");
+			Assert.AreEqual (0, da.TableMappings.Count, "#18");
+#if NET_2_0
+			Assert.AreEqual (1, da.UpdateBatchSize, "#19");
+#endif
+			Assert.IsNull (da.UpdateCommand, "#20");
+		}
+
+		[Test]
+		public void DeleteCommand ()
+		{
+			SqlDataAdapter da = new SqlDataAdapter ();
+			SqlCommand cmd1 = new SqlCommand ();
+			SqlCommand cmd2 = new SqlCommand ();
+
+			da.DeleteCommand = cmd1;
+			Assert.AreSame (cmd1, da.DeleteCommand, "#1");
+			da.DeleteCommand = cmd2;
+			Assert.AreSame (cmd2, da.DeleteCommand, "#2");
+			da.DeleteCommand = null;
+			Assert.IsNull (da.DeleteCommand, "#3");
+		}
+
+		[Test]
+		public void DeleteCommand_IDbDataAdapter ()
+		{
+			IDbDataAdapter da = new SqlDataAdapter ();
+			SqlCommand cmd1 = new SqlCommand ();
+			SqlCommand cmd2 = new SqlCommand ();
+
+			da.DeleteCommand = cmd1;
+			Assert.AreSame (cmd1, da.DeleteCommand, "#A1");
+			da.DeleteCommand = cmd2;
+			Assert.AreSame (cmd2, da.DeleteCommand, "#A2");
+			da.DeleteCommand = null;
+			Assert.IsNull (da.DeleteCommand, "#A3");
+
+			try {
+				da.DeleteCommand = new OdbcCommand ();
+				Assert.Fail ("#B1");
+			} catch (InvalidCastException ex) {
+				Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+
+		[Test]
+		public void Dispose ()
+		{
+			SqlDataAdapter da = new SqlDataAdapter ();
+			da.DeleteCommand = new SqlCommand ();
+			da.InsertCommand = new SqlCommand ();
+			da.SelectCommand = new SqlCommand ();
+			da.UpdateCommand = new SqlCommand ();
+			da.Dispose ();
+
+			Assert.IsNull (da.DeleteCommand, "#1");
+			Assert.IsNull (da.InsertCommand, "#2");
+			Assert.IsNull (da.SelectCommand, "#3");
+			Assert.IsNotNull (da.TableMappings, "#4");
+			Assert.AreEqual (0, da.TableMappings.Count, "#5");
+			Assert.IsNull (da.UpdateCommand, "#6");
+		}
+
+		[Test]
+		public void InsertCommand ()
+		{
+			SqlDataAdapter da = new SqlDataAdapter ();
+			SqlCommand cmd1 = new SqlCommand ();
+			SqlCommand cmd2 = new SqlCommand ();
+
+			da.InsertCommand = cmd1;
+			Assert.AreSame (cmd1, da.InsertCommand, "#1");
+			da.InsertCommand = cmd2;
+			Assert.AreSame (cmd2, da.InsertCommand, "#2");
+			da.InsertCommand = null;
+			Assert.IsNull (da.InsertCommand, "#3");
+		}
+
+		[Test]
+		public void InsertCommand_IDbDataAdapter ()
+		{
+			IDbDataAdapter da = new SqlDataAdapter ();
+			SqlCommand cmd1 = new SqlCommand ();
+			SqlCommand cmd2 = new SqlCommand ();
+
+			da.InsertCommand = cmd1;
+			Assert.AreSame (cmd1, da.InsertCommand, "#A1");
+			da.InsertCommand = cmd2;
+			Assert.AreSame (cmd2, da.InsertCommand, "#A2");
+			da.InsertCommand = null;
+			Assert.IsNull (da.InsertCommand, "#A3");
+
+			try {
+				da.InsertCommand = new OdbcCommand ();
+				Assert.Fail ("#B1");
+			} catch (InvalidCastException ex) {
+				Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+
+		[Test]
+		public void SelectCommand ()
+		{
+			SqlDataAdapter da = new SqlDataAdapter ();
+			SqlCommand cmd1 = new SqlCommand ();
+			SqlCommand cmd2 = new SqlCommand ();
+
+			da.SelectCommand = cmd1;
+			Assert.AreSame (cmd1, da.SelectCommand, "#1");
+			da.SelectCommand = cmd2;
+			Assert.AreSame (cmd2, da.SelectCommand, "#2");
+			da.SelectCommand = null;
+			Assert.IsNull (da.SelectCommand, "#3");
+		}
+
+		[Test]
+		public void SelectCommand_IDbDataAdapter ()
+		{
+			IDbDataAdapter da = new SqlDataAdapter ();
+			SqlCommand cmd1 = new SqlCommand ();
+			SqlCommand cmd2 = new SqlCommand ();
+
+			da.SelectCommand = cmd1;
+			Assert.AreSame (cmd1, da.SelectCommand, "#A1");
+			da.SelectCommand = cmd2;
+			Assert.AreSame (cmd2, da.SelectCommand, "#A2");
+			da.SelectCommand = null;
+			Assert.IsNull (da.SelectCommand, "#A3");
+
+			try {
+				da.SelectCommand = new OdbcCommand ();
+				Assert.Fail ("#B1");
+			} catch (InvalidCastException ex) {
+				Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+
+#if NET_2_0
+		[Test]
+		public void UpdateBatchSize ()
+		{
+			SqlDataAdapter da = new SqlDataAdapter ();
+			da.UpdateBatchSize = 0;
+			Assert.AreEqual (0, da.UpdateBatchSize, "#1");
+			da.UpdateBatchSize = int.MaxValue;
+			Assert.AreEqual (int.MaxValue, da.UpdateBatchSize, "#2");
+			da.UpdateBatchSize = 1;
+			Assert.AreEqual (1, da.UpdateBatchSize, "#3");
+		}
+		
+		[Test]
+		public void UpdateBatchSize_Negative ()
+		{
+			SqlDataAdapter da = new SqlDataAdapter ();
+			try {
+				da.UpdateBatchSize = -1;
+				Assert.Fail ("#1");
+			} catch (ArgumentOutOfRangeException ex) {
+				Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
+				Assert.IsNull (ex.InnerException, "#3");
+				Assert.IsNotNull (ex.Message, "#4");
+				Assert.IsNotNull (ex.ParamName, "#5");
+				Assert.AreEqual ("UpdateBatchSize", ex.ParamName, "#6");
+			}
+		}
+#endif
+
+		[Test]
+		public void UpdateCommand ()
+		{
+			SqlDataAdapter da = new SqlDataAdapter ();
+			SqlCommand cmd1 = new SqlCommand ();
+			SqlCommand cmd2 = new SqlCommand ();
+
+			da.UpdateCommand = cmd1;
+			Assert.AreSame (cmd1, da.UpdateCommand, "#1");
+			da.UpdateCommand = cmd2;
+			Assert.AreSame (cmd2, da.UpdateCommand, "#2");
+			da.UpdateCommand = null;
+			Assert.IsNull (da.UpdateCommand, "#3");
+		}
+
+		[Test]
+		public void UpdateCommand_IDbDataAdapter ()
+		{
+			IDbDataAdapter da = new SqlDataAdapter ();
+			SqlCommand cmd1 = new SqlCommand ();
+			SqlCommand cmd2 = new SqlCommand ();
+
+			da.UpdateCommand = cmd1;
+			Assert.AreSame (cmd1, da.UpdateCommand, "#A1");
+			da.UpdateCommand = cmd2;
+			Assert.AreSame (cmd2, da.UpdateCommand, "#A2");
+			da.UpdateCommand = null;
+			Assert.IsNull (da.UpdateCommand, "#A3");
+
+			try {
+				da.UpdateCommand = new OdbcCommand ();
+				Assert.Fail ("#B1");
+			} catch (InvalidCastException ex) {
+				Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
+				Assert.IsNull (ex.InnerException, "#B3");
+				Assert.IsNotNull (ex.Message, "#B4");
+			}
+		}
+	}
+}