public void DownloadAllFiles()
        {
            DatabaseFileHandler dfh = new DatabaseFileHandler();

            String fileName = "test.txt";
            String path     = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            String fullPath = System.IO.Path.Combine(path, fileName);

            if (!File.Exists(fullPath))
            {
                using (StreamWriter sw = File.CreateText(fullPath))
                {
                    sw.WriteLine("TEST FILE :)");
                    sw.WriteLine("Maybe it needs lots of text????");
                }
                while (!File.Exists(fullPath))
                {
                    Thread.Sleep(1000);
                }
            }

            int i = dfh.UploadFile(projectID, File.Open(fullPath, FileMode.Open), fileName);

            path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            List <String> fileList = dfh.DownloadAllFiles(projectID, path);

            foreach (String f in fileList)
            {
                if (File.Exists(f))
                {
                    Assert.IsTrue(true);
                    File.Delete(f);
                }
            }

            int fileID = 0;

            ConnectionClass.OpenConnection();
            MySqlCommand comm = ConnectionClass.con.CreateCommand();

            comm.CommandText = "SELECT FileID FROM storedfiles sf WHERE sf.FileName = @fileName AND sf.ProjectID = @id";
            comm.Parameters.AddWithValue("@fileName", fileName);
            comm.Parameters.AddWithValue("@id", projectID);
            using (MySqlDataReader sqlQueryResult = comm.ExecuteReader())
                if (sqlQueryResult != null)
                {
                    sqlQueryResult.Read();
                    fileID = Int32.Parse(sqlQueryResult["FileID"].ToString());
                }
            ConnectionClass.CloseConnection();

            dfh.DeleteFile(fileID);
        }
        public void DeleteFile()
        {
            DatabaseFileHandler dfh = new DatabaseFileHandler();

            String fileName = "test.txt";
            String path     = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            String fullPath = System.IO.Path.Combine(path, fileName);

            if (!File.Exists(fullPath))
            {
                FileStream f = File.Create(fullPath);
                f.Close();
            }

            dfh.UploadFile(projectID, File.Open(fullPath, FileMode.Open), fileName);

            int fileID = 0;

            ConnectionClass.OpenConnection();
            MySqlCommand comm = ConnectionClass.con.CreateCommand();

            comm.CommandText = "SELECT FileID FROM storedfiles sf WHERE sf.FileName = @fileName AND sf.ProjectID = @id";
            comm.Parameters.AddWithValue("@fileName", fileName);
            comm.Parameters.AddWithValue("@id", projectID);
            using (MySqlDataReader sqlQueryResult = comm.ExecuteReader())
                if (sqlQueryResult != null)
                {
                    sqlQueryResult.Read();
                    fileID = Int32.Parse(sqlQueryResult["FileID"].ToString());
                }
            ConnectionClass.CloseConnection();

            int i = dfh.DeleteFile(fileID);

            Assert.AreEqual(1, i);
        }
示例#3
0
        public void viewProjectFiles()
        {
            ConnectionClass.OpenConnection();

            //Add the expected record to the database, which will have a title of "test" and a user ID of "1".
            ProjectManager pm = new ProjectManager();
            //Create and upload test file
            DatabaseFileHandler dfh = new DatabaseFileHandler();

            String fileName = "viewProjectFilesTest.txt";
            String path     = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            String fullPath = System.IO.Path.Combine(path, fileName);

            if (!File.Exists(fullPath))
            {
                using (StreamWriter sw = File.CreateText(fullPath))
                {
                    sw.WriteLine("TEST FILE :3");
                    sw.WriteLine("Maybe it needs lots of text????");
                }
                while (!File.Exists(fullPath))
                {
                    Thread.Sleep(1000);
                }
            }

            int expectedRowCount = dfh.UploadFile(projectID, File.Open(fullPath, FileMode.Open), fileName);

            //Actual
            DataTable dt             = pm.viewProjectFiles(projectID);
            int       actualRowCount = dt.Rows.Count;

            Assert.AreEqual(expectedRowCount, actualRowCount);

            File.Delete(fullPath);
            DatabaseFileHandler dbfh = new DatabaseFileHandler();

            ConnectionClass.OpenConnection();
            MySqlCommand comm = ConnectionClass.con.CreateCommand();

            comm.CommandText = "SELECT FileID FROM storedfiles sf WHERE sf.FileName = @fileName AND sf.ProjectID = @id";
            comm.Parameters.AddWithValue("@fileName", fileName);
            comm.Parameters.AddWithValue("@id", projectID);

            int fileID = 0;

            using (MySqlDataReader sqlQueryResult = comm.ExecuteReader())
                if (sqlQueryResult != null)
                {
                    sqlQueryResult.Read();
                    fileID = Int32.Parse(sqlQueryResult["FileID"].ToString());
                }
            ConnectionClass.CloseConnection();

            int i = dfh.DeleteFile(fileID);



            //REMEMBER TO DELETE THE PROJECT RECORDS with pete's method
            newProject.DeleteProject(projectID);
        }