Exemple #1
0
        public void TestGetFullPath(string filename)
        {
            string fullPathExpected = testsDirFullPath + "\\" + filename;
            string localPath        = new Uri(fullPathExpected).LocalPath;

            Assert.Equal(fullPathExpected, BaseFileWorker.GetFullPath(localPath));
        }
        public void AddFile_WithContentFromReadLinesFirstLine_WithGetFullPath_AddsFileToDatabase()
        {
            // Arrange
            StorageDatabaseUtils db = DatabaseHelper.ProvideStorageDatabaseUtils();
            string contents = BaseFileWorker.ReadLines(FILE_STATIC_INPUT)[0];
            string path = BaseFileWorker.GetFullPath(FILE_STATIC_INPUT);
            var    contentBytes = DEFAULT_ENCODING.GetBytes(contents);
            int    initialFileCountInDB = db.GetFiles(path).Rows.Count;          // initial count of files with specified path
            string result_fileName, result_fileContent; byte[] result_fileContentBytes;

            // Act
            bool      result     = db.AddFile(path, contentBytes);
            DataTable dt         = db.GetFiles(path);
            var       lastRow    = dt.Rows[dt.Rows.Count - 1];
            var       lastFileId = (int)lastRow.ItemArray[0];

            db.GetFile(lastFileId, out result_fileName, out result_fileContentBytes);
            result_fileContent = DEFAULT_ENCODING.GetString(result_fileContentBytes);
            // Assert
            Assert.IsTrue(result);
            Assert.AreEqual(initialFileCountInDB + 1, dt.Rows.Count);
            Assert.AreEqual(path, result_fileName);
            CollectionAssert.AreEqual(contentBytes, result_fileContentBytes);
            Assert.AreEqual(contents, result_fileContent);
        }
Exemple #3
0
 public void GetMultimediaFileFullPath()
 {
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\ms18.mp4", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\ms18.mp4"));
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\DUSTCELL - DERO.mp3", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\DUSTCELL - DERO.mp3"));
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\bell.png", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\bell.png"));
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\pexels-photo-4173624.jpeg", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\pexels-photo-4173624.jpeg"));
 }
Exemple #4
0
        public void GetFullPath(string filename)
        {
            File.WriteAllText(Directory.GetCurrentDirectory() + "/" + filename, filename);
            string path = Path.GetFullPath(Directory.GetCurrentDirectory() + "/" + filename);

            Assert.Equal(path, BaseFileWorker.GetFullPath(filename));
        }
Exemple #5
0
 public void GetSpecialFileFullPath()
 {
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\0524.torrent", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\0524.torrent"));
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\IIG.Core.FileWorkingUtils.pdb", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\IIG.Core.FileWorkingUtils.pdb"));
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\vlc-3.0.10-win64.exe", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\vlc-3.0.10-win64.exe"));
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\-73_1_1.zip", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\-73_1_1.zip"));
 }
Exemple #6
0
 public void GetFullPathForTextFile()
 {
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\0.5.2.docx", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\0.5.2.docx"));
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\Neechy.pptx", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\Neechy.pptx"));
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\test.txt", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\test.txt"));
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\sds.pdf", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\sds.pdf"));
 }
