Пример #1
0
        public void TestProccessExecutesButDoesNotCompleteWithNoOutputAndErrors()
        {
            try
            {
                if (!HasFilePermission)
                {
                    return;
                }

                // setup
                _processInfo.Arguments = "config1";

                string output;
                string errors;

                // execute
                var completed = _processUtils.ExecuteProcess(_processInfo, out output, out errors);

                // assert
                Assert.IsFalse(completed, "Error executing proccess");
                Assert.IsNull(output, "Error executing proccess, expected no output");
                Assert.IsNotNull(errors, "Error executing proccess, expected errors");

                Console.WriteLine(errors);
            }
            finally
            {
                if (HasFilePermission)
                {
                    IoFiles.DeleteFile(Directory.GetCurrentDirectory() + "\\" + ProcessExe);
                }
            }
        }
Пример #2
0
        public void CreateDocument()
        {
            try
            {
                if (!HasFilePermission || !HasFolderPermission)
                {
                    return;
                }

                Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path");
                Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory");
                Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory");

                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument(TestFolder + "//", TestFile, null, Xsd, Ns.NamespaceName), "Error validating xml, expected false");
                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument(TestFolder + "//", TestFile, E1.ToString(), null, Ns.NamespaceName), "Error validating xml, expected false");
                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument(TestFolder + "//", TestFile, E1.ToString(), Xsd, null), "Error validating xml, expected false");
                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument(TestFolder + "//", TestFile, E1.ToString(), Xsd, Ns.NamespaceName), "Error validating xml, expected false");

                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument("a//", TestFile, E2.ToString(), Xsd, Ns.NamespaceName), "Error validating xml, expected false");
                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument(null, TestFile, E2.ToString(), Xsd, Ns.NamespaceName), "Error validating xml, expected false");

                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument(TestFolder + "//", null, E2.ToString(), Xsd, Ns.NamespaceName), "Error validating xml, expected false");

                Assert.IsTrue(DevUtilsXmlUtils.CreateDocument(TestFolder + "//", TestFile, E2.ToString(), Xsd, Ns.NamespaceName), "Error validating xml, expected true");
                Assert.IsTrue(IoFiles.FileExists(TestFolder + "//" + TestFile), "Error creating xml file");
            }
            finally
            {
                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                }
            }
        }
Пример #3
0
        public void TestProccessDoesNotExecuteOrCompleteWithNoOutputOrErrors()
        {
            try
            {
                if (!HasFilePermission)
                {
                    return;
                }

                // setup
                _processInfo = null;

                string output;
                string errors;

                // execute
                var completed = _processUtils.ExecuteProcess(_processInfo, out output, out errors);

                // assert
                Assert.IsFalse(completed, "Error executing proccess");
                Assert.IsNull(output, "Error executing proccess, expected output");
                Assert.IsNull(errors, "Error executing proccess, expected errors");
            }
            finally
            {
                if (HasFilePermission)
                {
                    IoFiles.DeleteFile(Directory.GetCurrentDirectory() + "\\" + ProcessExe);
                }
            }
        }
Пример #4
0
        public void ReadFileAsString()
        {
            try
            {
                if (!HasFilePermission || !HasFolderPermission)
                {
                    return;
                }

                const string fileContent = "test content";

                Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path");
                Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory");
                Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory");

                Assert.IsFalse(IoFiles.FileExists(TestFolder + "//0.txt"), "Invalid file path");
                IoFiles.CreateFile(TestFolder + "//0.txt", fileContent);
                Assert.IsTrue(IoFiles.FileExists(TestFolder + "//0.txt"), "Error creating file");

                Assert.AreEqual(IoFiles.ReadFileAsString(TestFolder + "//0.txt"), fileContent, "Error getting file content");
            }
            finally
            {
                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                }
            }
        }
Пример #5
0
        public void FileExists()
        {
            try
            {
                if (!HasFilePermission || !HasFolderPermission)
                {
                    return;
                }

                Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path");
                Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory");
                Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory");

                Assert.IsFalse(IoFiles.FileExists(TestFolder + "//0.txt"), "Invalid file path");
                IoFiles.CreateFile(TestFolder + "//0.txt", "0");
                Assert.IsTrue(IoFiles.FileExists(TestFolder + "//0.txt"), "Error creating file");
            }
            finally
            {
                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                }
            }
        }
