Пример #1
0
        public void getNotUsualByteCodingFileFromDBTest()
        {
            string filename_out;

            byte[] content_out;

            Assert.IsTrue(storageDatabaseUtils.GetFile(7, out filename_out, out content_out));
            Assert.AreEqual("🐂🌹🚒.txt", filename_out);
            Assert.IsTrue(Encoding.ASCII.GetBytes(testStr3).SequenceEqual(content_out));
            Assert.IsTrue(
                Encoding.ASCII.GetBytes(BaseFileWorker.ReadAll("C:\\FileWorkerTest\\ReadTest\\🐂🌹🚒.txt")).SequenceEqual(content_out)
                );
        }
        public void CreateFlag_DefaultValue_BiggerThanMinLenght()
        {
            var flag = new MultipleBinaryFlag(minLength + 1);

            var expected = flag.ToString();
            var result   = BaseFileWorker.Write(expected, filePath);

            Assert.True(result);

            var actual = BaseFileWorker.ReadAll(filePath);

            Assert.Equal(expected, actual);
        }
        public void CreateFlag_TrueValue()
        {
            var flag = new MultipleBinaryFlag(length, true);

            var expected = flag.ToString();
            var result   = BaseFileWorker.Write(expected, filePath);

            Assert.True(result);

            var actual = BaseFileWorker.ReadAll(filePath);

            Assert.Equal(expected, actual);
        }
Пример #4
0
        public void TryWrite_EmptyHash()
        {
            string password = "";
            string filePath = "test.txt";
            int    attempts = 3;
            string newHash  = PasswordHasher.GetHash(password);
            bool   result   = BaseFileWorker.TryWrite(newHash, filePath, attempts);

            Assert.True(result);
            string data = BaseFileWorker.ReadAll(filePath);

            Assert.Equal(newHash, data);
        }
Пример #5
0
 public void ReadLinesFromFile()
 {
     Assert.Equal(
         new string[] {
         "To be, or not to be, that is the question:",
         "Whether 'tis nobler in the mind to suffer",
         "The slings and arrows of outrageous fortune,",
         "Or to take arms against a sea of troubles",
         "And by opposing end them."
     },
         BaseFileWorker.ReadLines("C:\\FileWokerTest\\ReadTest\\William Shakespeare.txt"
                                  ));
 }
Пример #6
0
        public void ReadAll(string name, string content)
        {
            string path_ra = Directory.GetCurrentDirectory() + "/" + name;

            if (content != "")
            {
                File.WriteAllText(path_ra, content);
            }
            else
            {
                content = System.Text.Encoding.Default.GetString(File.ReadAllBytes(path_ra));
            }
            Assert.Equal(content, BaseFileWorker.ReadAll(path_ra));
        }
Пример #7
0
        public void Test_GetFlag_Disposed_ReAssigned_True()
        {
            MultipleBinaryFlag multipleBinaryFlag = new MultipleBinaryFlag(3);

            multipleBinaryFlag.Dispose();
            multipleBinaryFlag = new MultipleBinaryFlag(3);
            var result = multipleBinaryFlag.GetFlag();

            BaseFileWorker.Write(result.ToString(), path);
            string fromFile = BaseFileWorker.ReadAll(path);

            Assert.Equal(Boolean.TrueString, fromFile);
            Assert.True(result);
        }
Пример #8
0
        public void TestGetFlagFalseAfterSetFlag()
        {
            string expected = "True";

            MultipleBinaryFlag flag = new MultipleBinaryFlag(44, false);

            for (uint i = 0; i < 44; i++)
            {
                flag.SetFlag(i);
            }

            Assert.IsTrue(BaseFileWorker.Write(flag.GetFlag().ToString(), testFile));
            Assert.AreEqual(expected, File.ReadAllText(testFile));
        }
Пример #9
0
        public void TestReadLines()
        {
            MultipleBinaryFlag[] binaryFlags = { new MultipleBinaryFlag(2, true),
                                                 new MultipleBinaryFlag(2, false) };

            string[] results = BaseFileWorker.ReadLines(filledFile);

            Assert.AreEqual(binaryFlags.Length, results.Length);

            for (int i = 0; i < binaryFlags.Length; i++)
            {
                Assert.AreEqual(binaryFlags[i].GetFlag().ToString(), results[i]);
            }
        }