Exemple #7
0
 public void TestGetFullPathReturnValid()
 {
     //get regular file
     Assert.Equal(pathToFiles + "\\a.txt", BaseFileWorker.GetFullPath(pathToFiles + @"\a.txt"));
     Assert.Equal(pathToFiles + "\\a.txt", BaseFileWorker.GetFullPath(@"..\..\..\Files\a.txt"));
     //get file no extension
     Assert.Equal(pathToFiles + "\\IIG", BaseFileWorker.GetFullPath(pathToFiles + @"\IIG"));
     Assert.Equal(pathToFiles + "\\IIG", BaseFileWorker.GetFullPath(@"..\..\..\Files\IIG"));
     //get file with space in name
     Assert.Equal(pathToFiles + "\\I IG.txt", BaseFileWorker.GetFullPath(pathToFiles + @"\I IG.txt"));
     Assert.Equal(pathToFiles + "\\I IG.txt", BaseFileWorker.GetFullPath(@"..\..\..\Files\I IG.txt"));
     //with cyrilic in nane
     Assert.Equal(pathToFiles + "\\абв.txt", BaseFileWorker.GetFullPath(pathToFiles + @"\абв.txt"));
     Assert.Equal(pathToFiles + "\\абв.txt", BaseFileWorker.GetFullPath(@"..\..\..\Files\абв.txt"));
     //with ieroglif
     Assert.Equal(pathToFiles + "\\お母様.txt", BaseFileWorker.GetFullPath(pathToFiles + @"\お母様.txt"));
     Assert.Equal(pathToFiles + "\\お母様.txt", BaseFileWorker.GetFullPath(@"..\..\..\Files\お母様.txt"));
     //with few dots in name
     Assert.Equal(pathToFiles + "\\a.b.c.txt", BaseFileWorker.GetFullPath(pathToFiles + @"\a.b.c.txt"));
     Assert.Equal(pathToFiles + "\\a.b.c.txt", BaseFileWorker.GetFullPath(@"..\..\..\Files\a.b.c.txt"));
     //with smiles
     Assert.Equal(pathToFiles + "\\😅.txt", BaseFileWorker.GetFullPath(pathToFiles + @"\😅.txt"));
     Assert.Equal(pathToFiles + "\\😅.txt", BaseFileWorker.GetFullPath(@"..\..\..\Files\😅.txt"));
     //with different extensions
     Assert.Equal(pathToFiles + "\\a.csc", BaseFileWorker.GetFullPath(pathToFiles + @"\a.csc"));
     Assert.Equal(pathToFiles + "\\a.csc", BaseFileWorker.GetFullPath(@"..\..\..\Files\a.csc"));
     Assert.Equal(pathToFiles + "\\a.docx", BaseFileWorker.GetFullPath(pathToFiles + @"\a.docx"));
     Assert.Equal(pathToFiles + "\\a.docx", BaseFileWorker.GetFullPath(@"..\..\..\Files\a.docx"));
     Assert.Equal(pathToFiles + "\\a.mp4", BaseFileWorker.GetFullPath(@"..\..\..\Files\a.mp4"));
     Assert.Equal(pathToFiles + "\\a.mp4", BaseFileWorker.GetFullPath(pathToFiles + @"\a.mp4"));
     Assert.Equal(pathToFiles + "\\a.pptx", BaseFileWorker.GetFullPath(pathToFiles + @"\a.pptx"));
     Assert.Equal(pathToFiles + "\\a.pptx", BaseFileWorker.GetFullPath(@"..\..\..\Files\a.pptx"));
     Assert.Equal(pathToFiles + "\\a.torrent", BaseFileWorker.GetFullPath(pathToFiles + @"\a.torrent"));
     Assert.Equal(pathToFiles + "\\a.torrent", BaseFileWorker.GetFullPath(@"..\..\..\Files\a.torrent"));
 }
Exemple #8
0
 public void GetFullPathWithSpecificAlphabetName()
 {
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\신의 탑.txt", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\신의 탑.txt"));
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\鋼の錬金術師.txt", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\鋼の錬金術師.txt"));
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\นรางามิ เทวดาขาจร.txt", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\นรางามิ เทวดาขาจร.txt"));
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\Тест єії'.txt", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\Тест єії'.txt"));
 }
Exemple #9
0
        public void GetFullPathError()
        {
            Assert.Throws <ArgumentException>(() => BaseFileWorker.GetFullPath(""));
            Assert.Throws <ArgumentNullException>(() => BaseFileWorker.GetFullPath(null));
            Assert.Throws <Exception>(() => BaseFileWorker.GetFullPath("noSuchFile.txt"));

            Assert.Throws <Exception>(() => BaseFileWorker.GetFullPath("inval:File.txt"));
        }
Exemple #10
0
 public void TestGetFullPathException(string filename)
 {
     try {
         BaseFileWorker.GetFullPath(filename);
     } catch (Exception e) {
         Assert.NotNull(e);
     }
 }
Exemple #11
0
 public void Test_GetFullPath_Different_Types()
 {
     Assert.AreEqual("C:\\TestFiles\\1.txt", BaseFileWorker.GetFullPath("C:\\TestFiles\\1.txt"));
     Assert.AreEqual("C:\\TestFiles\\1.bmp", BaseFileWorker.GetFullPath("C:\\TestFiles\\1.bmp"));
     Assert.AreEqual("C:\\TestFiles\\1.mpp", BaseFileWorker.GetFullPath("C:\\TestFiles\\1.mpp"));
     Assert.AreEqual("C:\\TestFiles\\1.odg", BaseFileWorker.GetFullPath("C:\\TestFiles\\1.odg"));
     Assert.AreEqual("C:\\TestFiles\\1.rar", BaseFileWorker.GetFullPath("C:\\TestFiles\\1.rar"));
     Assert.AreEqual("C:\\TestFiles\\1.rtf", BaseFileWorker.GetFullPath("C:\\TestFiles\\1.rtf"));
     Assert.AreEqual("C:\\TestFiles\\1.mp4", BaseFileWorker.GetFullPath("C:\\TestFiles\\1.mp4"));
 }
