Exemple #1
0
        //Implements SaveAs functionality
        private void SaveAs()
        {
            saveFileDialog1.Filter           = "db files (*.db)|*.db|All files (*.*)|*.*";
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string newName = saveFileDialog1.FileName;
                //Should never be hit
                if (null == database)
                {
                    System.Windows.Forms.MessageBox.Show("No database is open",
                                                         "Error",
                                                         System.Windows.Forms.MessageBoxButtons.OK,
                                                         System.Windows.Forms.MessageBoxIcon.Hand,
                                                         System.Windows.Forms.MessageBoxDefaultButton.Button1);
                }

                else if (IsReadOnly(newName))
                {
                    string errMsg = String.Format("File {0} is read only! \nSave the file under different name?",
                                                  newName);
                    DialogResult result = System.Windows.Forms.MessageBox.Show(errMsg,
                                                                               "Error",
                                                                               System.Windows.Forms.MessageBoxButtons.YesNo,
                                                                               System.Windows.Forms.MessageBoxIcon.Hand,
                                                                               System.Windows.Forms.MessageBoxDefaultButton.Button1);

                    if (DialogResult.Yes == result)
                    {
                        this.SaveAs();
                    }
                }
                else
                {
                    //If the source file is read only the CopyTo method will also create a ReadOnly file
                    //Take the new file and remove the ReadOnly attribute in order to be able to save any new changes
                    System.IO.FileAttributes attribute = new System.IO.FileAttributes();
                    FileInfo oldDbFile = new FileInfo(database.GetName());
                    oldDbFile.CopyTo(newName, true);
                    if (IsReadOnly(database.GetName()))
                    {
                        FileInfo newDbFile = new FileInfo(newName);
                        newDbFile.Attributes = FileAttributes.Archive;
                    }

                    //Open the new file
                    database.Close();
                    database = new SqliteDb();
                    database.Open(newName);

                    this.SaveDatabase();
                    this.OpenDatabase(newName);
                }
            }
        }
Exemple #2
0
        public TestExecutionRun(string dbPath, ITestExecutorCollection exec, bool generateDump = false)
        {
            _executors    = exec;
            _generateDump = generateDump;
            _unitTestDb   = new SqliteDb();
            _unitTestDb.Open(dbPath);

            _unitTestVm       = new SqliteVm(_unitTestDb, false);
            _unitTestResultVm = new SqliteVm(_unitTestDb, false);
        }
Exemple #3
0
        public TestExecutionRun(string dbPath, ITestExecutorCollection exec, bool generateDump = false)
        {
            _executors = exec;
            _generateDump = generateDump;
            _unitTestDb = new SqliteDb();
            _unitTestDb.Open(dbPath);

            _unitTestVm = new SqliteVm(_unitTestDb, false);
            _unitTestResultVm = new SqliteVm(_unitTestDb, false);
        }
Exemple #4
0
        private void NewDatabase(bool template)
        {
            saveFileDialog1.Filter           = "db files (*.db)|*.db|All files (*.*)|*.*";
            saveFileDialog1.RestoreDirectory = true;
            SqliteDb db = null;

            string dbName = "";

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                dbName = saveFileDialog1.FileName;
                if (!IsReadOnly(dbName))
                {
                    //Close the existing database
                    if (null != this.database)
                    {
                        this.CloseDatabase();
                    }

                    //Delete the file
                    this.DeleteFile(dbName);

                    //Open the database. SQLite will create the file for us
                    db = new SqliteDb();
                    db.Open(dbName);

                    //Create a template database for the unit test infrastructure
                    if (template && (db != null))
                    {
                        SqliteVm templateVm = new SqliteVm(db, true);
                        templateVm.Execute("CREATE TABLE TestCase (ExecuteSequence INTEGER, TestName TEXT, ParamSets TEXT, Description TEXT, TestType TEXT, Prerequisite TEXT)");
                        templateVm.Execute("CREATE TABLE Params (ParamSet INTEGER, ParamName TEXT, ParamValue TEXT)");
                        templateVm.Execute("CREATE TABLE CommonParams (ParamName text, ParamValue text)");
                        templateVm.Execute("CREATE TABLE ApiTestResults (Description TEXT, ParamSet INTEGER, ContentType TEXT, Result TEXT)");
                        templateVm.Execute("CREATE TABLE HttpTestResults (Description TEXT, ParamSet INTEGER, ContentType TEXT, Result BLOB)");
                        templateVm.SqlFinalize();
                        templateVm = null;
                    }
                    db.Close();

                    //Open the new database
                    this.OpenDatabase(dbName);
                }
                else
                {
                    string errMsg;
                    errMsg = String.Format("File {0} is readOnly and cannot be replaced", dbName);
                    System.Windows.Forms.MessageBox.Show(errMsg,
                                                         "Error",
                                                         System.Windows.Forms.MessageBoxButtons.OK,
                                                         System.Windows.Forms.MessageBoxIcon.Hand);
                    this.NewDatabase(template);
                }
            }
        }
        protected PlatformApiTestExecutor(string opName, string apiType, string unitTestVm)
        {
            _opName = opName;
            _apiType = apiType;
            _unitTestVmPath = unitTestVm;

            _unitTestDb = new SqliteDb();
            _unitTestDb.Open(_unitTestVmPath);

            _unitTestVm = new SqliteVm(_unitTestDb, true);
        }
        protected PlatformApiTestExecutor(string opName, string apiType, string unitTestVm)
        {
            _opName         = opName;
            _apiType        = apiType;
            _unitTestVmPath = unitTestVm;

            _unitTestDb = new SqliteDb();
            _unitTestDb.Open(_unitTestVmPath);

            _unitTestVm = new SqliteVm(_unitTestDb, true);
        }
