public void TestGetHashExtensionsOnly() { string password = PasswordHasher.GetHash("password", "password"); BaseFileWorker.Write(password, path + "\\" + ".txt"); Assert.Equal(password, BaseFileWorker.ReadAll(path + "\\" + ".txt")); }
public void TestReadlAllNotEqualGetFlag() { MultipleBinaryFlag flag = new MultipleBinaryFlag(2); flag.ResetFlag(1); Assert.AreNotEqual(flag.GetFlag().ToString(), BaseFileWorker.ReadAll(readAllFile)); }
public void TestGetHashEmptyFilename() { string password = PasswordHasher.GetHash("password", "password"); BaseFileWorker.Write(password, path + "\\" + string.Empty); Assert.NotEqual(password, BaseFileWorker.ReadAll(path + "\\" + string.Empty)); }
public void TestGetHashDifferentExtension() { string password = PasswordHasher.GetHash("password", "password"); BaseFileWorker.Write(password, path + "\\" + "test.js"); Assert.Equal(password, BaseFileWorker.ReadAll(path + "\\" + "test.js")); }
public void Test_ReadAll_and_Deleting_from_DB(string filename) { try { string textFromFile = BaseFileWorker.ReadAll(filename); byte[] fileContent = Encoding.ASCII.GetBytes(textFromFile); string filenameTxtFromDB; byte[] fileContentFromDB; Assert.IsTrue(storageDatabase.AddFile(filename, fileContent), $"The file {filename} was not added successfully"); int?fileID = storageDatabase.GetIntBySql("SELECT MAX(FileID) FROM Files"); Assert.IsTrue(storageDatabase.DeleteFile((int)fileID), $"Deleting a file by ID = {fileID} is not successful"); Assert.IsFalse(storageDatabase.GetFile((int)fileID, out filenameTxtFromDB, out fileContentFromDB), $"Even though the file by ID = {fileID} was deleted from the database, the method tells us that it is there."); Assert.IsNull(filenameTxtFromDB, $"Even though the file by ID = {fileID} was deleted from the database, the method returns some value of its name"); Assert.IsNull(fileContentFromDB, $"Although the file by ID = {fileID} is deleted from the database, the method returns some value of its content"); } catch (Exception err) { Assert.Fail(err.Message); } }
public void Test_ReadAll_GetFiles_from_DB_NotNull() { try { string textFromFile = BaseFileWorker.ReadAll(filenameTxt); byte[] fileContent = Encoding.ASCII.GetBytes(textFromFile); const int countFiles = 3; for (int i = 0; i < countFiles; i++) { Assert.IsTrue(storageDatabase.AddFile(filenameTxt, fileContent), $"The file filenameTxt was not added successfully for the {i + 1} time"); } DataTable files = storageDatabase.GetFiles(filenameTxt); Assert.IsNotNull(files, "GetFiles returns zero values even when there are files with the same name in the database"); Assert.AreEqual(files.Rows.Count, countFiles, "The number of records for a certain file name is not returned correctly"); } catch (Exception err) { Assert.Fail(err.Message); } }
public void OneInOutTest_wrongFilePathTests(string path) { try { PasswordHasher.Init("99", 1); string hash = PasswordHasher.GetHash("string"); bool writeRes = BaseFileWorker.Write(hash, path); if (writeRes) { Assert.True(false); } string readRes = BaseFileWorker.ReadAll(path); if (readRes != hash) { Assert.True(false); } Assert.True(false); } catch (Exception) { Assert.True(true); } Assert.True(true); }
public void Test_ReadLines_Push_in_DB_Unicode_Text() { try { string textFromFile = BaseFileWorker.ReadAll(filenameUnicode); byte[] fileContent = Encoding.UTF8.GetBytes(textFromFile); string filenameTxtFromDB; byte[] fileContentFromDB; Assert.IsTrue(storageDatabase.AddFile(filenameUnicode, fileContent), "The file filenameUnicode was not added successfully"); int?fileID = storageDatabase.GetIntBySql("SELECT MAX(FileID) FROM Files"); Assert.IsTrue(storageDatabase.GetFile((int)fileID, out filenameTxtFromDB, out fileContentFromDB), "File filenameUnicode not found in db, although add method returned true"); string textFromDB = Encoding.UTF8.GetString(fileContentFromDB); Assert.AreEqual(filenameUnicode, filenameTxtFromDB, "The names of the files returned by the method and the database do not match"); Assert.AreEqual(textFromFile, textFromDB, "The content of the files returned by the method and the database do not match"); } catch (Exception err) { Assert.Fail(err.Message); } }
public void ReadTest() { //ReadLines string[] lines1 = BaseFileWorker.ReadLines(path + "PasswrodHashTest1.txt"); Assert.AreEqual(lines1[0], first_string); Assert.AreEqual(lines1[1], second_string); Assert.AreEqual(lines1[2], third_string); Assert.AreNotEqual(lines1[0], PasswordHasher.GetHash("pass", "salt", 3)); string[] lines2 = BaseFileWorker.ReadLines(path + "PasswrodHashTest2.txt"); Assert.AreEqual(lines2[0], first_string); Assert.AreEqual(lines2[1], second_string); Assert.AreEqual(lines2[2], third_string); Assert.AreNotEqual(lines2[1], PasswordHasher.GetHash("pass2", "salt", 4)); //ReadAll string[] lines3 = BaseFileWorker.ReadAll(path + "PasswrodHashTest1.txt").Split("\r\n"); Assert.AreEqual(lines3[0], first_string); Assert.AreEqual(lines3[1], second_string); Assert.AreEqual(lines3[2], third_string); Assert.AreNotEqual(lines3[2], PasswordHasher.GetHash("pass3", "salt3", 3)); string[] lines4 = BaseFileWorker.ReadAll(path + "PasswrodHashTest2.txt").Split("\r\n"); Assert.AreEqual(lines4[0], first_string); Assert.AreEqual(lines4[1], second_string); Assert.AreEqual(lines4[2], third_string); Assert.AreNotEqual(lines4[1], PasswordHasher.GetHash("2", "salt2", 4)); }
public void OneInOutTest_trueArgs(string salt, UInt32 adler, string toHash, string fullPathToFile) { try { PasswordHasher.Init(salt, adler); string hash = PasswordHasher.GetHash(toHash); bool writeRes = BaseFileWorker.Write(hash, fullPathToFile); if (!writeRes) { Assert.True(false); } string readRes = BaseFileWorker.ReadAll(fullPathToFile); if (readRes != hash) { Assert.True(false); } } catch (Exception) { Assert.True(false); } Assert.True(true); }
public void AddNotUsualByteCodingFileToDBTest() { Assert.IsTrue(storageDatabaseUtils.AddFile( "🐂🌹🚒.txt", Encoding.ASCII.GetBytes(BaseFileWorker.ReadAll("C:\\FileWorkerTest\\ReadTest\\🐂🌹🚒.txt")) )); }
public void AddASCIIFileToDBTest() { Assert.IsTrue(storageDatabaseUtils.AddFile( "中原 中也.txt", Encoding.ASCII.GetBytes(BaseFileWorker.ReadAll("C:\\FileWorkerTest\\ReadTest\\中原 中也.txt")) )); }
public void AddFileToDBTest() { Assert.IsTrue(storageDatabaseUtils.AddFile( "William Shakespeare.txt", Encoding.ASCII.GetBytes(BaseFileWorker.ReadAll("C:\\FileWorkerTest\\ReadTest\\William Shakespeare.txt")) )); }
public void Test_GetHash() { string hashedPassword = PasswordHasher.GetHash(password); BaseFileWorker.Write(hashedPassword, path + "\\" + "hashedPassword.txt"); Assert.Equal(hashedPassword, BaseFileWorker.ReadAll(path + "\\" + "hashedPassword.txt")); }
public void AddFile_WithContentFromLargeFile_AddsFile_But_TruncatesContent(int contentSizeBytes = MAX_CONTENT_LENGTH_BYTES) { // Arrange StorageDatabaseUtils db = DatabaseHelper.ProvideStorageDatabaseUtils(); string path = InputHelper.GenerateInputFile(contentSizeBytes); string inputContent = BaseFileWorker.ReadAll(path); var inputContentBytes = DEFAULT_ENCODING.GetBytes(inputContent); Console.WriteLine("Working with file " + path + "\nContent: " + inputContent); Console.WriteLine("FileName length: " + path.Length + "\nContent length: " + inputContent.Length + "\nContent length (bytes): " + inputContentBytes.Length); int initialFileCountInDB = db.GetFiles(path).Rows.Count; // initial count of files with specified path in DB string result_fileName; byte[] result_fileContentBytes; // Act bool result = db.AddFile(path, inputContentBytes); 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); // Assert Assert.IsTrue(result); // Entry added to database successfully Assert.AreEqual(initialFileCountInDB + 1, dt.Rows.Count); // Row count increased (new row was added) Assert.AreEqual(path, result_fileName); // File path in DB is equal to inputs Assert.IsTrue(inputContentBytes.Length > result_fileContentBytes.Length); // Content is being truncated because it exceeds maximum length. }
public void Test__adlerMod32BoundaryValue(long value) { string hashedPassword = PasswordHasher.GetHash(password, salt, (uint)value); BaseFileWorker.Write(hashedPassword, path + "\\" + "hashedPassword.txt"); Assert.Equal(hashedPassword, BaseFileWorker.ReadAll(path + "\\" + "hashedPassword.txt")); }
public void Test_ReadAll_by_XML_File() { try { const string pathAbs = "D:\\GitHub\\software-testing\\MaksGovor.FileWorker.Test\\testfile.xml"; const string pathRel = ".\\..\\..\\testfile.xml"; string receivedByFullPath = BaseFileWorker.ReadAll(pathAbs); string receivedByRelativePath = BaseFileWorker.ReadAll(pathRel); const string available = "<note>" + "\r\n<to>Tove</to>" + "\r\n<from>Jani</from>" + "\r\n<heading>Reminder</heading>" + "\r\n<body>Don't forget me this weekend!</body>" + "\r\n</note>"; Assert.AreEqual(available, receivedByFullPath, "The read text by full path from XML file do not match the available result!"); Assert.AreEqual(available, receivedByRelativePath, "The read text by relative path from XML file do not match the available result!"); } catch (Exception err) { Assert.Fail(err.Message); } }
public void ReadAll_FileExist_ReturnData() { string ext = "txt"; string result = BaseFileWorker.ReadAll(pathToLabFolder + "/somefile." + ext); Assert.AreEqual("some text 11\nsome text 22\nsome text 33", result); }
public void Test_ReadAll_by_JSON_File() { try { const string pathAbs = "D:\\GitHub\\software-testing\\MaksGovor.FileWorker.Test\\testfile.json"; const string pathRel = ".\\..\\..\\testfile.json"; string receivedByFullPath = BaseFileWorker.ReadAll(pathAbs); string receivedByRelativePath = BaseFileWorker.ReadAll(pathRel); const string available = "{" + "\r\n \"server\": {" + "\r\n \"transport\": \"http\"," + "\r\n \"address\": \"127.0.0.1\"," + "\r\n \"port\": 8000" + "\r\n }" + "\r\n}"; Assert.AreEqual(available, receivedByFullPath, "The read text by full path from JSON file do not match the available result!"); Assert.AreEqual(available, receivedByRelativePath, "The read text by relative path from JSON file do not match the available result!"); } catch (Exception err) { Assert.Fail(err.Message); } }
public void ReadLinesError() { Assert.Throws <Exception>(() => BaseFileWorker.ReadAll("invalRL.txt")); Assert.Throws <Exception>(() => BaseFileWorker.ReadAll("")); Assert.Throws <Exception>(() => BaseFileWorker.ReadAll(null)); Assert.Throws <Exception>(() => BaseFileWorker.ReadAll("@#%^\\")); }
void TestReadAllforNull() { //read from nothing Assert.Null(BaseFileWorker.ReadAll("")); //read from non-existing file Assert.Null(BaseFileWorker.ReadAll(pathToFiles + "//read_all.non_existed")); }
public void ReadAllFromFile() { Assert.Equal( "To be, or not to be, that is the question:\r\nWhether 'tis nobler in the mind to suffer\r\nThe slings and arrows of outrageous fortune,\r\nOr to take arms against a sea of troubles\r\nAnd by opposing end them.", BaseFileWorker.ReadAll("C:\\FileWokerTest\\ReadTest\\William Shakespeare.txt" )); }
public void TestReadAll() { string fullPathExpected = testsDirFullPath + "\\Test.txt"; string contentReal = BaseFileWorker.ReadAll(fullPathExpected); Assert.Equal("oh shit i'm sorry\r\nsorry for what", contentReal); }
public void TestAddFileNameNull() { string fileFullPath = testsDirFullPath + "\\empty.txt"; string data = BaseFileWorker.ReadAll(fileFullPath); Assert.False(storageDatabaseUtils.AddFile(null, Encoding.UTF8.GetBytes(data))); }
public void WriteFlagFalse() { string mbf = new MultipleBinaryFlag(2, false).GetFlag().ToString(); BaseFileWorker.Write(mbf, @".\testFile1.txt"); Assert.Equal(mbf, BaseFileWorker.ReadAll(@".\testFile1.txt")); }
public void TestReadAllException(string dirname) { try { BaseFileWorker.ReadAll(dirname); } catch (Exception e) { Assert.NotNull(e); } }
public void WriteFlagLongTrue() { string mbf = new MultipleBinaryFlag(10000000000, true).GetFlag().ToString(); BaseFileWorker.Write(mbf, @".\testFile4.txt"); Assert.Equal(mbf, BaseFileWorker.ReadAll(@".\testFile4.txt")); }
public void Test_Write_Read_Hash_Equal() { string password = "******"; string salt = "test_salt"; string passHash = PasswordHasher.GetHash(password, salt); BaseFileWorker.Write(passHash, "C:\\TestFiles\\hashes.txt"); Assert.AreEqual(passHash, BaseFileWorker.ReadAll("C:\\TestFiles\\hashes.txt")); }
public void ReadAllFromSpecificFiles() { Assert.NotNull(BaseFileWorker.ReadAll("C:\\FileWokerTest\\ReadTest\\.travis.yml")); Assert.NotNull(BaseFileWorker.ReadAll("C:\\FileWokerTest\\ReadTest\\pom.xml")); Assert.NotNull(BaseFileWorker.ReadAll("C:\\FileWokerTest\\ReadTest\\system.properties")); Assert.NotNull(BaseFileWorker.ReadAll("C:\\FileWokerTest\\ReadTest\\QuizApplication.java")); Assert.NotNull(BaseFileWorker.ReadAll("C:\\FileWokerTest\\ReadTest\\IIG")); Assert.NotNull(BaseFileWorker.ReadAll("C:\\FileWokerTest\\ReadTest\\IIG.Core.FileWorkingUtils.pdb")); }
public void TestAddFile() { string fileFullPath = testsDirFullPath + "\\test.txt"; BaseFileWorker.Write("oh shit, i'm sorry", fileFullPath); string data = BaseFileWorker.ReadAll(fileFullPath); Assert.True(storageDatabaseUtils.AddFile("1", Encoding.UTF8.GetBytes(data))); }