-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathCompressProviderTests.cs
More file actions
65 lines (60 loc) · 2.4 KB
/
Copy pathCompressProviderTests.cs
File metadata and controls
65 lines (60 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using GeneralUpdate.Core.Compress;
namespace CoreTest.Compress;
public class CompressProviderTests
{
[Fact]
public void Compress_ZipFormat_UsesZipStrategy()
{
var tempDir = Path.Combine(Path.GetTempPath(), $"compress_test_{Guid.NewGuid():N}");
var destZip = Path.Combine(Path.GetTempPath(), $"result_{Guid.NewGuid():N}.zip");
Directory.CreateDirectory(tempDir);
File.WriteAllText(Path.Combine(tempDir, "test.txt"), "hello");
try
{
var ex = Record.Exception(() =>
CompressProvider.Compress(".zip", tempDir, destZip, false, System.Text.Encoding.UTF8));
Assert.Null(ex);
Assert.True(File.Exists(destZip));
}
finally
{
if (Directory.Exists(tempDir)) Directory.Delete(tempDir, true);
if (File.Exists(destZip)) File.Delete(destZip);
}
}
[Fact]
public void Compress_UnknownFormat_ThrowsArgumentException()
{
Assert.Throws<ArgumentException>(() =>
CompressProvider.Compress("RAR", "source", "dest", false, System.Text.Encoding.UTF8));
}
[Fact]
public void Decompress_ZipFormat_UsesZipStrategy()
{
var tempDir = Path.Combine(Path.GetTempPath(), $"decompress_src_{Guid.NewGuid():N}");
var zipPath = Path.Combine(Path.GetTempPath(), $"test_{Guid.NewGuid():N}.zip");
var destDir = Path.Combine(Path.GetTempPath(), $"decompress_dst_{Guid.NewGuid():N}");
Directory.CreateDirectory(tempDir);
File.WriteAllText(Path.Combine(tempDir, "test.txt"), "hello world");
try
{
System.IO.Compression.ZipFile.CreateFromDirectory(tempDir, zipPath);
var ex = Record.Exception(() =>
CompressProvider.Decompress(".zip", zipPath, destDir, System.Text.Encoding.UTF8));
Assert.Null(ex);
Assert.True(File.Exists(Path.Combine(destDir, "test.txt")));
}
finally
{
if (Directory.Exists(tempDir)) Directory.Delete(tempDir, true);
if (File.Exists(zipPath)) File.Delete(zipPath);
if (Directory.Exists(destDir)) Directory.Delete(destDir, true);
}
}
[Fact]
public void Decompress_UnknownFormat_ThrowsArgumentException()
{
Assert.Throws<ArgumentException>(() =>
CompressProvider.Decompress("7z", "source", "dest", System.Text.Encoding.UTF8));
}
}