Exemple #12
0
        public void GetFullPath_ReturnsNullNonExistentFile(string file)
        {
            try { File.Delete(file); }             // make sure file doesn't exist
            catch (Exception e) { }
            Action codeToTest = () =>
            {
                string results = BaseFileWorker.GetFullPath(file);
                Assert.Null(results);
            };
            var ex = Record.Exception(codeToTest);

            Assert.Null(ex);
        }
Exemple #13
0
        public void Test_GetFullPath_NoExisting_RelativePath()
        {
            try
            {
                const string pathRel  = ".\\..\\..\\NoExist.txt";
                string       received = BaseFileWorker.GetFullPath(pathRel);

                Assert.IsNull(received, "The full path retrieved from GetFullPath by relative path " +
                              "must be NULL on a path that does not exist!");
            }
            catch (Exception err)
            {
                Assert.Fail(err.Message);
            }
        }
Exemple #14
0
        public void Test_GetFullPath_EmptyPath()
        {
            try
            {
                const string pathEmpty = "";
                string       received  = BaseFileWorker.GetFullPath(pathEmpty);

                Assert.IsNull(received, "The full path retrieved from GetFullPath by empty path " +
                              "must be NULL");
            }
            catch (Exception err)
            {
                Assert.Fail(err.Message);
            }
        }
