From 6689b91e70abd0609d2bd12fdc358a11878c7cb8 Mon Sep 17 00:00:00 2001 From: Lunastra Date: Tue, 14 Dec 2021 22:24:28 -0800 Subject: [PATCH] Add testing compression method. --- .../Implementations/SqlDAO.cs | 6 +++-- .../ArchivingXUnitTest.cs | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs index 127d03e..487838e 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator.DataAccess/Implementations/SqlDAO.cs @@ -155,8 +155,10 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess // Check to see if the file is hidden or already compressed before compressing the file. if (atrribute != FileAttributes.Hidden && atrribute != FileAttributes.Compressed) { - using FileStream outputFile = File.Create(fileName + ".gz"); - + var compFileName = Path.ChangeExtension(fileName, ".gz"); + //using FileStream outputFile = File.Create(fileName + ".gz"); + using FileStream outputFile = File.Create(compFileName); + using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress); origFile.CopyTo(compressor); diff --git a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs index 71b5de3..196ad55 100644 --- a/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs +++ b/Source Code/TeamHobby.HobbyProjectGenerator/TeamHobby.Archiving.xTests/ArchivingXUnitTest.cs @@ -174,5 +174,29 @@ namespace TeamHobby.Archiving.xTests bool actualVal = File.Exists(filepath); Assert.Equal(expectedVal, actualVal); } + + [Fact] + public void IsFileCompressed() + { + // Arrange + SqlDAO sqlDAO = new SqlDAO(dbInfo); + ArchiveManager archiveManager = new ArchiveManager(sqlDAO); + + // Create the folder and the csv file to be compressed. + archiveManager.CreateArchiveFolder(); + string filePath = archiveManager.CreateOutFileName(); + sqlDAO.CopyToFile(filePath); + FileAttributes expectedAttribute = FileAttributes.Archive; + string compFilePath = Path.ChangeExtension(filePath, ".gz"); + + // Act + sqlDAO.CompressFile(filePath); + + // Assert + FileAttributes actualAttribute = File.GetAttributes(compFilePath); + Assert.Equal(expectedAttribute, actualAttribute); + + } + } } \ No newline at end of file