public void TestTransferToDataSet()
        {
            // must use hard coded params name b/c can't access config file
            string provider   = "System.Data.SqlClient";
            string connString = @"Server=(localdb)\mssqllocaldb;Integrated Security=True;
                 AttachDbFilename=|DataDirectory|\DefaultDb.mdf;Trusted_Connection=Yes;";

            try
            {
                DataSet dataSet = null;

                // Returning generic Database Provider
                var factory = new DbProvider(provider).Provider;

                // Making connection to appropriate DB based on provider
                var connection = factory.CreateConnection();
                connection.ConnectionString = connString;

                // Data access
                var dbToDataSet = new DbToDataSet(factory, connection);
                dataSet = new InitTransferDbToDataSet(dbToDataSet)
                          .TransferDataToDataSet();

                // This is merely testing that a transfer occurred (not null)
                Assert.IsNotNull(dataSet);
            }
            catch (DbException ex)
            {
                Program.ErrorMessage(ex);
                Console.WriteLine("ErrorCode: {0}", ex.ErrorCode);
            }
        }
        public void TestPrintTable()
        {
            DataSet dataSet = null;

            // must use hard coded params name b/c can't access config file
            string provider   = "System.Data.SqlClient";
            string connString = @"Server=(localdb)\mssqllocaldb;Integrated Security=True;
                 AttachDbFilename=|DataDirectory|\DefaultDb.mdf;Trusted_Connection=Yes;";

            try
            {
                // Returning generic Database Provider
                var factory = new DbProvider(provider).Provider;

                // Making connection to appropriate DB based on provider
                var connection = factory.CreateConnection();
                connection.ConnectionString = connString;

                // Data access
                var dbToDataSet = new DbToDataSet(factory, connection)
                {
                    CommandType = CommandType.Text
                };

                Assert.IsNotNull(dbToDataSet);

                // testing printing against different SQL queries
                foreach (string query in _testQueries)
                {
                    dbToDataSet.Query = query;
                    dataSet           = new InitTransferDbToDataSet(dbToDataSet)
                                        .TransferDataToDataSet();

                    Assert.IsNotNull(dataSet);

                    // Testing various query outputs to console
                    Program.PrintTables(dataSet);
                }

                // testing production query
                //dbToDataSet.Query = _productionQuery;
                dbToDataSet.CommandType = CommandType.StoredProcedure;
                dbToDataSet.Query       = "spGet_Bugs_Daffy";

                dataSet = new InitTransferDbToDataSet(dbToDataSet)
                          .TransferDataToDataSet();

                Assert.IsNotNull(dataSet);

                Program.PrintTables(dataSet);
            }
            catch (DbException ex)
            {
                Program.ErrorMessage(ex);
                Console.WriteLine("ErrorCode: {0}", ex.ErrorCode);
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            // Ensuring DataDirectory knows file location; for using the DB
            SetClientDataDirFileLocation();

            DataSet dataSet = null;

            try
            {
                // Returning generic Database Provider
                var factory = new DbProvider().Provider;

                // Making connection to appropriate DB based on provider
                var connection = factory.CreateConnection();
                connection.ConnectionString =
                    DbConfigurationSettings.ConnectionString;

                // Data access
                var dbToDataSet = new DbToDataSet(factory, connection);
                dataSet = new InitTransferDbToDataSet(dbToDataSet)
                          .TransferDataToDataSet();
            }
            catch (DbException ex)
            {
                ErrorMessage(ex);
                Console.WriteLine("ErrorCode: {0}", ex.ErrorCode);
            }

            // Printing of DB table to console
            PrintTables(dataSet);

            // Writing the table information as XML to bin file
            PrintXml(dataSet);

            Console.ReadKey();
        }