tests/DotNetCommon.Test/CompressHelperTests.cs
(开头部分) 11KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using DotNetCommon.Compress;
using NUnit.Framework;
using Shouldly;
using System;
using System.Collections.Generic;
using System.IO;
namespace DotNetCommon.Test
{
[TestFixture]
internal class CompressHelperTests
{
private string rootPath = Path.Combine(Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)), "DotNetCommon.Compress.TestFiles");
private string testfolderPath = "";
[SetUp]
public void SetUp()
{
//准备文件夹和文件
if (Directory.Exists(rootPath)) Directory.Delete(rootPath, true);
Directory.CreateDirectory(rootPath);
//准备目录
/*
C:\Users\Administrator\Documents\DotNetCommon.Compress.TestFiles
\testfolder\
testsubfolder\
testsubfolder-suba.txt "我是testsubfolder-suba.txt"
testemptysubfolder\
testsubfolder2\
testsubfolder-suba.txt "我是testsubfolder-suba.txt"
testfolder-a.txt "我是testfolder-a.txt"
testfolder-中文B.txt "testfolder-中文B.txt"
*/
testfolderPath = Path.Combine(rootPath, "testfolder");
Directory.CreateDirectory(testfolderPath);
File.AppendAllText(Path.Combine(testfolderPath, "testfolder-a.txt"), "我是testfolder-a.txt");
File.AppendAllText(Path.Combine(testfolderPath, "testfolder-中文B.txt"), "testfolder-中文B.txt");
Directory.CreateDirectory(Path.Combine(testfolderPath, "testsubfolder"));
File.AppendAllText(Path.Combine(testfolderPath, "testsubfolder", "testsubfolder-suba.txt"), "我是testsubfolder-suba.txt");
Directory.CreateDirectory(Path.Combine(testfolderPath, "testsubfolder2"));
File.AppendAllText(Path.Combine(testfolderPath, "testsubfolder2", "testsubfolder-suba.txt"), "我是testsubfolder-suba.txt");
Directory.CreateDirectory(Path.Combine(testfolderPath, "testemptysubfolder"));
}
public void UnCompressTests()
{
var destDirPath = Path.Combine(rootPath, "testcompress_stream.zip");
if (File.Exists(destDirPath)) File.Delete(destDirPath);
//7z
CompressHelper.UnCompress(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testfolder.7z"), destDirPath);
File.ReadAllText(Path.Combine(destDirPath, "testfolder/testfolder-中文B.txt")).ShouldBe("testfolder-中文B.txt");
File.ReadAllText(Path.Combine(destDirPath, "testfolder/testsubfolder/testsubfolder-suba.txt")).ShouldBe("我是testsubfolder-suba.txt");
Directory.Delete(destDirPath, true);
//rar
CompressHelper.UnCompress(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testfolder.rar"), destDirPath);
File.ReadAllText(Path.Combine(destDirPath, "testfolder/testfolder-中文B.txt")).ShouldBe("testfolder-中文B.txt");
File.ReadAllText(Path.Combine(destDirPath, "testfolder/testsubfolder/testsubfolder-suba.txt")).ShouldBe("我是testsubfolder-suba.txt");
Directory.Delete(destDirPath, true);
后面还有 131 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
