示例#1
0
        public void ComponentCopyFileAction_Copies_File_Not_Overwriting_Events_Message()
        {
            // Copy First File
            string fileNameCopied = "ComponentCopyFileAction_Copies_File_Not_Overwriting_With_Message_Event.txt";

            _pathCopied = Path.Combine(_assemblyFolder, fileNameCopied);

            FileLibrary.ComponentCopyFileAction(_pathOriginal, _pathCopied, overWriteFile: false);

            // Test that file exists and modify file
            bool fileExists = File.Exists(_pathCopied);

            Assert.IsTrue(fileExists);

            using (StreamWriter sw = File.AppendText(_pathCopied))
            {
                sw.WriteLine("Test Text");
            }

            // Set up event listener
            var wasCalled = false;

            FileLibrary.Messenger += (e) => wasCalled = true;

            // Copy second time
            string expectedPromptText = "File Cannot be Overwritten";

            FileLibrary.ComponentCopyFileAction(_pathOriginal, _pathCopied,
                                                overWriteFile: false,
                                                promptMessage: expectedPromptText);

            Assert.IsTrue(wasCalled);
        }
示例#2
0
        public void ComponentCopyFileAction_Copies_File_Not_Overwriting_With_No_Message()
        {
            // Copy First File
            string fileNameCopied = "ComponentCopyFileAction_Copies_File_Not_Overwriting_With_No_Message.txt";

            _pathCopied = Path.Combine(_assemblyFolder, fileNameCopied);

            FileLibrary.ComponentCopyFileAction(_pathOriginal, _pathCopied, overWriteFile: false);

            // Test that file exists and modify file
            bool fileExists = File.Exists(_pathCopied);

            Assert.IsTrue(fileExists);

            using (StreamWriter sw = File.AppendText(_pathCopied))
            {
                sw.WriteLine("Test Text");
            }

            // Copy second time, and check that modification is no longer present
            FileLibrary.ComponentCopyFileAction(_pathOriginal, _pathCopied, overWriteFile: false);
            string[] readText = File.ReadAllLines(_pathCopied);
            int      expectedNumberOfLines = 1;

            Assert.AreEqual(expectedNumberOfLines, readText.Length);
        }
示例#3
0
        public void ComponentCopyFileAction_Copies_Blank_Source_Path()
        {
            string fileNameCopied = "ComponentCopyFileAction_Copies_Blank_Source_Path.txt";

            _pathCopied = Path.Combine(_assemblyFolder, fileNameCopied);
            FileLibrary.ComponentCopyFileAction("", _pathCopied, overWriteFile: false);

            Assert.IsFalse(File.Exists(_pathCopied));
        }
示例#4
0
        public void ComponentCopyFileAction_Copies_New_File_Under_Old_Name_To_New_Directory()
        {
            string newDirectory = Path.Combine(_assemblyFolder, "newDirectory");

            _pathCopied = Path.Combine(newDirectory, _fileNameOriginal);

            FileLibrary.ComponentCopyFileAction(_pathOriginal, _pathCopied, overWriteFile: false);

            Assert.IsTrue(File.Exists(_pathCopied));
        }
示例#5
0
        public void ComponentCopyFileAction_Copies_New_File_Under_New_Name()
        {
            string fileNameCopied = "ComponentCopyFileAction_Copies_New_File_Under_New_Name.txt";

            _pathCopied = Path.Combine(_assemblyFolder, fileNameCopied);

            FileLibrary.ComponentCopyFileAction(_pathOriginal, _pathCopied, overWriteFile: false);

            Assert.IsTrue(File.Exists(_pathCopied));
        }
示例#6
0
        public void ComponentCopyFileAction_Events_Log_From_Exception()
        {
            // Set up event listener
            var wasCalled = false;

            FileLibrary.Log += (e) => wasCalled = true;

            FileLibrary.ComponentCopyFileAction(_pathOriginal, "", overWriteFile: false);

            Assert.IsTrue(wasCalled);
        }
示例#7
0
        public void ComponentCopyFileAction_Copies_NonExisting_File()
        {
            string nonExistingFilePath = Path.Combine(_assemblyFolder, "NonExistingFile.txt");

            string fileNameCopied = "ComponentCopyFileAction_Copies_NonExisting_File.txt";

            _pathCopied = Path.Combine(_assemblyFolder, fileNameCopied);

            FileLibrary.ComponentCopyFileAction(nonExistingFilePath, _pathCopied, overWriteFile: false);

            Assert.IsFalse(File.Exists(_pathCopied));
        }
示例#8
0
        public void DeleteFile_Existing_ReadOnly_Not_Overwritten_Does_Not_Delete_File_And_Returns_False()
        {
            string fileNameCopied = "DeleteFile_Existing_ReadOnly_Not_Overwritten_Does_Not_Delete_File_And_Returns_False.txt";

            _pathCopied = Path.Combine(_assemblyFolder, fileNameCopied);

            FileLibrary.ComponentCopyFileAction(_pathOriginal, _pathCopied, overWriteFile: false);
            Assert.IsTrue(File.Exists(_pathCopied));

            File.SetAttributes(_pathCopied, FileAttributes.ReadOnly);

            Assert.IsFalse(FileLibrary.DeleteFile(_pathCopied));
            Assert.IsTrue(File.Exists(_pathCopied));
        }
示例#9
0
        public void DeleteFile_Existing_Deletes_File_And_Returns_True()
        {
            //string fileNameCopied = "DeleteFile_Existing_Deletes_File_And_Returns_True.txt";
            string fileNameCopied = "DeleteFile_1.txt";

            _pathCopied = Path.Combine(_assemblyFolder, fileNameCopied);

            FileLibrary.ComponentCopyFileAction(_pathOriginal, _pathCopied, overWriteFile: true);

            Assert.IsTrue(File.Exists(_pathCopied));

            Assert.IsTrue(FileLibrary.DeleteFile(_pathCopied));
            Assert.IsFalse(File.Exists(_pathCopied));
        }
示例#10
0
        public void ComponentDeleteFileAction_Events_Log_From_Exception()
        {
            string fileNameCopied = "ComponentDeleteFileAction_Events_Log_From_Exception.txt";

            _pathCopied = Path.Combine(_assemblyFolder, fileNameCopied);

            FileLibrary.ComponentCopyFileAction(_pathOriginal, _pathCopied, overWriteFile: false);
            Assert.IsTrue(File.Exists(_pathCopied));

            File.SetAttributes(_pathCopied, FileAttributes.ReadOnly);

            // Set up event listener
            var wasCalled = false;

            FileLibrary.Log += (e) => wasCalled = true;

            FileLibrary.ComponentDeleteFileAction(_pathCopied);

            Assert.IsTrue(wasCalled);
        }
示例#11
0
        public void ComponentCopyFileAction_Copies_Blank_Destination_Path()
        {
            FileLibrary.ComponentCopyFileAction(_pathOriginal, "", overWriteFile: false);

            Assert.IsFalse(File.Exists(_pathCopied));
        }