Пример #1
0
        public void GetDataAccessTestWithValidConnectionString()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();

            Assert.IsTrue(objDataAccess != null);
        }
        public void ExecuteNonQueryTestWithValidCommandType()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            int retVal = objDataAccess.ExecuteNonQuery(_validDmlCommandText, CommandType.Text);

            Assert.IsTrue(retVal > 0);
        }
        public void ExecuteNonQueryTestWithSelectCommandText()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            int RowsAffected = objDataAccess.ExecuteNonQuery(_validCommandText);

            Assert.IsTrue(RowsAffected == -1);
        }
        public void ExecuteScalerTestWithDMLCommandText()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            object            retVal        = objDataAccess.ExecuteScaler(_validDmlCommandText);

            Assert.IsTrue(retVal == null);
        }
        public void ExecuteDataTableTestWithValidCommandText()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DataTable         retVal        = objDataAccess.ExecuteDataTable(_validCommandText);

            Assert.IsTrue(retVal != null);
        }
        public void ExecuteDataSetTestWithDMLCommandText()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DataSet           retVal        = objDataAccess.ExecuteDataSet(_validDmlCommandText);

            Assert.IsTrue(retVal.Tables.Count == 0);
        }
        public void ExecuteNonQueryTestWithInValidCommandType()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            //CommandType.TableDirect is not valid command type for select command
            int RowsAffected = objDataAccess.ExecuteNonQuery(_validDmlCommandText, CommandType.TableDirect);

            Assert.IsTrue(RowsAffected == -1);
        }
        public void ExecuteScalerTestWithInValidCommandType()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            //CommandType.TableDirect is not valid command type for select command
            object retVal = objDataAccess.ExecuteScaler(_validCommandText, CommandType.TableDirect);

            Assert.IsTrue(retVal != null);
        }
        public void ExecuteDataTableTestWithEmptyParameterList()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DalParameterList  dal           = new DalParameterList();

            DataTable retVal = objDataAccess.ExecuteDataTable(_validCommandText, CommandType.Text, dal);

            Assert.IsTrue(retVal != null);
        }
        public void ExecuteDataReaderTestWithDMLCommandText()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();

            using (DbDataReader retVal = objDataAccess.ExecuteDataReader(_validDmlCommandText))
            {
                Assert.IsTrue(retVal != null);
            }
        }
        public void ExecuteDataReaderTestWithNullParameterList()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DalParameterList  dal           = null;

            using (DbDataReader retVal = objDataAccess.ExecuteDataReader(_validCommandText, CommandType.Text, dal))
            {
                Assert.IsTrue(retVal != null);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                string _connectionString = "Data Source=TEST-PC;Initial Catalog=kantarPractice;Integrated Security=False;User ID=sa;Password=pa$$word;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";

                FactoryDataAccess objFactory = new FactoryDataAccess(Provider.Sql, _connectionString);

                IDataAccess      objDataAccess = objFactory.GetDataAccess();
                DalParameterList dal           = new DalParameterList();
                dal.Add(new DalParameter()
                {
                    ParameterName      = "@cityid",
                    ParameterDirection = ParameterDirection.Input,
                    ParameterType      = SqlDbType.Int,
                    ParameterValue     = 2
                });

                //string[] tableNames = new string[] { "", "", "", "", "", "" };

                //DataSet obj = objDataAccess.ExecuteDataSet("[usp_GetCitiesWithParameter]", tableNames);
                //Console.WriteLine( );
                using (DbDataReader reader = objDataAccess.ExecuteDataReader("[usp_GetCitiesWithParameter]", CommandType.StoredProcedure, dal))
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            Console.WriteLine("{0}", reader.GetString(0));
                        }
                    }
                }

                using (DbDataReader reader = objDataAccess.ExecuteDataReader("[usp_GetCitiesWithParameter]", CommandType.StoredProcedure, dal))
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            Console.WriteLine("{0}", reader.GetString(0));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.GetBaseException());
            }
            Console.ReadKey(true);
        }
        public void ExecuteDataTableExecuteDataReaderTestWithInvalidParameterList()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DalParameterList  dal           = new DalParameterList();

            dal.Add(new DalParameter()
            {
                ParameterName      = "",
                ParameterDirection = ParameterDirection.Input
            });

            DataTable retVal = objDataAccess.ExecuteDataTable(_validCommandTextWithParameter, CommandType.Text, dal);

            Assert.IsTrue(retVal != null);
        }
