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_OpenFile_SaveFile()
        {
            string storePath = Path.Combine(baseDirectory, "Test");
            var storage = new DiskIsolateStorage("Test", storePath);
            storage.InitStore();

            //删除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);

            var fileName = "file.txt";
            //创建文件
            string testString = "This is teststring";
            MemoryStream stream = new MemoryStream();
            byte[] buffer = UTF8Encoding.Default.GetBytes(testString);
            stream.Write(buffer, 0, buffer.Length);
            storage.CreateFile(fileName, stream);

            //获取文件名、文件路径。。
            using (var of = storage.OpenFile(fileName, FileMode.Open))
            {
                var filePath = of.StorageFile.FilePath;
                var storageName = of.StorageFile.StorageName;

                //读取文件内容
                byte[] bytes = new byte[of.Stream.Length];
                UTF8Encoding temp = new UTF8Encoding(true);
                of.Stream.Seek(0, SeekOrigin.Begin);
                of.Stream.Read(bytes, 0, bytes.Length);
                string readStr = temp.GetString(bytes);
                Assert.AreEqual(testString, readStr);
            }
            //写文件并保存
            string writeString = "This is another teststring";
            byte[] buffer1 = UTF8Encoding.Default.GetBytes(writeString);
            using (var memoryStream = new MemoryStream(buffer1))
            {
                storage.UpdateFile(fileName, memoryStream);
            }

            //再读取文件内容
            using (var of1 = storage.OpenFile("file.txt", FileMode.Open))
            {
                byte[] b = new byte[of1.Stream.Length];
                UTF8Encoding temp1 = new UTF8Encoding(true);
                of1.Stream.Seek(0, SeekOrigin.Begin);
                of1.Stream.Read(b, 0, b.Length);
                string readStr1 = temp1.GetString(b);

                Assert.AreEqual(writeString, readStr1);
            }
        }
        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_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_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_FileExists()
        {
            var storage = new DiskIsolateStorage("Test", baseDirectory);
            storage.InitStore();
            string storePath = Path.Combine(baseDirectory, "Test");

            //创建文件
            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);
            bool result = storage.FileExists(filePath);

            //删除文件
            storage.DeleteFile(filePath);
            bool result1 = storage.FileExists(filePath);

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

            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 filePhysicalPath = Path.Combine(storePath, filePath);
            Assert.IsTrue(File.Exists(filePhysicalPath));
        }