Exemple #15
0
 public void TestGetFullPathReturnNull()
 {
     //get path to files without file
     Assert.Null(BaseFileWorker.GetFullPath(pathToFiles));
     Assert.Null(BaseFileWorker.GetFullPath(@"..\..\..\Files\"));
     //get path to folder
     Assert.Null(BaseFileWorker.GetFullPath(pathToFiles + "\\empty"));
     Assert.Null(BaseFileWorker.GetFullPath(@"..\..\..\Files\empty"));
     //get path to non-existing file
     Assert.Null(BaseFileWorker.GetFullPath(pathToFiles + "\\empty\\file.txt"));
     Assert.Null(BaseFileWorker.GetFullPath(@"..\..\..\Files\empty\file.txt"));
     //get path to file bur forgot to type extension
     Assert.Null(BaseFileWorker.GetFullPath(pathToFiles + "\\test"));
     Assert.Null(BaseFileWorker.GetFullPath(@"..\..\..\Files\test"));
 }
Exemple #16
0
        public void Test_GetFullPath_NoExisting_FullPath()
        {
            try
            {
                const string pathAbs  = "D:\\GitHub\\software-testing\\MaksGovor.FileWorker.Test\\NoExist.txt";
                string       received = BaseFileWorker.GetFullPath(pathAbs);

                Assert.IsNull(received, "The full path retrieved from GetFullPath by full path " +
                              "must be NULL on a path that does not exist!");
            }
            catch (Exception err)
            {
                Assert.Fail(err.Message);
            }
        }
Exemple #17
0
        public void GetFullPathFromPath(string filename)
        {
            string path;

            if (filename != "")
            {
                File.WriteAllText(Directory.GetCurrentDirectory() + "/" + filename, filename);
                path = Path.GetFullPath(Directory.GetCurrentDirectory() + "/" + filename);
            }
            else
            {
                path = Path.GetFullPath(Directory.GetCurrentDirectory());
            }
            Assert.Equal(path, BaseFileWorker.GetFullPath(path));
        }
Exemple #18
0
        public void Test_GetFullPath_Existing_RelativePath()
        {
            try
            {
                const string pathAbs  = "D:\\GitHub\\software-testing\\MaksGovor.FileWorker.Test\\testfile.txt";
                const string pathRel  = ".\\..\\..\\testfile.txt";
                string       received = BaseFileWorker.GetFullPath(pathRel);

                Assert.AreEqual(pathAbs, received, "The full path retrieved from GetFullPath by relative path " +
                                "must be NULL on a path that does not exist!");
            }
            catch (Exception err)
            {
                Assert.Fail(err.Message);
            }
        }
Exemple #19
0
        public void GetFullPath_ReadsExistingFilePath(string file)
        {
            File.WriteAllText(file, "");
            string expected   = $"{CurrentDirectory}\\{file}";
            string results    = null;
            Action codeToTest = () =>
            {
                results = BaseFileWorker.GetFullPath(file);
            };
            var ex = Record.Exception(codeToTest);

            Assert.Null(ex);
            Assert.NotNull(results);
            Assert.Equal(expected, results);
            Assert.EndsWith(file, results);
            File.Delete(file);
        }
        public void DeleteFile_WithExistingPathInDB_UsingGetFullPath_DeletesEntry(int fileNameSize = -1, int contentSize = MAX_CONTENT_LENGTH_BYTES)
        {
            // Arrange
            if (fileNameSize < 0)
            {
                fileNameSize = MAX_FILE_LENGTH;
            }
            string fileName = InputHelper.GenerateInputFile(size: contentSize, fileNameSize: fileNameSize);
            string content  = BaseFileWorker.ReadAll(fileName);

            byte[] fileContentBytes = DEFAULT_ENCODING.GetBytes(content);
            Console.WriteLine("Working with " + fileName + ".\nContent: " + content);
            Console.WriteLine("FileName length: " + fileName.Length + "\nContent length: " + content.Length + "\nContent length (bytes): " + fileContentBytes.Length);
            BaseFileWorker.Write(content, fileName);
            string fullPath = BaseFileWorker.GetFullPath(fileName);
            string result_fileName; byte[] result_fileContentBytes;

            StorageDatabaseUtils db = DatabaseHelper.ProvideStorageDatabaseUtils();

            db.AddFile(fullPath, fileContentBytes);
            DataTable dt = db.GetFiles(fullPath);
            int       initialEntryCount = dt.Rows.Count;
            var       lastRow           = dt.Rows[dt.Rows.Count - 1];
            var       lastFileId        = (int)lastRow.ItemArray[0];

            // Act
            db.GetFile(lastFileId, out result_fileName, out result_fileContentBytes);
            bool success          = db.DeleteFile(lastFileId);
            int  resultEntryCount = db.GetFiles(fullPath).Rows.Count;

            // Assert
            Assert.IsTrue(success);
            Assert.AreEqual(initialEntryCount - 1, resultEntryCount);
            CollectionAssert.AreEqual(fileContentBytes, result_fileContentBytes);
            // Cleanup
            File.Delete(fullPath);
            Console.WriteLine("File was deleted from database and from file system.");
        }
Exemple #21
0
    public void GetFilePath_FileNotExists_ReturnNull()
    {
        string result = BaseFileWorker.GetFullPath(pathToLabFolder + "/somefile2.txt");

        Assert.AreEqual(null, result);
    }
Exemple #22
0
 public void GetFullPathWithAltCodesName()
 {
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\☺☻♥♫►.txt", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\☺☻♥♫►.txt"));
 }
Exemple #23
0
 public void GetFilePathWithoutFullPath()
 {
     Assert.Null(BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest"));
 }
Exemple #24
0
 public void Test_GetFullPath_No_Extension()
 {
     Assert.IsNull(BaseFileWorker.GetFullPath("C:\\TestFiles\\1"));
 }
Exemple #25
0
 public void GetFullPathWithoutExtencion()
 {
     Assert.Equal("C:\\FileWokerTest\\GetFilesSomethingTest\\IIG", BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\IIG"));
 }
Exemple #26
0
 public void Test_GetFullPath_Non_Existent_File()
 {
     Assert.IsNull(BaseFileWorker.GetFullPath("C:\\TestFiles\\2.txt"));
 }
Exemple #27
0
 public void Test_GetFullPath_Empty_Path()
 {
     Assert.IsNull(BaseFileWorker.GetFullPath(""));
 }
Exemple #28
0
    public void GetFilePath_FileExists_ReturnFileName()
    {
        string result = BaseFileWorker.GetFullPath(pathToLabFolder + "/somefile.txt");

        Assert.AreEqual(pathToLabFolder + "/somefile.txt", result);
    }
Exemple #29
0
 public void GetFullPathFOrNotExistingFile()
 {
     Assert.Null(BaseFileWorker.GetFullPath("C:\\FileWokerTest\\GetFilesSomethingTest\\void"));
 }