public void Test_MoveDirectory()
        {
            var storage = new DiskIsolateStorage("Test", baseDirectory);
            storage.InitStore();
            string storePath = Path.Combine(baseDirectory, "Test");

            //删除Test目录下的所以文件和文件夹
            string[] strDirs = Directory.GetDirectories(storePath);
            string[] strFiles = Directory.GetFiles(storePath);
            foreach (var file in strFiles)
                File.Delete(file);
            foreach (var dir in strDirs)
                Directory.Delete(dir, true);

            //创建两个目录
            storage.CreateDirectory("dir1");
            storage.CreateDirectory("dir2");

            //把dir2移到dir1中
            storage.MoveDirectory("dir2", "dir1/dir2");

            var resultPath = Path.Combine(storePath, "dir1/dir2");

            Assert.IsTrue(Directory.Exists(resultPath));
        }
        public void Test_MoveFile()
        {
            var storage = new DiskIsolateStorage("Test", baseDirectory);
            storage.InitStore();
            string storePath = Path.Combine(baseDirectory, "Test");

            //删除Test目录下的所以文件和文件夹
            string[] strDirs = Directory.GetDirectories(storePath);
            string[] strFiles = Directory.GetFiles(storePath);
            foreach (var file in strFiles)
                File.Delete(file);
            foreach (var dir in strDirs)
                Directory.Delete(dir, true);

            //创建一个目录和一个文件
            storage.CreateDirectory("dir");
            string testString = "This is teststring";
            MemoryStream stream = new MemoryStream();
            byte[] buffer = Encoding.Default.GetBytes(testString);
            stream.Write(buffer, 0, 18);
            storage.CreateFile("file.txt", stream);

            storage.MoveFile("file.txt", "dir/file.txt");

            var resultPath = Path.Combine(storePath, "dir/file.txt");

            Assert.IsTrue(File.Exists(resultPath));
        }
        public void Test_GetFileNames()
        {
            var storage = new DiskIsolateStorage("Test", baseDirectory);
            storage.InitStore();
            string storePath = Path.Combine(baseDirectory, "Test");

            //删除Test目录下的所以文件和文件夹
            string[] strDirs = Directory.GetDirectories(storePath);
            string[] strFiles = Directory.GetFiles(storePath);
            foreach (var file in strFiles)
                File.Delete(file);
            foreach (var dir in strDirs)
                Directory.Delete(dir, true);

            //创建多个文件
            string testString = "This is teststring";
            MemoryStream stream = new MemoryStream();
            byte[] buffer = Encoding.Default.GetBytes(testString);
            stream.Write(buffer, 0, 18);
            for (int i = 0; i < 5; i++)
            {
                var fileName = Guid.NewGuid().ToString() + ".txt";
                storage.CreateDirectory("fDir");
                storage.CreateFile("fDir/" + fileName, stream);
                storage.CreateFile(fileName, stream);
            }

            var result1 = storage.GetFileNames("fDir");
            var result2 = storage.GetFileNames(null, "*.txt");
            var result3 = storage.GetFileNames("fDir", "*.txt");

            Assert.AreEqual(5, result1.Count());
            Assert.AreEqual(5, result2.Count());
            Assert.AreEqual(5, result3.Count());
        }
        public void Test_GetLastWriteTimeUtc()
        {
            var storage = new DiskIsolateStorage("Test", baseDirectory);
            storage.InitStore();
            string storePath = Path.Combine(baseDirectory, "Test");

            //创建目录
            string dir = "Test" + Guid.NewGuid().ToString();
            storage.CreateDirectory(dir);
            //在目录里创建文件
            string testString = "This is teststring";
            MemoryStream stream = new MemoryStream();
            byte[] buffer = Encoding.Default.GetBytes(testString);
            stream.Write(buffer, 0, 18);
            var filePath = dir + "/" + Guid.NewGuid().ToString() + ".txt";
            storage.CreateFile(filePath, stream);
            //修改文件内容
            FileStream fs = File.Open(Path.Combine(storePath, filePath), FileMode.Open);
            Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
            fs.Write(info, 0, info.Length);
            fs.Close();

            var dirLastWriteTime = Directory.GetLastWriteTimeUtc(Path.Combine(storePath, dir));
            var fileLastWriteTime = File.GetLastWriteTimeUtc(Path.Combine(storePath, filePath));

            var dirResult = storage.GetLastWriteTimeUtc(dir);
            var fileResult = storage.GetLastWriteTimeUtc(filePath);

            Assert.AreEqual(dirLastWriteTime, dirResult);
            Assert.AreEqual(fileLastWriteTime, fileResult);
        }
        public void Test_GetDirectoryNames()
        {
            var storage = new DiskIsolateStorage("Test", baseDirectory);
            storage.InitStore();
            string storePath = Path.Combine(baseDirectory, "Test");

            //删除Test目录下的所以文件和文件夹
            string[] strDirs = Directory.GetDirectories(storePath);
            string[] strFiles = Directory.GetFiles(storePath);
            foreach (var file in strFiles)
                File.Delete(file);
            foreach (var dir in strDirs)
                Directory.Delete(dir, true);

            //创建多个目录
            for (int i = 0; i < 5; i++)
            {
                storage.CreateDirectory("Dir/Di_" + Guid.NewGuid().ToString());
                string dir = "Dir_" + Guid.NewGuid().ToString();
                storage.CreateDirectory(dir);
            }

            var result1 = storage.GetDirectoryNames("Dir");
            var result2 = storage.GetDirectoryNames(null, "Dir_*");
            var result3 = storage.GetDirectoryNames("Dir", "Di_*");

            Assert.AreEqual(5, result1.Count());
            Assert.AreEqual(5, result2.Count());
            Assert.AreEqual(5, result3.Count());
        }
        public void Test_GetCreationTimeUtc()
        {
            var storage = new DiskIsolateStorage("Test", baseDirectory);
            storage.InitStore();
            string storePath = Path.Combine(baseDirectory, "Test");

            //创建目录
            string dir = "Test" + Guid.NewGuid().ToString();
            storage.CreateDirectory(dir);
            var dirCreatedDate = Directory.GetCreationTimeUtc(Path.Combine(storePath, dir));

            //创建文件
            string testString = "This is teststring";
            MemoryStream stream = new MemoryStream();
            byte[] buffer = Encoding.Default.GetBytes(testString);
            stream.Write(buffer, 0, 18);
            var filePath = Guid.NewGuid().ToString() + ".txt";
            storage.CreateFile(filePath, stream);
            var fileCreatedDate = File.GetCreationTimeUtc(Path.Combine(storePath, filePath));

            var dirResult = storage.GetCreationTimeUtc(dir);
            var fileResult = storage.GetCreationTimeUtc(filePath);

            Assert.AreEqual(dirCreatedDate, dirResult);
            Assert.AreEqual(fileCreatedDate, fileResult);
        }
        public void Test_DirectoryExists()
        {
            var storage = new DiskIsolateStorage("Test", baseDirectory);
            storage.InitStore();
            string storePath = Path.Combine(baseDirectory, "Test");

            //创建目录
            string dir = "Test" + Guid.NewGuid().ToString();
            storage.CreateDirectory(dir);

            bool result = storage.DirectoryExists(dir);

            //删除目录
            storage.DeleteDirectory(dir);
            bool result1 = storage.DirectoryExists(dir);

            Assert.IsTrue(result);
            Assert.IsFalse(result1);
        }
        public void Test_DeleteDirectory()
        {
            var storage = new DiskIsolateStorage("Test", baseDirectory);
            storage.InitStore();
            string storePath = Path.Combine(baseDirectory, "Test");

            string dir = "Test" + Guid.NewGuid().ToString();
            storage.CreateDirectory(dir);

            storage.DeleteDirectory(dir);

            string dirPath = Path.Combine(storePath, dir);
            Assert.IsFalse(Directory.Exists(dirPath));
        }
        public void Test_Create_SubDir()
        {
            var storage = new DiskIsolateStorage("Test", baseDirectory);
            storage.InitStore();

            string dir = "Test_Create_SubDir" + Guid.NewGuid().ToString();
            string subDir = Path.Combine(dir, "Sub");

            storage.CreateDirectory(subDir);

            Assert.IsTrue(storage.DirectoryExists(subDir));

            storage.DeleteDirectory(subDir);

            Assert.IsFalse(storage.DirectoryExists(subDir));
        }