1- using System ;
1+ using System ;
22using System . IO ;
33using System . Text ;
44using System . Threading . Tasks ;
@@ -10,13 +10,13 @@ namespace Senparc.CO2NET.Tests.Utilities
1010 [ TestClass ]
1111 public class StreamUtilityTests
1212 {
13- string str = "盛派在你身边" ;
13+ string str = "Senparc is by your side" ;
1414 string baseString = "77u/55ub5rS+5Zyo5L2g6Lqr6L65" ;
1515
1616 private MemoryStream GetStream ( string content )
1717 {
18- var ms = new MemoryStream ( ) ; //模拟一个已经存在的Stream
19- var sw = new StreamWriter ( ms , encoding : Encoding . UTF8 ) ; //写入
18+ var ms = new MemoryStream ( ) ; // Simulate an existing Stream
19+ var sw = new StreamWriter ( ms , encoding : Encoding . UTF8 ) ; // Write
2020 sw . Write ( content ) ;
2121 sw . Flush ( ) ;
2222 return ms ;
@@ -30,37 +30,34 @@ public void GetBase64StringTest()
3030 Assert . AreEqual ( baseString , result ) ;
3131 }
3232
33- #region 测试异步方法
34-
35- Console . WriteLine ( "=== 测试异步方法 ===" ) ;
33+ #region Test Asynchronous Method
34+ Console . WriteLine ( "=== Test Asynchronous Method ===" ) ;
3635 Task . Run ( async ( ) =>
3736 {
3837 var result = await StreamUtility . GetBase64StringAsync ( GetStream ( str ) ) ;
3938 Assert . AreEqual ( baseString , result ) ;
40-
41- Console . WriteLine ( "=== 异步完成 ===" ) ;
39+ Console . WriteLine ( "=== Asynchronous Completed ===" ) ;
4240 } ) . GetAwaiter ( ) . GetResult ( ) ;
43-
44- #endregion
41+ #endregion
4542 }
4643
47- [ TestMethod ]
44+ [ TestMethod ]
4845 public void GetStreamFromBase64String ( )
4946 {
5047 {
51- //不保存文件
48+ // Create a new file
5249 var ms = StreamUtility . GetStreamFromBase64String ( baseString , null ) ;
5350
5451 Assert . AreEqual ( 21 , ms . Length ) ;
5552
56- //保存文件
53+ // Open a file
5754 var file = UnitTestHelper . RootPath + "GetStreamFromBase64String.txt" ;
5855 var ms2 = StreamUtility . GetStreamFromBase64String ( baseString , file ) ;
5956 Assert . AreEqual ( 21 , ms . Length ) ;
6057
6158 Assert . IsTrue ( File . Exists ( file ) ) ;
6259
63- //读取文件
60+ // Read a file
6461 using ( var fs = new FileStream ( file , FileMode . Open ) )
6562 {
6663 using ( var sr = new StreamReader ( fs , Encoding . UTF8 ) )
@@ -70,26 +67,26 @@ public void GetStreamFromBase64String()
7067 }
7168 }
7269
73- File . Delete ( file ) ; //删除文件
70+ File . Delete ( file ) ; // Delete a file
7471 }
7572
7673
77- #region 测试异步方法
78- Console . WriteLine ( "=== 测试异步方法 ===" ) ;
74+ #region Test Asynchronous Method
75+ Console . WriteLine ( "=== Asynchronous Completed ===" ) ;
7976 Task . Run ( async ( ) =>
8077 {
81- //不保存文件
78+ // Create a new file
8279 var ms = await StreamUtility . GetStreamFromBase64StringAsync ( baseString , null ) ;
8380 Assert . AreEqual ( 21 , ms . Length ) ;
8481
85- //保存文件
82+ // Open a file
8683 var file = UnitTestHelper . RootPath + "GetStreamFromBase64String_Async.txt" ;
8784 var ms2 = await StreamUtility . GetStreamFromBase64StringAsync ( baseString , file ) ;
8885 Assert . AreEqual ( 21 , ms . Length ) ;
8986
9087 Assert . IsTrue ( File . Exists ( file ) ) ;
9188
92- //读取文件
89+ // Read a file
9390 using ( var fs = new FileStream ( file , FileMode . Open ) )
9491 {
9592 using ( var sr = new StreamReader ( fs , Encoding . UTF8 ) )
@@ -99,9 +96,9 @@ public void GetStreamFromBase64String()
9996 }
10097 }
10198
102- File . Delete ( file ) ; //删除文件
99+ File . Delete ( file ) ; // Delete a file
103100
104- Console . WriteLine ( "=== 异步完成 ===" ) ;
101+ Console . WriteLine ( "=== Asynchronous Completed ===" ) ;
105102 } ) . GetAwaiter ( ) . GetResult ( ) ;
106103
107104 #endregion
@@ -116,23 +113,23 @@ public void SaveFileFromStreamTest()
116113 StreamUtility . SaveFileFromStream ( stream , file ) ;
117114
118115 Assert . IsTrue ( File . Exists ( file ) ) ;
119- Assert . IsTrue ( UnitTestHelper . CheckKeywordsExist ( file , str ) ) ; //检查内容已经被记录
116+ Assert . IsTrue ( UnitTestHelper . CheckKeywordsExist ( file , str ) ) ; // The file has already been recorded
120117
121- File . Delete ( file ) ; //删除文件
118+ File . Delete ( file ) ; // Delete a file
122119 }
123120
124- #region 测试异步方法
121+ #region Test Asynchronous Method
125122 Task . Run ( async ( ) =>
126123 {
127124 var stream = GetStream ( str ) ;
128125 var file = UnitTestHelper . RootPath + "SaveFileFromStreamTest.txt" ;
129126 await StreamUtility . SaveFileFromStreamAsync ( stream , file ) ;
130127
131128 Assert . IsTrue ( File . Exists ( file ) ) ;
132- Assert . IsTrue ( UnitTestHelper . CheckKeywordsExist ( file , str ) ) ; //检查内容已经被记录
129+ Assert . IsTrue ( UnitTestHelper . CheckKeywordsExist ( file , str ) ) ; // The file has already been recorded
133130
134- File . Delete ( file ) ; //删除文件
135- Console . WriteLine ( "=== 异步完成 ===" ) ;
131+ File . Delete ( file ) ; // Delete a file
132+ Console . WriteLine ( "=== Asynchronous Completed ===" ) ;
136133 } ) . GetAwaiter ( ) . GetResult ( ) ;
137134 #endregion
138135 }
0 commit comments