Add testing compression method.
This commit is contained in:
parent
03cfb10c10
commit
6689b91e70
@ -155,8 +155,10 @@ namespace TeamHobby.HobbyProjectGenerator.DataAccess
|
|||||||
// Check to see if the file is hidden or already compressed before compressing the file.
|
// Check to see if the file is hidden or already compressed before compressing the file.
|
||||||
if (atrribute != FileAttributes.Hidden && atrribute != FileAttributes.Compressed)
|
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);
|
using GZipStream compressor = new GZipStream(outputFile, CompressionMode.Compress);
|
||||||
origFile.CopyTo(compressor);
|
origFile.CopyTo(compressor);
|
||||||
|
|
||||||
|
|||||||
@ -174,5 +174,29 @@ namespace TeamHobby.Archiving.xTests
|
|||||||
bool actualVal = File.Exists(filepath);
|
bool actualVal = File.Exists(filepath);
|
||||||
Assert.Equal(expectedVal, actualVal);
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user