Exemple #7
0
        private void OpenDatabase(string fName)
        {
            if (database != null)
            {
                CloseDatabase();
            }

            if (fName.Length > 0)
            {
                database = new SqliteDb();
                int err = database.Open(fName);
                if (err != 0)
                {
                    database = null;
                }
            }

            if (database != null)
            {
                databaseName = fName;

                treeView1.BeginUpdate();

                // Clear the TreeView each time the method is called.
                treeView1.Nodes.Clear();

                TreeNode databaseNode = new TreeNode(fName);

                SqliteVm vm        = new SqliteVm(database, true);
                string   tableList = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;";

                int fini = vm.Execute(tableList);
                while (fini == Sqlite.Row)
                {
                    string tableName = vm.GetString("name");

                    databaseNode.Nodes.Add(tableName);

                    fini = vm.NextRow();
                }
                vm.SqlFinalize();
                vm = null;

                treeView1.Nodes.Add(databaseNode);

                treeView1.EndUpdate();
                //Enable menu items
                this.menuItem3.Enabled      = true;
                this.menuAddTest.Enabled    = true;
                this.saveAsMenuItem.Enabled = true;
                this.saveDbMenuItem.Enabled = true;
            }
        }
        public int Execute(ref int testsRun, ITestLogger logger, bool isEnterprise)
        {
            int    exitStatus = 0;
            string dbPath     = CommonUtility.GetDbPath(this.DumpFile);
            string dbName     = CommonUtility.GetPath(dbPath);

            if (File.Exists(dbName))
            {
                var db = new SqliteDb();
                db.Open(dbName);

                var vm = new SqliteVm(db, true);

                int status = vm.Execute("Select TestName, TestType from TestCase where TestType=\"{0}\" order by ExecuteSequence", this.ApiType);

                //NOTE: We can't share the SqliteVm instance among our executor objects as this messes up query results
                //we must be able to re-create a new SqliteVm for each executor, so we pass down the db path
                SetupExecutors(dbName);

                while (status == Sqlite.Row)
                {
                    string testName = vm.GetString("TestName");
                    string testType = vm.GetString("TestType");

                    Console.WriteLine("Executing {0} test: {1}", testType, testName);
                    using (var run = new TestExecutionRun(dbPath, this))
                    {
                        try
                        {
                            exitStatus += run.RunTests(testName, logger, ref testsRun);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                            exitStatus += 1;
                        }
                    }
                    status = vm.NextRow();
                }
                vm.SqlFinalize();
                vm = null;
                db = null;
            }
            return(exitStatus);
        }
Exemple #9
0
        private void SaveDatabase()
        {
            if (!this.addTestForm.IsDisposed)
            {
                this.addTestForm.Dispose();
            }

            if (database != null)
            {
                string dbName = database.GetName();
                if (!IsReadOnly(dbName))
                {
                    this.CloseForms();
                }
                else
                {
                    //If the file is read only show a warning message and if the user wants, make the file writeable
                    string errMsg = String.Format("File {0} is read only! \nOverwrite it?",
                                                  dbName);
                    DialogResult result = System.Windows.Forms.MessageBox.Show(errMsg,
                                                                               "Error",
                                                                               System.Windows.Forms.MessageBoxButtons.YesNo,
                                                                               System.Windows.Forms.MessageBoxIcon.Hand,
                                                                               System.Windows.Forms.MessageBoxDefaultButton.Button1);

                    if (DialogResult.Yes == result)
                    {
                        FileInfo dbFile = new FileInfo(dbName);
                        dbFile.Attributes = FileAttributes.Archive;

                        //Hack...if the database is not read only we can write to it.
                        //Nevertheles, if the ReadOnly property has changed after the database handler was created
                        //then, we need to re-create it or SQLite will throw exception
                        database.Close();
                        database = new SqliteDb();
                        database.Open(dbName);
                        this.CloseForms();
                    }
                }
            }
        }
Exemple #10
0
        private void SaveDatabase()
        {
            if (!this.addTestForm.IsDisposed)
            {
                this.addTestForm.Dispose();
            }

            if (database != null)
            {
                string dbName = database.GetName();
                if (!IsReadOnly(dbName))
                {
                    this.CloseForms();
                }
                else
                {
                    //If the file is read only show a warning message and if the user wants, make the file writeable
                    string errMsg = String.Format("File {0} is read only! \nOverwrite it?",
                                                  dbName);
                    DialogResult result = System.Windows.Forms.MessageBox.Show(errMsg,
                        "Error",
                        System.Windows.Forms.MessageBoxButtons.YesNo,
                        System.Windows.Forms.MessageBoxIcon.Hand,
                        System.Windows.Forms.MessageBoxDefaultButton.Button1);

                    if (DialogResult.Yes == result)
                    {
                        FileInfo dbFile = new FileInfo(dbName);
                        dbFile.Attributes = FileAttributes.Archive;

                        //Hack...if the database is not read only we can write to it.
                        //Nevertheles, if the ReadOnly property has changed after the database handler was created
                        //then, we need to re-create it or SQLite will throw exception
                        database.Close();
                        database = new SqliteDb();
                        database.Open(dbName);
                        this.CloseForms();
                    }
                }
            }
        }
Exemple #11
0
        //Implements SaveAs functionality
        private void SaveAs()
        {
            saveFileDialog1.Filter = "db files (*.db)|*.db|All files (*.*)|*.*";
            saveFileDialog1.RestoreDirectory = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string newName = saveFileDialog1.FileName;
                //Should never be hit
                if (null == database)
                {
                    System.Windows.Forms.MessageBox.Show("No database is open",
                        "Error",
                        System.Windows.Forms.MessageBoxButtons.OK,
                        System.Windows.Forms.MessageBoxIcon.Hand,
                        System.Windows.Forms.MessageBoxDefaultButton.Button1);
                }

                else if (IsReadOnly(newName))
                {
                    string errMsg = String.Format("File {0} is read only! \nSave the file under different name?",
                        newName);
                    DialogResult result = System.Windows.Forms.MessageBox.Show(errMsg,
                        "Error",
                        System.Windows.Forms.MessageBoxButtons.YesNo,
                        System.Windows.Forms.MessageBoxIcon.Hand,
                        System.Windows.Forms.MessageBoxDefaultButton.Button1);

                    if (DialogResult.Yes == result)
                    {
                        this.SaveAs();
                    }
                }
                else
                {
                    //If the source file is read only the CopyTo method will also create a ReadOnly file
                    //Take the new file and remove the ReadOnly attribute in order to be able to save any new changes
                    System.IO.FileAttributes attribute = new System.IO.FileAttributes();
                    FileInfo oldDbFile = new FileInfo(database.GetName());
                    oldDbFile.CopyTo(newName, true);
                    if (IsReadOnly(database.GetName()))
                    {
                        FileInfo newDbFile = new FileInfo(newName);
                        newDbFile.Attributes = FileAttributes.Archive;
                    }

                    //Open the new file
                    database.Close();
                    database = new SqliteDb();
                    database.Open(newName);

                    this.SaveDatabase();
                    this.OpenDatabase(newName);
                }
            }
        }
