Пример #1
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 + "//");
                }
            }
        }
        public void GetParentDirectory()
        {
            try
            {
                if (!HasFolderPermission)
                {
                    return;
                }

                Assert.IsNull(IoDir.GetParentDirectory(""), "GetParentDirectory, Expected null");

                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.IsNotNull(IoDir.GetParentDirectory(TestFolder + "//"), "GetParentDirectory, Expected null");
            }
            finally
            {
                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                }
            }
        }
        public void GetCountOfSubdirectories()
        {
            try
            {
                if (!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");

                for (var d = 0; d < 5; d++)
                {
                    IoDir.CreateDirectory(TestFolder + "//" + d + "//");
                }

                Assert.IsTrue(IoDir.GetCountOfSubdirectories(TestFolder + "//") == 5, "Error counting subdirectories");
            }
            finally
            {
                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                }
            }
        }
Пример #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 SetDirectoryPermissions()
        {
            try
            {
                if (!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");

                var permissions = IoDir.GetDirectoryPermission(TestFolder + "//");
                Assert.IsTrue(permissions.Any(), "Error getting directory permissions");

                IList <FileSystemRights> newPermissions = new List <FileSystemRights>();
                foreach (var permission in (FileSystemRights[])System.Enum.GetValues(typeof(FileSystemRights)))
                {
                    if (permissions.All(p => p != permission))
                    {
                        newPermissions.Add(permission);
                    }
                }

                Assert.IsNotNull(newPermissions, "Error getting permissions");
                Assert.IsTrue(newPermissions.Any(), "Error getting permissions");
                Console.WriteLine("Permission to set: {0}", string.Join(", ", newPermissions));

                var permissionProccessResult = IoDir.SetDirectoryPermissions(TestFolder + "//", newPermissions.ToArray());
                if (!permissionProccessResult)
                {
                    Assert.Inconclusive("Error setting directory permission");
                }

                permissions = IoDir.GetDirectoryPermission(TestFolder + "//");
                foreach (var ps in newPermissions)
                {
                    Assert.IsNotNull(permissions.FirstOrDefault(p => p == ps), "Error setting permission: {0}", ps);
                }
            }
            finally
            {
                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                }
            }
        }
Пример #11
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 + "//");
                }
            }
        }
Пример #12
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 + "//");
                }
            }
        }
Пример #13
0
        public void DirectoryExists()
        {
            try
            {
                if (!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");
            }
            finally
            {
                if (HasFolderPermission)
                {
                    IoDir.DeleteDirectory(TestFolder + "//");
                }
            }
        }