コード例 #1
0
 public static async Task <IFileInfo> CreateFileAsync(this IFileProvider fileProvider, string path, string data, Encoding encoding = null, bool canOverwrite = false)
 {
     using (var memoryStream = new MemoryStream((encoding ?? Encoding.UTF8).GetBytes(data)))
     {
         return(await fileProvider.CreateFileAsync(path, memoryStream));
     }
 }
コード例 #2
0
        public void CanWriteReadDelteFile()
        {
            var tempDir  = Path.GetTempPath();
            var tempFile = Path.GetRandomFileName();

            var fullName = Path.Combine(tempDir, tempFile);

            FileProvider.CreateFileAsync(fullName, "Jake").GetAwaiter().GetResult();
            var file = FileProvider.GetFileInfoAsync(fullName).Result;

            Assert.IsTrue(file.Exists);
            Assert.AreEqual(fullName, file.Path);
            Assert.AreEqual("Jake", file.ReadAllTextAsync().GetAwaiter().GetResult());

            FileProvider.DeleteFileAsync(fullName).GetAwaiter().GetResult();

            file = FileProvider.GetFileInfoAsync(fullName).Result;

            Assert.IsFalse(file.Exists);
        }