Пример #10
0
    public void MkDir_ReturnFolderPath()
    {
        string name = Lab1_FileWorkerTests.RandName("somefolder");

        // Create new folder
        string result = BaseFileWorker.MkDir(pathToLabFolder + "/" + name);

        Assert.AreEqual(pathToLabFolder + "/" + name, result);

        // Return exists folder
        result = BaseFileWorker.MkDir(pathToLabFolder + "/" + name);

        Assert.AreEqual(pathToLabFolder + "/" + name, result);
    }
Пример #11
0
        public void WriteFileToDisk()
        {
            MultipleBinaryFlag first  = new MultipleBinaryFlag(7, true);
            MultipleBinaryFlag second = new MultipleBinaryFlag(10, false);

            first.ResetFlag(0);
            first.ResetFlag(2);
            first.ResetFlag(5);
            second.SetFlag(1);
            second.SetFlag(3);
            second.SetFlag(7);
            second.SetFlag(9);
            Assert.IsTrue(BaseFileWorker.Write(first.ToString() + " " + first.GetFlag() + "\r\n" + second.ToString() + " " + second.GetFlag(), path + "writedFileWithFlag.txt"));
        }
Пример #12
0
        public void Write_ModerateHash()
        {
            string password = "******";
            string salt     = "salt";
            uint   adler    = 312;
            string filePath = "test.txt";
            string newHash  = PasswordHasher.GetHash(password, salt, adler);
            bool   result   = BaseFileWorker.Write(newHash, filePath);

            Assert.True(result);
            string data = BaseFileWorker.ReadAll(filePath);

            Assert.Equal(newHash, data);
        }
Пример #13
0
        public void getFileFromDBTest()
        {
            string filename_out;

            byte[] content_out;

            Assert.IsTrue(storageDatabaseUtils.GetFile(5, out filename_out, out content_out));
            Assert.AreEqual("William Shakespeare.txt", filename_out);
            Assert.AreEqual(testStr1, Encoding.ASCII.GetString(content_out, 0, content_out.Length));
            Assert.AreEqual(
                BaseFileWorker.ReadAll("C:\\FileWorkerTest\\ReadTest\\William Shakespeare.txt"),
                Encoding.ASCII.GetString(content_out, 0, content_out.Length)
                );
        }
Пример #14
0
        void TryCopy_RewriteEnabled_ReturnsTrue_When_DestinationExists()
        {
            string from = TEMP_FILE_PATH_IN;
            string to   = TEMP_FILE_PATH_OUT;
            string data = InputHelper.GenerateData(100);

            File.WriteAllText(from, data);
            File.WriteAllText(to, "Hello world");
            var result = BaseFileWorker.TryCopy(from, to, true);

            Assert.True(result);
            Assert.Equal(data, File.ReadAllText(to));             // text should have been overriden with data
            File.Delete(from); File.Delete(to);
        }
Пример #15
0
        public void TryCopyError()
        {
            string to   = Directory.GetCurrentDirectory() + "toEr.txt";
            string from = Directory.GetCurrentDirectory() + "fromEr.txt";

            File.WriteAllText(to, "written to to");
            File.WriteAllText(from, "written to from");
            Assert.Throws <Exception>(() => BaseFileWorker.TryCopy(Directory.GetCurrentDirectory() + "not_valid_from.txt", to, true, 5));
            Assert.Throws <Exception>(() => BaseFileWorker.TryCopy(Directory.GetCurrentDirectory() + "not_valid_from", to, true, 5));

            Assert.Throws <Exception>(() => BaseFileWorker.TryCopy(from, Directory.GetCurrentDirectory() + "not_valid_to.txt", true, 5));
            Assert.Throws <Exception>(() => BaseFileWorker.TryCopy(from, Directory.GetCurrentDirectory() + "not_valid_to", true, 5));
            Assert.Throws <Exception>(() => BaseFileWorker.TryCopy(from, to, true, -1));
        }
Пример #16
0
        public void Test_ReadLines_by_Null_FilePath()
        {
            try
            {
                const string pathNull           = null;
                string[]     receivedByNullPath = BaseFileWorker.ReadLines(pathNull);

                Assert.IsNull(receivedByNullPath, "The readLines does not return null when a null path is specified!");
            }
            catch (Exception err)
            {
                Assert.Fail(err.Message);
            }
        }