Пример #6
0
        public void DeleteFiles()
        {
            try
            {
                if (!HasFolderPermission || !HasFilePermission)
                {
                    return;
                }

                Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path");
                Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory");
                Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory");

                IList <string> files = new List <string>();
                for (var i = 0; i < 20; i++)
                {
                    files.Add(TestFolder + "//" + i + ".txt");
                }

                foreach (var file in files)
                {
                    IoFiles.CreateFile(file, file);
                }

                Assert.IsTrue(IoFiles.DeleteFiles(TestFolder + "//") == files.Count, "Error deleting files");
            }
            finally
            {
                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                    IoDir.DeleteDirectory(TestFolderCopy + "//");
                }
            }
        }
        public void DeleteDirectoryContents()
        {
            try
            {
                if (!HasFolderPermission || !HasFilePermission)
                {
                    return;
                }

                Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path");
                Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory");
                Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory");

                for (var d = 0; d < 5; d++)
                {
                    if (d == 0)
                    {
                        for (var i = 0; i < 20; i++)
                        {
                            IoFiles.CreateFile(TestFolder + "//" + i + ".txt", i.ToString(CultureInfo.InvariantCulture));
                        }
                    }


                    IoDir.CreateDirectory(TestFolder + "//" + d + "//");

                    for (var i = 0; i < 20; i++)
                    {
                        IoFiles.CreateFile(TestFolder + "//" + d + "//" + i + ".txt", i.ToString(CultureInfo.InvariantCulture));
                    }
                }

                var mainFilesCount   = IoFiles.GetCountOfFilesInDirectoryAndSubdirectories(TestFolder + "//");
                var mainFoldersCount = IoDir.GetCountOfSubdirectories(TestFolder + "//");
                Assert.IsTrue(mainFilesCount > 0, "Error counting files on directory");
                Assert.IsTrue(mainFoldersCount > 0, "Error counting subdirectories");

                Console.WriteLine("Files count: {0}", mainFilesCount);
                Console.WriteLine("Subdirectories count: {0}", mainFoldersCount);

                Assert.IsTrue(IoDir.DeleteDirectoryContents(TestFolder + "//"), "Error deleting directory content");

                mainFilesCount   = IoFiles.GetCountOfFilesInDirectoryAndSubdirectories(TestFolder + "//");
                mainFoldersCount = IoDir.GetCountOfSubdirectories(TestFolder + "//");
                Console.WriteLine("\nFiles count: {0}", mainFilesCount);
                Console.WriteLine("Subdirectories count: {0}", mainFoldersCount);

                Assert.IsTrue(mainFilesCount == mainFoldersCount && mainFilesCount == 0, "Error deleting files and subdirectories");
            }
            finally
            {
                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                }
            }
        }
Пример #8
0
        public void ReadFileAsStream()
        {
            FileStream file1 = null;
            FileStream file2 = null;

            try
            {
                if (!HasFilePermission || !HasFolderPermission)
                {
                    return;
                }

                const string fileContent = "test content";

                Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path");
                Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory");
                Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory");

                Assert.IsFalse(IoFiles.FileExists(TestFolder + "//0.txt"), "Invalid file path");
                IoFiles.CreateFile(TestFolder + "//0.txt", fileContent);
                Assert.IsTrue(IoFiles.FileExists(TestFolder + "//0.txt"), "Error creating file");

                Assert.IsFalse(IoFiles.FileExists(TestFolder + "//1.txt"), "Invalid file path");
                IoFiles.CreateFile(TestFolder + "//1.txt", fileContent);
                Assert.IsTrue(IoFiles.FileExists(TestFolder + "//1.txt"), "Error creating file");

                Assert.AreEqual(IoFiles.ReadFileAsString(TestFolder + "//0.txt"), fileContent, "Error getting file content");
                Assert.AreEqual(IoFiles.ReadFileAsString(TestFolder + "//1.txt"), fileContent, "Error getting file content");

                file1 = IoFiles.ReadFileAsStream(TestFolder + "//0.txt");
                file2 = IoFiles.ReadFileAsStream(TestFolder + "//1.txt");

                Assert.IsNotNull(file1, "Error getting file content");
                Assert.IsNotNull(file2, "Error getting file content");
            }
            finally
            {
                if (file1 != null)
                {
                    file1.Close();
                    file1.Dispose();
                }


                if (file2 != null)
                {
                    file2.Close();
                    file2.Dispose();
                }


                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                }
            }
        }
        public void CopyDirectory()
        {
            try
            {
                if (!HasFolderPermission || !HasFilePermission)
                {
                    return;
                }

                Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path");
                Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory");
                Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory");

                for (var d = 0; d < 5; d++)
                {
                    if (d == 0)
                    {
                        for (var i = 0; i < 20; i++)
                        {
                            IoFiles.CreateFile(TestFolder + "//" + i + ".txt", i.ToString(CultureInfo.InvariantCulture));
                        }
                    }


                    IoDir.CreateDirectory(TestFolder + "//" + d + "//");

                    for (var i = 0; i < 20; i++)
                    {
                        IoFiles.CreateFile(TestFolder + "//" + d + "//" + i + ".txt", i.ToString(CultureInfo.InvariantCulture));
                    }
                }

                Assert.IsFalse(IoDir.DirectoryExists(TestFolderCopy + "//"), "Invalid directory path");
                IoDir.CopyDirectory(TestFolder, TestFolderCopy);
                Assert.IsTrue(IoDir.DirectoryExists(TestFolderCopy + "//"), "Error creating directory");

                var mainFilesCount = IoFiles.GetCountOfFilesInDirectoryAndSubdirectories(TestFolder + "//");
                var copyFilesCount = IoFiles.GetCountOfFilesInDirectoryAndSubdirectories(TestFolderCopy + "//");

                Console.WriteLine("Main folder files count: {0}", mainFilesCount);
                Console.WriteLine("Copy folder files count: {0}", copyFilesCount);

                Assert.IsTrue(mainFilesCount == copyFilesCount, "Error coping files");
            }
            finally
            {
                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                    IoDir.DeleteDirectory(TestFolderCopy + "//");
                }
            }
        }
