예제 #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"));
        }
예제 #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");
                }
            }
        }
예제 #3
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");
                }
            }
        }