diff --git a/DeepLTests/BaseDeepLTest.cs b/DeepLTests/BaseDeepLTest.cs index 90bbda7..8eae5b7 100644 --- a/DeepLTests/BaseDeepLTest.cs +++ b/DeepLTests/BaseDeepLTest.cs @@ -22,7 +22,6 @@ public class BaseDeepLTest { protected static readonly string? ServerUrl; protected static readonly string? ProxyUrl; protected static readonly Dictionary DocMinificationTestFilesMapping; - private static readonly string DocMinificationTestZipFile = "example_zip_template.zip"; private static Random _random = new Random(); static BaseDeepLTest() { @@ -38,7 +37,8 @@ static BaseDeepLTest() { ProxyUrl = Environment.GetEnvironmentVariable("DEEPL_PROXY_URL"); DocMinificationTestFilesMapping = new Dictionary() { {".docx", "example_document_template.docx" }, - {".pptx", "example_presentation_template.pptx" } + {".pptx", "example_presentation_template.pptx" }, + {".zip", "example_zip_template.zip" } }; } @@ -245,16 +245,8 @@ protected static string CreateMinifiedTestDocument(string extension, string outp return outputFilePath; } - protected static string CreateDeminifiedTestDocument(string outputDirectory) { - var extractionDir = TempDir(); - var testFilePath = GetFullPathForTestFile(DocMinificationTestZipFile); - var outputFilePath = Path.Combine(outputDirectory, "example_zip.zip"); - ZipFile.ExtractToDirectory(testFilePath, extractionDir); - using var image = new MagickImage(MagickColors.Gray, 20000, 20000); - image.Write(Path.Combine(extractionDir, "placeholder_image.png")); - ZipFile.CreateFromDirectory(extractionDir, outputFilePath); - Directory.Delete(extractionDir, true); - return outputFilePath; + protected static void CreatePlaceholderImage() { + } public bool AssertDirectoriesAreEqual(string dir1, string dir2, string message = "") diff --git a/DeepLTests/DocumentMinificationTest.cs b/DeepLTests/DocumentMinificationTest.cs index 94bd481..b166659 100644 --- a/DeepLTests/DocumentMinificationTest.cs +++ b/DeepLTests/DocumentMinificationTest.cs @@ -56,10 +56,9 @@ public void TestDocumentMinificationCleansUpProperly(bool shouldCleanUp) { File.Delete(minifiedDocumentPath); } - [Fact] public void TestDeminifyDocumentHappyPath() { - var inputFile = CreateDeminifiedTestDocument(_tempDir); + var inputFile = CreateMinifiedTestDocument(".zip", _tempDir); var outputFile = Path.Combine(_tempDir, "example_zip_transformed.zip"); var minifier = new DocumentMinifier(_tempDir); var minifiedFile = minifier.MinifyDocument(inputFile, true); @@ -76,6 +75,29 @@ public void TestDeminifyDocumentHappyPath() { Directory.Delete(_tempDir, true); } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void TestDocumentDeminificationCleansUpProperly(bool shouldCleanUp) { + var minifiedTestDocument = CreateMinifiedTestDocument(".zip", _tempDir); + var outputFile = Path.Combine(_tempDir, "example_zip_transformed.zip"); + var minifier = new DocumentMinifier(); + var minifiedFile = minifier.MinifyDocument(minifiedTestDocument, true); + minifier.DeminifyDocument(minifiedFile, outputFile, shouldCleanUp); + + Assert.Equal(shouldCleanUp, !Directory.Exists(minifier.GetExtractedDocDirectory())); + + // Cleanup + if (!shouldCleanUp) { + Directory.Delete(minifier.GetExtractedDocDirectory(), true); + Directory.Delete(minifier.GetOriginalMediaDirectory(), true); + File.Delete(minifiedFile); + } + File.Delete(minifiedTestDocument); + File.Delete(outputFile); + } + [RealServerOnlyFact] public async Task TestMinifyAndTranslateDocuments() { var translator = CreateTestTranslator();