Пример #10
0
        public void GetElement()
        {
            try
            {
                if (!HasFilePermission || !HasFolderPermission)
                {
                    return;
                }

                Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path");
                Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory");
                Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory");

                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument(TestFolder + "//", TestFile, null, Xsd, Ns.NamespaceName), "Error validating xml, expected false");
                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument(TestFolder + "//", TestFile, E1.ToString(), null, Ns.NamespaceName), "Error validating xml, expected false");
                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument(TestFolder + "//", TestFile, E1.ToString(), Xsd, null), "Error validating xml, expected false");
                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument(TestFolder + "//", TestFile, E1.ToString(), Xsd, Ns.NamespaceName), "Error validating xml, expected false");

                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument("a//", TestFile, E2.ToString(), Xsd, Ns.NamespaceName), "Error validating xml, expected false");
                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument(null, TestFile, E2.ToString(), Xsd, Ns.NamespaceName), "Error validating xml, expected false");

                Assert.IsFalse(DevUtilsXmlUtils.CreateDocument(TestFolder + "//", null, E2.ToString(), Xsd, Ns.NamespaceName), "Error validating xml, expected false");

                Assert.IsTrue(DevUtilsXmlUtils.CreateDocument(TestFolder + "//", TestFile, E2.ToString(), Xsd, Ns.NamespaceName), "Error validating xml, expected true");
                Assert.IsTrue(IoFiles.FileExists(TestFolder + "//" + TestFile), "Error creating xml file");

                var value = DevUtilsXmlUtils.GetElement(TestFolder + "//" + TestFile, "count", Ns.NamespaceName);
                Assert.AreEqual("2", value, "Error getting element value, espected 2");

                value = DevUtilsXmlUtils.GetElement(TestFolder + "//" + TestFile, "count", null);
                Assert.AreEqual("2", value, "Error getting element value, espected 2");

                value = DevUtilsXmlUtils.GetElement(TestFolder + "//" + TestFile, "foo", Ns);
                Assert.IsNull(value, "Error getting element value, espected null");

                value = DevUtilsXmlUtils.GetElement(TestFolder + "//" + TestFile, "foo", null);
                Assert.IsNull(value, "Error getting element value, espected null");
            }
            finally
            {
                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                }
            }
        }
Пример #11
0
        public void DeleteDirectory()
        {
            try
            {
                if (!HasFolderPermission || !HasFilePermission)
                {
                    return;
                }

                Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path");
                Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory");
                Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory");

                for (var d = 0; d < 5; d++)
                {
                    if (d == 0)
                    {
                        for (var i = 0; i < 20; i++)
                        {
                            IoFiles.CreateFile(TestFolder + "//" + i + ".txt", i.ToString(CultureInfo.InvariantCulture));
                        }
                    }


                    IoDir.CreateDirectory(TestFolder + "//" + d + "//");

                    for (var i = 0; i < 20; i++)
                    {
                        IoFiles.CreateFile(TestFolder + "//" + d + "//" + i + ".txt", i.ToString(CultureInfo.InvariantCulture));
                    }
                }

                Assert.IsTrue(IoDir.DeleteDirectory(TestFolder + "//"), "Error deleting directory");
                Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path");
            }
            finally
            {
                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                }
            }
        }
Пример #12
0
        public void GenerateNugetPackage()
        {
            try
            {
                if (!HasFilePermission)
                {
                    return;
                }

                string output;
                string errors;

                _processInfo.Arguments = "pack ../DevUtils/DevUtils/DevUtils.csproj -IncludeReferencedProjects -Prop Configuration=Release";
                var completed = _processUtils.ExecuteProcess(_processInfo, out output, out errors);

                Console.WriteLine("Complete generate: {0}", completed);
                Console.WriteLine("Output: {0}", output);
                Console.WriteLine("Errors: {0}", errors);
                Console.WriteLine("");

                if (!completed)
                {
                    return;
                }

                _processInfo.Arguments = "push DevUtils.1.0.0.0.nupkg";
                completed = _processUtils.ExecuteProcess(_processInfo, out output, out errors);
                Console.WriteLine("Complete generate: {0}", completed);
                Console.WriteLine("Output: {0}", output);
                Console.WriteLine("Errors: {0}", errors);
            }
            finally
            {
                if (HasFilePermission)
                {
                    IoFiles.DeleteFile(Directory.GetCurrentDirectory() + "\\" + ProcessExe);
                }
            }
        }