Пример #17
0
        public void Test_MkDir_by_Directory_EmptyPath()
        {
            try
            {
                const string dirEmptyPath = null;
                string       received     = BaseFileWorker.MkDir(dirEmptyPath);

                Assert.IsNull(received, "Unable to create a directory with a empty path!");
            }
            catch (Exception err)
            {
                Assert.Fail(err.Message);
            }
        }
Пример #18
0
        public void Test_ReadAll_by_Empty_FilePath()
        {
            try
            {
                const string pathNull           = "";
                string       receivedByNullPath = BaseFileWorker.ReadAll(pathNull);

                Assert.IsNull(receivedByNullPath, "The readAll does not return null when a empty string path is specified!");
            }
            catch (Exception err)
            {
                Assert.Fail(err.Message);
            }
        }
Пример #19
0
        public void Test_Constructor()
        {
            try
            {
                BaseFileWorker baseFileWorker1 = new BaseFileWorker();
                BaseFileWorker baseFileWorker2 = new BaseFileWorker();

                Assert.IsNotNull(baseFileWorker1, "Instance of BaseFileWorker is null object!");
                Assert.AreNotEqual(baseFileWorker1, baseFileWorker2, "Different instances of BaseFileWorker are equal!");
            } catch (Exception err)
            {
                Assert.Fail(err.Message);
            }
        }
