Skip to content

Commit

Permalink
static file removed
Browse files Browse the repository at this point in the history
  • Loading branch information
vahid committed Nov 11, 2024
1 parent bcee157 commit b90c878
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 135,254 deletions.
6 changes: 0 additions & 6 deletions Tests/Jinget.Core.Tests/Jinget.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,4 @@
<ProjectReference Include="..\..\01-Core\Jinget.Core\Jinget.Core.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="sample.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
50 changes: 35 additions & 15 deletions Tests/Jinget.Core.Tests/Utilities/Compression/ZipUtilityTests.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
using System.IO;
using System.Security.Cryptography;
using Jinget.Core.Utilities.Compression;

namespace Jinget.Core.Tests.Utilities.Compression;

[TestClass]
public class ZipUtilityTests
{
string Create15MBFile()
{
string filename = Path.ChangeExtension(Path.GetTempFileName(), ".txt");
long fileSizeInBytes = 15 * 1024 * 1024; // 15MB
using (FileStream fs = new(filename, FileMode.Create, FileAccess.Write))
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
{
byte[] buffer = new byte[1024 * 1024]; // 1 MB buffer
long bytesWritten = 0;

while (bytesWritten < fileSizeInBytes)
{
int bytesToWrite = (int)Math.Min(buffer.Length, fileSizeInBytes - bytesWritten);
rng.GetBytes(buffer, 0, bytesToWrite);
fs.Write(buffer, 0, bytesToWrite);
bytesWritten += bytesToWrite;
}
}
return filename;
}
private async Task<FileInfo> CompressAsync(string fileName, string password = "")
{
using (var tw = new StreamWriter(fileName, true))
Expand All @@ -18,9 +39,9 @@ private async Task<FileInfo> CompressAsync(string fileName, string password = ""
return tobeCompressed[0];
}

private async Task<FileInfo> CompressLargeFileAsync(string fileName, string password = "", int eachFileMaxSize = 1)
private async Task<FileInfo> CompressLargeFileAsync(string password = "", int eachFileMaxSize = 1)
{
new FileInfo("sample.txt").CopyTo(fileName);
string fileName = Create15MBFile();
FileInfo file = new(fileName);
int maxDOP = 5;

Expand All @@ -32,13 +53,12 @@ private async Task<FileInfo> CompressLargeFileAsync(string fileName, string pass
[TestCleanup]
public void Cleanup()
{
string[] zipFiles = Directory.GetFiles(".", "*.zip"); // Get all zip files in the root directory
string[] zipFiles = Directory.GetFiles(".", "*.zip");
foreach (string zipFile in zipFiles)
{
File.Delete(zipFile);
}
string[] txtFiles = Directory.GetFiles(".", "*.txt")
.Where(x => x != ".\\sample.txt").ToArray(); // Get all zip files in the root directory
string[] txtFiles = Directory.GetFiles(".", "*.txt");
foreach (string txtFile in txtFiles)
{
File.Delete(txtFile);
Expand Down Expand Up @@ -88,24 +108,24 @@ public async Task should_decompressAsync()
[TestMethod]
public async Task should_compress_large_file_and_chunkAsync()
{
var compressedFile = await CompressLargeFileAsync($"{Guid.NewGuid()}.txt", eachFileMaxSize: 1);
var compressedFile = await CompressLargeFileAsync(eachFileMaxSize: 1);
string compressedFileName = $"{Path.GetFileNameWithoutExtension(compressedFile.Name)}";

Assert.IsTrue(compressedFile.Directory.GetFiles($"{compressedFileName}.zip").Length == 1);
Assert.IsTrue(compressedFile.Directory.GetFiles($"{compressedFileName}-part?.zip").Length > 0);
Assert.IsTrue(Directory.GetFiles(".", $"{compressedFileName}.zip").Length == 1);
Assert.IsTrue(Directory.GetFiles(".", $"{compressedFileName}-part?.zip").Length > 0);
}

[TestMethod]
public async Task should_decompress_large_file_with_chunkAsync()
{
var compressedFile = await CompressLargeFileAsync($"{Guid.NewGuid()}.txt", eachFileMaxSize: 1);
var compressedFile = await CompressLargeFileAsync(eachFileMaxSize: 1);
string compressedFileName = $"{Path.GetFileNameWithoutExtension(compressedFile.Name)}";

FileInfo file = new($"{compressedFileName}.zip");
List<FileInfo> files = [file];
await ZipUtility.DecompressAsync([.. files], files[0].DirectoryName);

Assert.IsTrue(file.Directory.GetFiles($"{compressedFileName}.txt").Length == 1);
Assert.IsTrue(Directory.GetFiles(".", $"{compressedFileName}.txt").Length == 1);
}

[TestMethod]
Expand Down Expand Up @@ -149,23 +169,23 @@ await Assert.ThrowsExceptionAsync<Exception>(async () =>
[TestMethod]
public async Task should_compress_large_file_using_password_and_chunkAsync()
{
var compressedFile = await CompressLargeFileAsync($"{Guid.NewGuid()}.txt", password: "123", eachFileMaxSize: 1);
var compressedFile = await CompressLargeFileAsync(password: "123", eachFileMaxSize: 1);
string compressedFileName = $"{Path.GetFileNameWithoutExtension(compressedFile.Name)}";

Assert.IsTrue(compressedFile.Directory.GetFiles($"{compressedFileName}.zip").Length == 1);
Assert.IsTrue(compressedFile.Directory.GetFiles($"{compressedFileName}-part?.zip").Length > 0);
Assert.IsTrue(Directory.GetFiles(".", $"{compressedFileName}.zip").Length == 1);
Assert.IsTrue(Directory.GetFiles(".", $"{compressedFileName}-part?.zip").Length > 0);
}

[TestMethod]
public async Task should_decompress_large_file_using_password_and_chunkAsync()
{
var compressedFile = await CompressLargeFileAsync($"{Guid.NewGuid()}.txt", password: "123", eachFileMaxSize: 1);
var compressedFile = await CompressLargeFileAsync(password: "123", eachFileMaxSize: 1);
string compressedFileName = $"{Path.GetFileNameWithoutExtension(compressedFile.Name)}";

FileInfo file = new($"{compressedFileName}.zip");
List<FileInfo> files = [file];
await ZipUtility.DecompressAsync([.. files], files[0].DirectoryName, password: "123");

Assert.IsTrue(file.Directory.GetFiles($"{compressedFileName}.txt").Length == 1);
Assert.IsTrue(Directory.GetFiles(".", $"{compressedFileName}.txt").Length == 1);
}
}
135,233 changes: 0 additions & 135,233 deletions Tests/Jinget.Core.Tests/sample.txt

This file was deleted.

0 comments on commit b90c878

Please sign in to comment.