Beispiel #1
0
		private int ReadDBData_Fill(Sys.Data.Common.DbDataAdapter dbDA, ref DataSet ds, bool ReadSchemaOnly) {
			int ExpectedRowsCount = 0;
			IDbDataAdapter Ida = (IDbDataAdapter)dbDA;
			IDbCommand ICmd = Ida.SelectCommand; 
			IDbConnection IConn = ICmd.Connection; 
			IDataReader Idr;
			IConn.ConnectionString = MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString;
			ICmd.CommandText = "SELECT EmployeeID, LastName, FirstName, Title, Address, City, Region, Country, Extension, HomePhone  FROM Employees "  ;
			IConn.Open();

			//get db type
			DBType = ConnectedDataProvider.GetDbType(((IDbDataAdapter)dbDA).SelectCommand.Connection.ConnectionString);

			// Execute data Reader - Get Expected results
			Idr = ICmd.ExecuteReader();

			// create temp dataset to insert results
			ExpectedRowsCount = DataReaderFill_Fill(ref ds,ref Idr,ReadSchemaOnly);
			Idr.Close();
			return ExpectedRowsCount;
		}
Beispiel #2
0
		protected void DataAdapter_MissingSchemaAction(Sys.Data.Common.DbDataAdapter dbDA) {
			Exception exp = null;
			IDbDataAdapter Ida = (IDbDataAdapter)dbDA;
			IDbCommand ICmd = Ida.SelectCommand; 
			IDbConnection IConn = ICmd.Connection; 
			IConn.ConnectionString = MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString;
//			IConn.Open();

			PrepareDataForTesting( MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
			IConn.Open();

			//get the total rows count
			ICmd.CommandText = "SELECT Count(*) FROM Customers where CustomerID in ('GH100','GH200','GH300','GH400','GH500','GH600','GH700')";
			int ExpectedRows = Sys.Convert.ToInt32(ICmd.ExecuteScalar());
			try {
				BeginCase("Check that Expected rows count > 0");
				Compare(ExpectedRows > 0 ,true);
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

			ICmd.CommandText = "SELECT CustomerID, CompanyName, City, Country, Phone FROM Customers where CustomerID in ('GH100','GH200','GH300','GH400','GH500','GH600','GH700')";

			//get db type
			DBType = ConnectedDataProvider.GetDbType(((IDbDataAdapter)dbDA).SelectCommand.Connection.ConnectionString);

			//init dataset
			DataSet ds = new DataSet();
			try {
				BeginCase("Execute Fill - check return rows count");
				int i = dbDA.Fill(ds);
				Compare(i ,ExpectedRows );
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

			//make dataset schema mismatch with DB
			ds.Tables[0].Columns.Remove("Country");
			ds.Tables[0].Clear();
        

			//--- Default value ---
        
			try {
				BeginCase("MissingSchemaAction Default value");
				Compare(dbDA.MissingSchemaAction, MissingSchemaAction.Add);
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}
	
			//--- MissingSchemaAction.Error ---
			ds.Tables[0].Clear();
			dbDA.MissingSchemaAction  = MissingSchemaAction.Error  ;
			Exception ExMissingSchemaAction = null;
			try {
				BeginCase("MissingSchemaAction.Error");
				try {
					dbDA.Fill(ds);
				}
				catch (InvalidOperationException e) {
					ExMissingSchemaAction = e;
				}
				Compare(ExMissingSchemaAction.GetType() ,typeof(InvalidOperationException));
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

			try {
				BeginCase("MissingSchemaAction.Error, Row.Count = 0");
				Compare(ds.Tables[0].Rows.Count , 0 );
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

			try {
				BeginCase("MissingSchemaAction.Error, Column");
				Compare(ds.Tables[0].Columns.IndexOf("Country")  , -1 );
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}
	

			//--- MissingSchemaAction.Ignore ---
			try {
				//catch any exception that might occure 
				BeginCase("MissingSchemaAction.Ignore - invoke");
				ds.Tables[0].Clear();
				dbDA.MissingSchemaAction  = MissingSchemaAction.Ignore  ;
				ExMissingSchemaAction = null;
				dbDA.Fill(ds);
				Compare(true ,true);
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

			try {
				BeginCase("MissingSchemaAction.Ignore, Row.Count = 0");
				Compare(ds.Tables[0].Rows.Count > 0 ,true);
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

			try {
				BeginCase("MissingSchemaAction.Ignore, Column");
				Compare(ds.Tables[0].Columns.IndexOf("Country")  , -1 );
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

#if !KNOWN_BUG //BUG_NUM:1951
			try {
				BeginCase("MissingSchemaAction.Ignore, PrimaryKey");
				Compare(ds.Tables[0].PrimaryKey.Length == 0 ,true );
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}
#endif

			//--- MissingSchemaAction.Add ---
			try {
				//catch any exception that might occure 
				BeginCase("MissingSchemaAction.Add - invoke");
				ds.Tables[0].Clear();
				dbDA.MissingSchemaAction  = MissingSchemaAction.Add   ;
				ExMissingSchemaAction = null;
				dbDA.Fill(ds);
				Compare(true ,true);
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

			try {
				BeginCase("MissingSchemaAction.Add, Row.Count > 0");
				Compare(ds.Tables[0].Rows.Count >= 0 ,true );
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

			try {
				BeginCase("MissingSchemaAction.Add, Column");
				Compare(ds.Tables[0].Columns.IndexOf("Country") >= 0  ,true );
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

#if !KNOWN_BUG //BUG_NUM:1952
			//DB2 don't return primary key
			if (DBType != DataBaseServer.DB2) {
				try {
					BeginCase("MissingSchemaAction.AddWithKey, PrimaryKey");
					Compare(ds.Tables[0].PrimaryKey.Length  ,0);
				}
				catch(Exception ex)	{exp = ex;}
				finally	{EndCase(exp); exp = null;}
			}

			//--- MissingSchemaAction.AddWithKey ---
			try {
				//catch any exception that might occure 
				BeginCase("MissingSchemaAction.AddWithKey - invoke");
				ds.Tables[0].Clear();
				ds.Tables[0].Columns.Remove("Country");
				dbDA.MissingSchemaAction  = MissingSchemaAction.AddWithKey    ;
				ExMissingSchemaAction = null;
				dbDA.Fill(ds);
				Compare(true ,true);
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

			try {
				BeginCase("MissingSchemaAction.AddWithKey, Row.Count > 0");
				Compare(ds.Tables[0].Rows.Count >= 0 ,true );
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

			try {
				BeginCase("MissingSchemaAction.AddWithKey, Column");
				Compare(ds.Tables[0].Columns.IndexOf("Country") >= 0  ,true );
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

			//DB2 don't return primary key
			if (DBType != DataBaseServer.DB2 &&
				DBType != DataBaseServer.Oracle) {
				try {
					BeginCase("MissingSchemaAction.AddWithKey, PrimaryKey");
					Compare(ds.Tables[0].PrimaryKey.Length > 0 ,true );
				}
				catch(Exception ex)	{exp = ex;}
				finally	{EndCase(exp); exp = null;}
			}
#endif

			//close connection
			if (  ((IDbDataAdapter)dbDA).SelectCommand.Connection.State != ConnectionState.Closed )
				((IDbDataAdapter)dbDA).SelectCommand.Connection.Close();
		}