Пример #14
0
        public void ExecuteDataSetTestWithNullTableNames()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DalParameterList  dal           = new DalParameterList();


            //without Parameter value
            dal.Add(new DalParameter()
            {
                ParameterName      = "@p1",
                ParameterValue     = 2,
                ParameterDirection = ParameterDirection.Input
            });
            string[] tableNames = null;
            DataSet  retVal     = objDataAccess.ExecuteDataSet(_validCommandTextWithParameter, CommandType.Text, dal, tableNames);

            Assert.IsTrue(retVal.Tables[0].TableName == "Table");
        }
        public void ExecuteDataTableTestWithValidTableName()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DalParameterList  dal           = new DalParameterList();


            //without Parameter value
            dal.Add(new DalParameter()
            {
                ParameterName      = "@p1",
                ParameterValue     = 2,
                ParameterDirection = ParameterDirection.Input
            });
            string    tableName = "CityData";
            DataTable retVal    = objDataAccess.ExecuteDataTable(_validCommandTextWithParameter, CommandType.StoredProcedure, dal, tableName);

            Assert.IsTrue(retVal.TableName == "CityData");
        }
        public void ExecuteDataSetTestWithInValidTableNamesList()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DalParameterList  dal           = new DalParameterList();


            //without Parameter value
            dal.Add(new DalParameter()
            {
                ParameterName      = "@p1",
                ParameterValue     = 2,
                ParameterDirection = ParameterDirection.Input
            });
            string[] tableNames = new string[] { "CityData", "sdasdas", "dasdasd", "dsadsad" };
            DataSet  retVal     = objDataAccess.ExecuteDataSet(_validCommandTextWithParameter, CommandType.StoredProcedure, dal, tableNames);

            Assert.IsTrue(retVal.Tables[0].TableName == "CityData");
        }
        public void ExecuteNonQueryTestWithInvalidParameterDirection()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DalParameterList  dal           = new DalParameterList();


            //without Parameter value
            dal.Add(new DalParameter()
            {
                ParameterName      = "@p1",
                ParameterValue     = "Country222",
                ParameterDirection = ParameterDirection.ReturnValue
            });

            int retVal = objDataAccess.ExecuteNonQuery(_validDmlCommandTextWithParameter, CommandType.Text, dal);

            Assert.IsTrue(retVal == -1);
        }
        public void ExecuteScalerTestWithoutInputParameterValue()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DalParameterList  dal           = new DalParameterList();


            //without Parameter value
            dal.Add(new DalParameter()
            {
                ParameterName      = "@p1",
                ParameterDirection = ParameterDirection.Input
            });


            object retVal = objDataAccess.ExecuteScaler(_validCommandTextWithParameter, CommandType.Text, dal);

            Assert.IsTrue(retVal != null);
        }
        public void ExecuteDataSetTestWithInvalidParameterDirectionOutput()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DalParameterList  dal           = new DalParameterList();


            //without Parameter value
            dal.Add(new DalParameter()
            {
                ParameterName      = "@p1",
                ParameterValue     = 2,
                ParameterDirection = ParameterDirection.Output
            });


            DataSet retVal = objDataAccess.ExecuteDataSet(_validCommandTextWithParameter, CommandType.StoredProcedure, dal);

            Assert.IsTrue(retVal != null);
        }
        public void ExecuteNonQueryTestWithWithValidParameterType()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DalParameterList  dal           = new DalParameterList();


            //without Parameter value
            dal.Add(new DalParameter()
            {
                ParameterName      = "@p1",
                ParameterValue     = "Country1",
                ParameterDirection = ParameterDirection.Input,
                ParameterType      = SqlDbType.VarChar
            });

            int retVal = objDataAccess.ExecuteNonQuery(_validDmlCommandTextWithParameter, CommandType.StoredProcedure, dal);

            Assert.IsTrue(retVal > 0);
        }
Пример #21
0
        public void ExecuteDataReaderTestWithValidParameter()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DalParameterList  dal           = new DalParameterList();


            //without Parameter value
            dal.Add(new DalParameter()
            {
                ParameterName      = "@p1",
                ParameterValue     = "2; select * from city",
                ParameterDirection = ParameterDirection.Input,
                ParameterType      = SqlDbType.VarChar
            });

            using (DbDataReader retVal = objDataAccess.ExecuteDataReader(_validCommandTextWithParameter, CommandType.Text, dal))
            {
                Assert.IsTrue(retVal != null);
            }
        }
        public void ExecuteDataReaderTestWithInvalidParameterDirection()
        {
            FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
            IDataAccess       objDataAccess = objFactory.GetDataAccess();
            DalParameterList  dal           = new DalParameterList();


            //without Parameter value
            dal.Add(new DalParameter()
            {
                ParameterName      = "@p1",
                ParameterValue     = 2,
                ParameterDirection = ParameterDirection.ReturnValue
            });


            using (DbDataReader retVal = objDataAccess.ExecuteDataReader(_validCommandTextWithParameter, CommandType.Text, dal))
            {
                Assert.IsTrue(retVal == null);
            }
        }
 public void ExecuteDataSetTestWithNullCommandText()
 {
     FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
     IDataAccess       objDataAccess = objFactory.GetDataAccess();
     DataSet           retVal        = objDataAccess.ExecuteDataSet(_nullCommandText);
 }
 public void ExecuteDataTableTestWithEmptyCommandText()
 {
     FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
     IDataAccess       objDataAccess = objFactory.GetDataAccess();
     DataTable         retVal        = objDataAccess.ExecuteDataTable(_emptyCommandText);
 }
 public void ExecuteNonQueryTestWithNullCommandText()
 {
     FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _validConnectionString);
     IDataAccess       objDataAccess = objFactory.GetDataAccess();
     int RowsAffected = objDataAccess.ExecuteNonQuery(_nullCommandText);
 }
Пример #26
0
 public void GetDataAccessTestWithInvalidConnectionString()
 {
     FactoryDataAccess objFactory    = new FactoryDataAccess(Provider.Sql, _inValidConnectionString);
     IDataAccess       objDataAccess = objFactory.GetDataAccess();
 }