Beispiel #1
0
        public void CanThrowExceptionWhenUnknownDatabase()
        {
            string fullPath;
            var    isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);

            using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("Testfile.cnf", FileMode.OpenOrCreate, isoStore))
            {
                using (StreamWriter writer = new StreamWriter(isoStream))
                {
                    writer.WriteLine("[mysqldump]");
                    writer.WriteLine("user=test");
                    writer.WriteLine("password=test");
                }

                var fieldInfo = isoStream.GetType().GetField("m_FullPath", BindingFlags.Instance | BindingFlags.NonPublic);
                Assert.True(fieldInfo != null);
                fullPath = fieldInfo.GetValue(isoStream).ToString();
            }

            _options.database = "unknown";
            _options.port     = 3305;
            var mysqldump = new MySqlDumpFacade(_options, _saveToFile, fullPath);

            mysqldump._dumpFilePath = Path.GetFullPath(@"..\..\..\..\..\Dependencies\MySql\mysqldump.exe");

            mysqldump.ProcessRequest(_saveToFile);

            var errors = mysqldump.ErrorsOutput.ToString();

            Assert.True(errors.Contains("mysqldump: Got error: 1044: Access denied for user 'test'@'localhost' to database 'unknown' when selecting the database"));
        }
Beispiel #2
0
        public void CanDumpAListOfDatabases()
        {
            string fullPath;

            var isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);

            using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("Testfile.cnf", FileMode.OpenOrCreate, isoStore))
            {
                using (StreamWriter writer = new StreamWriter(isoStream))
                {
                    writer.WriteLine("[mysqldump]");
                    writer.WriteLine("user=test");
                    writer.WriteLine("password=test");
                }

                var fieldInfo = isoStream.GetType().GetField("m_FullPath", BindingFlags.Instance | BindingFlags.NonPublic);
                Assert.True(fieldInfo != null);
                fullPath = fieldInfo.GetValue(isoStream).ToString();
            }

            var databases = new List <string>();

            databases.Add("DumpTest");
            databases.Add("SecondTest");
            databases.Add("ThirdTest");
            foreach (var database in databases)
            {
                _options.database = database;
                _options.port     = 3305;
                var mysqldump = new MySqlDumpFacade(_options, _saveToFile, fullPath);
                mysqldump._dumpFilePath = Path.GetFullPath(@"..\..\..\..\..\Dependencies\MySql\mysqldump.exe");

                mysqldump.ProcessRequest(_saveToFile);

                if (File.Exists(_saveToFile))
                {
                    using (var dump = new StreamReader(_saveToFile))
                    {
                        var content = dump.ReadToEnd();
                        Assert.True(content.Contains(database), "A database is missed in the dump file");
                    }
                }
                if (!string.IsNullOrEmpty(mysqldump.ErrorsOutput.ToString()))
                {
                    Assert.False(true, "CanDumpAListOfDatabases: Test Failed");
                }
            }
        }
Beispiel #3
0
        public void CanLoadAllOptions()
        {
            var testOptions = new MySqlDbExportOptions();

            testOptions.no_data        = true;
            testOptions.insert_ignore  = true;
            testOptions.ignore_table   = "nameoftable";
            testOptions.routines       = true;
            testOptions.lock_tables    = true;
            testOptions.port           = 3305;
            testOptions.allow_keywords = true;

            string fullPath;

            var isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);

            using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("Testfile.cnf", FileMode.OpenOrCreate, isoStore))
            {
                using (StreamWriter writer = new StreamWriter(isoStream))
                {
                    writer.WriteLine("[mysqldump]");
                    writer.WriteLine("user=test;");
                    writer.WriteLine("password=test;");
                }

                var fieldInfo = isoStream.GetType().GetField("m_FullPath", BindingFlags.Instance | BindingFlags.NonPublic);
                Assert.True(fieldInfo != null);
                fullPath = fieldInfo.GetValue(isoStream).ToString();
            }

            var mysqldumpFacade = new MySqlDumpFacade(testOptions, _saveToFile, fullPath);
            var arguments       = mysqldumpFacade.GetType().GetField("_arguments", BindingFlags.NonPublic | BindingFlags.Instance);

            if (arguments != null)
            {
                isoStore.DeleteFile("Testfile.cnf");
                isoStore.Close();

                string expected = @"--add-drop-database  --add-drop-table  --add-locks=false  --all-databases=false  --allow-keywords  --comments  --compact=false  --complete-insert=false  --create-options  --databases  --default-character-set=utf8 --delayed-insert=false  --disable-keys  --events=false  --extended-insert  --flush-logs=false  --hex-blob=false  --ignore-table=nameoftable --insert-ignore  --lock-tables  --no-data  --no-create-info=false  --max_allowed_packet=1G --order-by-primary=false  --port=3305 --quote-names  --replace=false  --routines  --single-transaction=false  --set-gtid-purged=OFF  """;
                var    value    = arguments.GetValue(mysqldumpFacade);
                Assert.True(value.ToString().Contains(expected));
            }
        }
Beispiel #4
0
        public void CanDoDumpFileForDb()
        {
            string fullPath;
            var    isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);

            using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("Testfile.cnf", FileMode.OpenOrCreate, isoStore))
            {
                using (StreamWriter writer = new StreamWriter(isoStream))
                {
                    writer.WriteLine("[mysqldump]");
                    writer.WriteLine("user=test");
                    writer.WriteLine("password=test");
                }

                var fieldInfo = isoStream.GetType().GetField("m_FullPath", BindingFlags.Instance | BindingFlags.NonPublic);
                Assert.True(fieldInfo != null);
                fullPath = fieldInfo.GetValue(isoStream).ToString();
            }

            _options.database = "DumpTest";
            _options.port     = 3305;
            var mysqldump = new MySqlDumpFacade(_options, _saveToFile, fullPath);

            mysqldump._dumpFilePath = Path.GetFullPath(@"..\..\..\..\..\Dependencies\MySql\mysqldump.exe");

            mysqldump.ProcessRequest(_saveToFile);

            if (File.Exists(_saveToFile))
            {
                using (var dump = new StreamReader(_saveToFile))
                {
                    var content = dump.ReadToEnd();
                    Assert.True(content.Contains("DumpTest"), "A database is missed in the dump file");
                }
            }
        }