Skip to content

Commit 0913daa

Browse files
committed
💾 ✔️ Feat, Test: Improved FileHelper.cs and wrote units tests fot it.
1 parent 5f42ef4 commit 0913daa

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

Common.BasicHelper.Test/IO/FileHelper_Tests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,25 @@ public void Test_ByteToFile()
166166
for (int i = 0; i < read.LongLength; ++i)
167167
Assert.AreEqual(read[i], bytes[i]);
168168
}
169+
170+
[TestMethod()]
171+
public void Test_CreateFile()
172+
{
173+
var file = Path.GetTempFileName();
174+
175+
file.Print();
176+
177+
var bytes = Encoding.UTF8.GetBytes("Test");
178+
179+
FileHelper.CreateFile(bytes, file);
180+
181+
var read = FileHelper.ReadAllBytes(file);
182+
183+
File.Delete(file);
184+
185+
Assert.AreEqual(read.LongLength, bytes.LongLength);
186+
187+
for (int i = 0; i < read.LongLength; ++i)
188+
Assert.AreEqual(read[i], bytes[i]);
189+
}
169190
}

Common.BasicHelper/IO/FileHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static byte[] ReadAllBytes(string path)
165165
/// </summary>
166166
/// <param name="fileBuffer">二进制流</param>
167167
/// <param name="newFilePath">文件路径</param>
168-
private static void CreateFile(byte[] fileBuffer, string newFilePath)
168+
public static void CreateFile(byte[] fileBuffer, string newFilePath)
169169
{
170170
if (File.Exists(newFilePath))
171171
File.Delete(newFilePath);

0 commit comments

Comments
 (0)