Exemple #12
0
        private void OpenDatabase(string fName)
        {
            if (database != null)
            {
                CloseDatabase();
            }

            if (fName.Length > 0)
            {
                database = new SqliteDb();
                int err = database.Open(fName);
                if (err != 0)
                {
                    database = null;
                }
            }

            if (database != null)
            {
                databaseName = fName;

                treeView1.BeginUpdate();

                // Clear the TreeView each time the method is called.
                treeView1.Nodes.Clear();

                TreeNode databaseNode = new TreeNode(fName);

                SqliteVm vm = new SqliteVm(database, true);
                string tableList = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;";

                int fini = vm.Execute(tableList);
                while (fini == Sqlite.Row)
                {
                    string tableName = vm.GetString("name");

                    databaseNode.Nodes.Add(tableName);

                    fini = vm.NextRow();
                }
                vm.SqlFinalize();
                vm = null;

                treeView1.Nodes.Add(databaseNode);

                treeView1.EndUpdate();
                //Enable menu items
                this.menuItem3.Enabled = true;
                this.menuAddTest.Enabled = true;
                this.saveAsMenuItem.Enabled = true;
                this.saveDbMenuItem.Enabled = true;
            }
        }
Exemple #13
0
        private void NewDatabase(bool template)
        {
            saveFileDialog1.Filter = "db files (*.db)|*.db|All files (*.*)|*.*";
            saveFileDialog1.RestoreDirectory = true;
            SqliteDb db = null;

            string dbName = "";

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                dbName = saveFileDialog1.FileName;
                if (!IsReadOnly(dbName))
                {

                    //Close the existing database
                    if (null != this.database)
                    {
                        this.CloseDatabase();
                    }

                    //Delete the file
                    this.DeleteFile(dbName);

                    //Open the database. SQLite will create the file for us
                    db = new SqliteDb();
                    db.Open(dbName);

                    //Create a template database for the unit test infrastructure
                    if (template && (db != null))
                    {
                        SqliteVm templateVm = new SqliteVm(db, true);
                        templateVm.Execute("CREATE TABLE TestCase (ExecuteSequence INTEGER, TestName TEXT, ParamSets TEXT, Description TEXT, TestType TEXT, Prerequisite TEXT)");
                        templateVm.Execute("CREATE TABLE Params (ParamSet INTEGER, ParamName TEXT, ParamValue TEXT)");
                        templateVm.Execute("CREATE TABLE CommonParams (ParamName text, ParamValue text)");
                        templateVm.Execute("CREATE TABLE ApiTestResults (Description TEXT, ParamSet INTEGER, ContentType TEXT, Result TEXT)");
                        templateVm.Execute("CREATE TABLE HttpTestResults (Description TEXT, ParamSet INTEGER, ContentType TEXT, Result BLOB)");
                        templateVm.SqlFinalize();
                        templateVm = null;
                    }
                    db.Close();

                    //Open the new database
                    this.OpenDatabase(dbName);
                }
                else
                {
                    string errMsg;
                    errMsg = String.Format("File {0} is readOnly and cannot be replaced", dbName);
                    System.Windows.Forms.MessageBox.Show(errMsg,
                        "Error",
                        System.Windows.Forms.MessageBoxButtons.OK,
                        System.Windows.Forms.MessageBoxIcon.Hand);
                    this.NewDatabase(template);
                }
            }
        }
        public int Execute(ref int testsRun, ITestLogger logger, bool isEnterprise)
        {
            int exitStatus = 0;
            string dbPath = CommonUtility.GetDbPath(this.DumpFile);
            string dbName = CommonUtility.GetPath(dbPath);

            if (File.Exists(dbName))
            {
                var db = new SqliteDb();
                db.Open(dbName);

                var vm = new SqliteVm(db, true);

                int status = vm.Execute("Select TestName, TestType from TestCase where TestType=\"{0}\" order by ExecuteSequence", this.ApiType);

                //NOTE: We can't share the SqliteVm instance among our executor objects as this messes up query results
                //we must be able to re-create a new SqliteVm for each executor, so we pass down the db path
                SetupExecutors(dbName);

                while (status == Sqlite.Row)
                {
                    string testName = vm.GetString("TestName");
                    string testType = vm.GetString("TestType");

                    Console.WriteLine("Executing {0} test: {1}", testType, testName);
                    using (var run = new TestExecutionRun(dbPath, this))
                    {
                        try
                        {
                            exitStatus += run.RunTests(testName, logger, ref testsRun);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                            exitStatus += 1;
                        }
                    }
                    status = vm.NextRow();
                }
                vm.SqlFinalize();
                vm = null;
                db = null;
            }
            return exitStatus;
        }