Пример #20
0
 public void GetPathReturnValidTest()
 {
     //regular
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(pathToFiles + "\\a.txt"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(@"..\..\..\Files\a.txt"));
     //file with no extension
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(pathToFiles + @"\IIG"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(@"..\..\..\Files\IIG"));
     //get file path with space in file name
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(pathToFiles + @"\I IG.txt"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(@"..\..\..\Files\I IG.txt"));
     //get file path with space in folder name
     Assert.Equal(pathToFiles + "\\II G", BaseFileWorker.GetPath(pathToFiles + @"\II G\test.txt"));
     Assert.Equal(pathToFiles + "\\II G", BaseFileWorker.GetPath(@"..\..\..\Files\II G\test.txt"));
     //with cyrilic in file name
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(pathToFiles + @"\абв.txt"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(@"..\..\..\Files\абв.txt"));
     //with cyrilic in folder name
     Assert.Equal(pathToFiles + "\\йцуке", BaseFileWorker.GetPath(pathToFiles + @"\йцуке\tset.txt"));
     Assert.Equal(pathToFiles + "\\йцуке", BaseFileWorker.GetPath(@"..\..\..\Files\йцуке\tset.txt"));
     //with ieroglif in file name
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(pathToFiles + @"\お母様.txt"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(@"..\..\..\Files\お母様.txt"));
     //with ieroglif in folder name
     Assert.Equal(pathToFiles + "\\到着した", BaseFileWorker.GetPath(pathToFiles + @"\到着した\test.txt"));
     Assert.Equal(pathToFiles + "\\到着した", BaseFileWorker.GetPath(@"..\..\..\Files\到着した\test.txt"));
     //with few dots in file name
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(pathToFiles + @"\a.b.c.txt"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(@"..\..\..\Files\a.b.c.txt"));
     //with few dots in folder name
     Assert.Equal(pathToFiles + "\\dot.dot", BaseFileWorker.GetPath(pathToFiles + @"\dot.dot\test.txt"));
     Assert.Equal(pathToFiles + "\\dot.dot", BaseFileWorker.GetPath(@"..\..\..\Files\dot.dot\test.txt"));
     //with smiles in file name
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(pathToFiles + @"\😅.txt"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(@"..\..\..\Files\😅.txt"));
     //with smiles in folder name
     Assert.Equal(pathToFiles + "\\😂😂", BaseFileWorker.GetPath(pathToFiles + @"\😂😂\test.txt"));
     Assert.Equal(pathToFiles + "\\😂😂", BaseFileWorker.GetPath(@"..\..\..\Files\😂😂\test.txt"));
     //with different extensions
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(pathToFiles + @"\a.csc"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(@"..\..\..\Files\a.csc"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(pathToFiles + @"\a.docx"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(@"..\..\..\Files\a.docx"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(@"..\..\..\Files\a.mp4"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(pathToFiles + @"\a.mp4"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(pathToFiles + @"\a.pptx"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(@"..\..\..\Files\a.pptx"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(pathToFiles + @"\a.torrent"));
     Assert.Equal(pathToFiles, BaseFileWorker.GetPath(@"..\..\..\Files\a.torrent"));
 }
Пример #21
0
        public void Test_GetFileName_NullPath()
        {
            try
            {
                const string pathNull = null;
                string       received = BaseFileWorker.GetFileName(pathNull);

                Assert.IsNull(received, "The filename retrieved from GetFileName by null path " +
                              "must be NULL!");
            }
            catch (Exception err)
            {
                Assert.Fail(err.Message);
            }
        }
Пример #22
0
        public void Test_GetFileName_NoExisting_RelativePath()
        {
            try
            {
                const string pathRel  = ".\\..\\..\\NoExist.txt";
                string       received = BaseFileWorker.GetFileName(pathRel);

                Assert.IsNull(received, "The filename retrieved from GetFileName by relative path " +
                              "must be NULL on a path that does not exist!");
            }
            catch (Exception err)
            {
                Assert.Fail(err.Message);
            }
        }
Пример #23
0
        public void Test_GetFileName_NoExisting_FullPath()
        {
            try
            {
                const string pathAbs  = "D:\\GitHub\\software-testing\\MaksGovor.FileWorker.Test\\NoExist.txt";
                string       received = BaseFileWorker.GetFileName(pathAbs);

                Assert.IsNull(received, "The filename retrieved from GetFileName by full path " +
                              "must be NULL on a path that does not exist!");
            }
            catch (Exception err)
            {
                Assert.Fail(err.Message);
            }
        }
Пример #24
0
        public void Test_GetPath_EmptyPath()
        {
            try
            {
                const string pathEmpty = "";
                string       received  = BaseFileWorker.GetPath(pathEmpty);

                Assert.IsNull(received, "The filename retrieved from GetFileName by empty path " +
                              "must be NULL!");
            }
            catch (Exception err)
            {
                Assert.Fail(err.Message);
            }
        }
Пример #25
0
        public void Test_GetFullPath_Existing_FullPath()
        {
            try
            {
                const string pathAbs  = "D:\\GitHub\\software-testing\\MaksGovor.FileWorker.Test\\testfile.txt";
                string       received = BaseFileWorker.GetFullPath(pathAbs);

                Assert.AreEqual(pathAbs, 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);
            }
        }
Пример #26
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"));
 }
Пример #27
0
 public void GetPathReturnNullTest()
 {
     //without file
     Assert.Null(BaseFileWorker.GetPath(pathToFiles));
     Assert.Null(BaseFileWorker.GetPath(@"..\..\..\Files"));
     //folder
     Assert.Null(BaseFileWorker.GetPath(pathToFiles + "\\empty"));
     Assert.Null(BaseFileWorker.GetPath(@"..\..\..\Files\empty"));
     //non-existed file
     Assert.Null(BaseFileWorker.GetPath(pathToFiles + "\\empty\\test.txt"));
     Assert.Null(BaseFileWorker.GetPath(@"..\..\..\Files\empty\test.txt"));
     //file but forgot to type extension
     Assert.Null(BaseFileWorker.GetPath(pathToFiles + "\\test"));
     Assert.Null(BaseFileWorker.GetPath(@"..\..\..\Files\test"));
 }
Пример #28
0
        public void Test_GetFlag_DefaultFalseValue_FullSet_True()
        {
            MultipleBinaryFlag multipleBinaryFlag = new MultipleBinaryFlag(3, false);

            multipleBinaryFlag.SetFlag(1);
            multipleBinaryFlag.SetFlag(0);
            multipleBinaryFlag.SetFlag(2);
            var result = multipleBinaryFlag.GetFlag();

            BaseFileWorker.Write(result.ToString(), path);
            string fromFile = BaseFileWorker.ReadAll(path);

            Assert.Equal(Boolean.TrueString, fromFile);
            Assert.True(result);
        }
Пример #29
0
        void Write_WorksCorrect_NewFile()
        {
            string path = TEMP_FILE_PATH_OUT;

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            var data   = InputHelper.GenerateData(100);
            var result = BaseFileWorker.Write(data, path);

            Assert.True(result);
            Assert.Equal(data, File.ReadAllText(path));
            File.Delete(path);
        }
Пример #30
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));
        }