public void GetStreamFromBase64String() { { //不保存文件 var ms = StreamUtility.GetStreamFromBase64String(baseString, null); Assert.AreEqual(21, ms.Length); //保存文件 var file = UnitTestHelper.RootPath + "GetStreamFromBase64String.txt"; var ms2 = StreamUtility.GetStreamFromBase64String(baseString, file); Assert.AreEqual(21, ms.Length); Assert.IsTrue(File.Exists(file)); //读取文件 using (var fs = new FileStream(file, FileMode.Open)) { using (var sr = new StreamReader(fs, Encoding.UTF8)) { var content = sr.ReadToEnd(); Assert.AreEqual(str, content); } } File.Delete(file);//删除文件 } #region 测试异步方法 Console.WriteLine("=== 测试异步方法 ==="); Task.Run(async() => { //不保存文件 var ms = await StreamUtility.GetStreamFromBase64StringAsync(baseString, null); Assert.AreEqual(21, ms.Length); //保存文件 var file = UnitTestHelper.RootPath + "GetStreamFromBase64String_Async.txt"; var ms2 = await StreamUtility.GetStreamFromBase64StringAsync(baseString, file); Assert.AreEqual(21, ms.Length); Assert.IsTrue(File.Exists(file)); //读取文件 using (var fs = new FileStream(file, FileMode.Open)) { using (var sr = new StreamReader(fs, Encoding.UTF8)) { var content = await sr.ReadToEndAsync(); Assert.AreEqual(str, content); } } File.Delete(file);//删除文件 Console.WriteLine("=== 异步完成 ==="); }).GetAwaiter().GetResult(); #endregion }