From 16ef25b07a03a56ff346a9e71d28f719155b4ce2 Mon Sep 17 00:00:00 2001 From: Mutudu Date: Tue, 19 Dec 2023 15:34:12 +0800 Subject: [PATCH] Refactor and complete unit tests --- Zaabee.Compression.sln | 7 ++ src/Zaabee.Brotli/Zaabee.Brotli.csproj | 6 +- src/Zaabee.LZ4/Zaabee.LZ4.csproj | 6 +- src/Zaabee.LZMA/Zaabee.LZMA.csproj | 6 +- .../Zaabee.SharpZipLib.csproj | 6 +- src/Zaabee.Snappy/Zaabee.Snappy.csproj | 6 +- .../Zaabee.SystemIoCompression.csproj | 6 +- src/Zaabee.XZ/Zaabee.XZ.csproj | 6 +- src/Zaabee.Zstd/Zaabee.Zstd.csproj | 6 +- .../GlobalUsings.cs | 2 + .../UnitTest.cs | 66 +++++++++++++++++++ ...ee.Compressor.Abstractions.UnitTest.csproj | 30 +++++++++ 12 files changed, 129 insertions(+), 24 deletions(-) create mode 100644 tests/Zaabee.Compressor.Abstractions.UnitTest/GlobalUsings.cs create mode 100644 tests/Zaabee.Compressor.Abstractions.UnitTest/UnitTest.cs create mode 100644 tests/Zaabee.Compressor.Abstractions.UnitTest/Zaabee.Compressor.Abstractions.UnitTest.csproj diff --git a/Zaabee.Compression.sln b/Zaabee.Compression.sln index 3940925..bd23a12 100644 --- a/Zaabee.Compression.sln +++ b/Zaabee.Compression.sln @@ -46,6 +46,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zaabee.SystemIoCompression" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zaabee.SystemIoCompression.UnitTest", "tests\Zaabee.SystemIoCompression.UnitTest\Zaabee.SystemIoCompression.UnitTest.csproj", "{70D3599E-7CAA-4DE8-826F-DDA211E3FE75}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zaabee.Compressor.Abstractions.UnitTest", "tests\Zaabee.Compressor.Abstractions.UnitTest\Zaabee.Compressor.Abstractions.UnitTest.csproj", "{81529D2A-F446-4046-8792-318D4808503F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -72,6 +74,7 @@ Global {73E05D79-6F20-4281-B6D2-41049402CBC5} = {5BE4F706-456E-4DF8-A606-69F992835B47} {41831AEE-A2EE-4248-B231-007AA198C5F1} = {158FA242-DD0C-4482-BD54-4E7EDA9C44CA} {70D3599E-7CAA-4DE8-826F-DDA211E3FE75} = {5BE4F706-456E-4DF8-A606-69F992835B47} + {81529D2A-F446-4046-8792-318D4808503F} = {5BE4F706-456E-4DF8-A606-69F992835B47} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {F9369C2B-0732-46F2-B95A-8F109BFE59A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -154,5 +157,9 @@ Global {70D3599E-7CAA-4DE8-826F-DDA211E3FE75}.Debug|Any CPU.Build.0 = Debug|Any CPU {70D3599E-7CAA-4DE8-826F-DDA211E3FE75}.Release|Any CPU.ActiveCfg = Release|Any CPU {70D3599E-7CAA-4DE8-826F-DDA211E3FE75}.Release|Any CPU.Build.0 = Release|Any CPU + {81529D2A-F446-4046-8792-318D4808503F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {81529D2A-F446-4046-8792-318D4808503F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {81529D2A-F446-4046-8792-318D4808503F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {81529D2A-F446-4046-8792-318D4808503F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/src/Zaabee.Brotli/Zaabee.Brotli.csproj b/src/Zaabee.Brotli/Zaabee.Brotli.csproj index 6ecd9e5..b97fb98 100644 --- a/src/Zaabee.Brotli/Zaabee.Brotli.csproj +++ b/src/Zaabee.Brotli/Zaabee.Brotli.csproj @@ -3,8 +3,8 @@ netstandard2.0;net6.0;net7.0;net8.0 true - 2023.10.0 - 2023.10.0 + 2023.10.1 + 2023.10.1 Mutuduxf Mutuduxf Zaabee;Brotli.NET;Brotli;Compression @@ -18,7 +18,7 @@ - + diff --git a/src/Zaabee.LZ4/Zaabee.LZ4.csproj b/src/Zaabee.LZ4/Zaabee.LZ4.csproj index 0e836cb..38d026b 100644 --- a/src/Zaabee.LZ4/Zaabee.LZ4.csproj +++ b/src/Zaabee.LZ4/Zaabee.LZ4.csproj @@ -3,8 +3,8 @@ netstandard2.0;net6.0;net7.0;net8.0 true - 2023.10.0 - 2023.10.0 + 2023.10.1 + 2023.10.1 Mutuduxf Mutuduxf Zaabee;K4os.Compression.LZ4;LZ4;Compression @@ -19,7 +19,7 @@ - + diff --git a/src/Zaabee.LZMA/Zaabee.LZMA.csproj b/src/Zaabee.LZMA/Zaabee.LZMA.csproj index 5b6ab8a..8028235 100644 --- a/src/Zaabee.LZMA/Zaabee.LZMA.csproj +++ b/src/Zaabee.LZMA/Zaabee.LZMA.csproj @@ -3,8 +3,8 @@ netstandard2.0;net6.0;net7.0;net8.0 true - 2023.10.0 - 2023.10.0 + 2023.10.1 + 2023.10.1 Mutuduxf Mutuduxf Zaabee;LZMA-SDK;LZMA;Compression @@ -18,7 +18,7 @@ - + diff --git a/src/Zaabee.SharpZipLib/Zaabee.SharpZipLib.csproj b/src/Zaabee.SharpZipLib/Zaabee.SharpZipLib.csproj index 480c18e..b0fbbf9 100644 --- a/src/Zaabee.SharpZipLib/Zaabee.SharpZipLib.csproj +++ b/src/Zaabee.SharpZipLib/Zaabee.SharpZipLib.csproj @@ -3,8 +3,8 @@ netstandard2.0;net6.0;net7.0;net8.0 true - 2023.10.0 - 2023.10.0 + 2023.10.1 + 2023.10.1 Mutuduxf Mutuduxf Zaabee;SharpZipLib;BZip2;GZip;Compression @@ -18,7 +18,7 @@ - + diff --git a/src/Zaabee.Snappy/Zaabee.Snappy.csproj b/src/Zaabee.Snappy/Zaabee.Snappy.csproj index 7e2d014..b987de0 100644 --- a/src/Zaabee.Snappy/Zaabee.Snappy.csproj +++ b/src/Zaabee.Snappy/Zaabee.Snappy.csproj @@ -3,8 +3,8 @@ netstandard2.0;net6.0;net7.0;net8.0 true - 2023.10.0 - 2023.10.0 + 2023.10.1 + 2023.10.1 Mutuduxf Mutuduxf Zaabee;IronSnappy;Snappy;Compression @@ -18,7 +18,7 @@ - + diff --git a/src/Zaabee.SystemIoCompression/Zaabee.SystemIoCompression.csproj b/src/Zaabee.SystemIoCompression/Zaabee.SystemIoCompression.csproj index c653607..ba2b4e0 100644 --- a/src/Zaabee.SystemIoCompression/Zaabee.SystemIoCompression.csproj +++ b/src/Zaabee.SystemIoCompression/Zaabee.SystemIoCompression.csproj @@ -3,8 +3,8 @@ netstandard2.0;net6.0;net7.0;net8.0 true - 2023.10.0 - 2023.10.0 + 2023.10.1 + 2023.10.1 Mutuduxf Mutuduxf Zaabee;System.IO.Compression;Brotli;Deflate;GZip;Compression @@ -18,7 +18,7 @@ - + diff --git a/src/Zaabee.XZ/Zaabee.XZ.csproj b/src/Zaabee.XZ/Zaabee.XZ.csproj index 1e68eef..0260e3b 100644 --- a/src/Zaabee.XZ/Zaabee.XZ.csproj +++ b/src/Zaabee.XZ/Zaabee.XZ.csproj @@ -3,8 +3,8 @@ netstandard2.0;net6.0;net7.0;net8.0 true - 2023.10.0 - 2023.10.0 + 2023.10.1 + 2023.10.1 Mutuduxf Mutuduxf Zaabee;XZ.NET-netstandard;XZ;Compression @@ -18,7 +18,7 @@ - + diff --git a/src/Zaabee.Zstd/Zaabee.Zstd.csproj b/src/Zaabee.Zstd/Zaabee.Zstd.csproj index 1c01392..cad94f8 100644 --- a/src/Zaabee.Zstd/Zaabee.Zstd.csproj +++ b/src/Zaabee.Zstd/Zaabee.Zstd.csproj @@ -3,8 +3,8 @@ netstandard2.0;net6.0;net7.0;net8.0 true - 2023.10.0 - 2023.10.0 + 2023.10.1 + 2023.10.1 Mutuduxf Mutuduxf Zaabee;ZstdNet;Zstd;Compression @@ -18,7 +18,7 @@ - + diff --git a/tests/Zaabee.Compressor.Abstractions.UnitTest/GlobalUsings.cs b/tests/Zaabee.Compressor.Abstractions.UnitTest/GlobalUsings.cs new file mode 100644 index 0000000..b8b3d9d --- /dev/null +++ b/tests/Zaabee.Compressor.Abstractions.UnitTest/GlobalUsings.cs @@ -0,0 +1,2 @@ +global using TestModel; +global using Xunit; \ No newline at end of file diff --git a/tests/Zaabee.Compressor.Abstractions.UnitTest/UnitTest.cs b/tests/Zaabee.Compressor.Abstractions.UnitTest/UnitTest.cs new file mode 100644 index 0000000..a02b1a6 --- /dev/null +++ b/tests/Zaabee.Compressor.Abstractions.UnitTest/UnitTest.cs @@ -0,0 +1,66 @@ +namespace Zaabee.Compressor.Abstractions.UnitTest; + +public class UnitTest +{ + [Fact] + public void CompressBytesTest() + { + var compressor = new NullCompressor(); + var compressedBytes = compressor.Compress(TestConsts.Data); + var decompressedBytes = compressor.Decompress(compressedBytes); + Assert.Equal(TestConsts.Data, decompressedBytes); + } + + [Fact] + public void CompressStringTest() + { + var compressor = new NullCompressor(); + var compressedBytes = compressor.Compress(TestConsts.Str); + var decompressedStr = compressor.DecompressToString(compressedBytes); + Assert.Equal(TestConsts.Str, decompressedStr); + } + + [Fact] + public void CompressStreamTest() + { + var compressor = new NullCompressor(); + var ms = new MemoryStream(TestConsts.Data); + var compressedStream = compressor.Compress(ms); + var decompressedMemory = compressor.Decompress(compressedStream); + Assert.Equal(ms.ToArray(), decompressedMemory.ToArray()); + } + + [Fact] + public void CompressPackToStreamTest() + { + var compressor = new NullCompressor(); + var ms = new MemoryStream(TestConsts.Data); + var compressedStream = new MemoryStream(); + compressor.Compress(ms, compressedStream); + var decompressedMemory = new MemoryStream(); + compressor.Decompress(compressedStream, decompressedMemory); + Assert.Equal(ms.ToArray(), decompressedMemory.ToArray()); + } + + [Fact] + public async Task CompressStreamTestAsync() + { + var compressor = new NullCompressor(); + var ms = new MemoryStream(TestConsts.Data); + var compressedStream = await compressor.CompressAsync(ms); + var decompressedMemory = await compressor.DecompressAsync(compressedStream); + Assert.Equal(ms.ToArray(), decompressedMemory.ToArray()); + } + + [Fact] + public async Task CompressPackToStreamTestAsync() + { + var compressor = new NullCompressor(); + var ms = new MemoryStream(TestConsts.Data); + var compressedStream = new MemoryStream(); + await compressor.CompressAsync(ms, compressedStream); + var decompressedMemory = new MemoryStream(); + await compressor.DecompressAsync(compressedStream, decompressedMemory); + Assert.Equal(ms.ToArray(), decompressedMemory.ToArray()); + } +} \ No newline at end of file diff --git a/tests/Zaabee.Compressor.Abstractions.UnitTest/Zaabee.Compressor.Abstractions.UnitTest.csproj b/tests/Zaabee.Compressor.Abstractions.UnitTest/Zaabee.Compressor.Abstractions.UnitTest.csproj new file mode 100644 index 0000000..946e4ed --- /dev/null +++ b/tests/Zaabee.Compressor.Abstractions.UnitTest/Zaabee.Compressor.Abstractions.UnitTest.csproj @@ -0,0 +1,30 @@ + + + + net48;net6.0;net7.0;net8.0 + enable + enable + latest + false + true + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + +