public void Open_OpensEntryStreamForModificationAndStorage_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); var epfArchiveEntry = epfArchive.FindEntry(EXISTING_ENTRY_NAME_B); var entryStream = epfArchiveEntry.Open(); //Act using (var toSaveInArchive = File.OpenRead($@"{EXPECTED_EXTRACT_DIR}\{EXISTING_ENTRY_NAME_A}")) { toSaveInArchive.CopyTo(entryStream); entryStream.SetLength(toSaveInArchive.Length); } epfArchive.Save(); epfArchive.Dispose(); using (var savedFile = File.OpenRead(@".\SandBox\ReadWriteValidArchive.epf")) { epfArchive = EPFArchive.ToExtract(savedFile); epfArchive.ExtractEntries(VALID_OUTPUT_EXTRACT_DIR, new string[] { EXISTING_ENTRY_NAME_B }); } var areSame = Helpers.FileEquals($@"{EXPECTED_EXTRACT_DIR}\{EXISTING_ENTRY_NAME_A}", $@"{ VALID_OUTPUT_EXTRACT_DIR}\{EXISTING_ENTRY_NAME_B}"); //Assert Assert.IsTrue(areSame, "Extracted entry should be exact as saved entry"); }
public void EPFArchive_NullInputStream_Throws_Test() { //Arrange //Act var epfArchive = EPFArchive.ToExtract(null); //Assert }
public void EPFArchive_InvalidInputStream_Throws_Test() { //Arrange //Act var epfArchive = EPFArchive.ToExtract(_invalidEPFFile); //Assert }
public void Save_ThrowsInvalidOperationException_Test() { //Arrange var epfArchive = EPFArchive.ToExtract(_validEPFFile); //Act epfArchive.Save(); //Assert }
public void ReplaceEntry_Throws() { //Arrange var epfArchive = EPFArchive.ToExtract(_validEPFFile); //Act epfArchive.ReplaceEntry("Huh.txt", @".\SandBox\Huh.png"); //Assert }
public void RemoveEntry_Throws_Test() { //Arrange var epfArchive = EPFArchive.ToExtract(_validEPFFile); //Act var result = epfArchive.RemoveEntry("TFile1.txt"); //Assert }
public void ExtractEntries_InvalidOutputFolder_Throws_Test() { //Arrange var epfArchive = EPFArchive.ToExtract(_validEPFFile); //Act epfArchive.ExtractEntries(MISSING_OUTPUT_EXTRACT_DIR, TEST_ENTRIES); //Assert }
public void ExtractAll_InvalidOutputFolder_Throws_Test() { //Arrange var epfArchive = EPFArchive.ToExtract(_validEPFFile); //Act epfArchive.ExtractAll(MISSING_OUTPUT_EXTRACT_DIR); //Assert }
public void Dispose_NoException_Test() { //Arrange var epfArchive = EPFArchive.ToExtract(_validEPFFile); //Act epfArchive.Dispose(); //Assert }
public void CreateEntry_Throws_Test() { //Arrange var epfArchive = EPFArchive.ToExtract(_validEPFFile); //Act epfArchive.CreateEntry("TFile1.txt", @".\SandBox\ValidEntry.png"); //Assert }
public void EPFArchive_ValidInputStream_OpensArchiveWithEntries_Test() { //Arrange //Act var epfArchive = EPFArchive.ToExtract(_validEPFFile); var entriesNo = epfArchive.Entries.Count; //Assert Assert.IsTrue(entriesNo != 0, "Opened EPF Archive should contain entries."); }
public void ExtractTo_InvalidOutputFolder_Throws_Test() { //Arrange var epfArchive = EPFArchive.ToExtract(_readWriteEPFArchiveFile); var epfArchiveEntry = epfArchive.FindEntry(EXISTING_ENTRY_NAME); //Act epfArchiveEntry.ExtractTo(INVALID_OUTPUT_EXTRACT_DIR); //Assert }
public void FindEntry_ExistingEntry_ReturnsEntryObject_Test() { //Arrange var epfArchive = EPFArchive.ToExtract(_validEPFFile); //Act var entry = epfArchive.FindEntry("TFile1.txt"); //Assert Assert.IsTrue(entry != null, "Entry supose to exist in archive."); }
public void FindEntry_NotExistingEntry_ReturnsNull_Test() { //Arrange var epfArchive = EPFArchive.ToExtract(_validEPFFile); //Act var entry = epfArchive.FindEntry("Huh.txt"); //Assert Assert.IsTrue(entry == null, "Entry should not exist."); }
public void Open_ReturnsStream_Test() { //Arrange var epfArchive = EPFArchive.ToExtract(_readWriteEPFArchiveFile); var epfArchiveEntry = epfArchive.FindEntry(EXISTING_ENTRY_NAME); //Act var entryStream1 = epfArchiveEntry.Open(); var entryStream2 = epfArchiveEntry.Open(); //Assert Assert.IsTrue(entryStream1 != entryStream2, "Entry streams should be different."); }
public void ExtractTo_ValidOutputFolder_ExtractsEntry_Test() { //Arrange var epfArchive = EPFArchive.ToExtract(_readWriteEPFArchiveFile); var epfArchiveEntry = epfArchive.FindEntry(EXISTING_ENTRY_NAME); //Act epfArchiveEntry.ExtractTo(VALID_OUTPUT_EXTRACT_DIR); var areSame = Helpers.FileEquals($@"{EXPECTED_EXTRACT_DIR}\{EXPECTED_EXTRACTED_FILE_NAME}", $@"{ VALID_OUTPUT_EXTRACT_DIR}\{EXISTING_ENTRY_NAME}"); //Assert Assert.IsTrue(areSame, "Extracted entry file should be exact as expected file"); }
private void OpenArchiveReadOnly(string archiveFilePath) { try { var fileStream = File.Open(archiveFilePath, FileMode.Open, FileAccess.Read); _epfArchive = EPFArchive.ToExtract(fileStream); dispatcher.Invoke(RefreshEntries); ArchiveFilePath = archiveFilePath; AppLabel = $"{APP_NAME} - {ArchiveFilePath} (Read-Only)"; IsArchiveOpened = true; IsReadOnly = true; IsArchiveSaveAllowed = false; Status.Log.Success($"Archive '{ Path.GetFileName(ArchiveFilePath)}' opened in read-only mode."); } catch (Exception ex) { Status.Log.Error($"Unable to open archive in read-only mode. Reason: {ex.Message}"); } }
public void Save_SavesData_Test() { //Arrange Helpers.DeployResource(@".\SandBox\ValidEntry.png", "ValidEntry.png"); var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act var epfEntry = epfArchive.CreateEntry("NewEntry.png", @".\SandBox\ValidEntry.png"); epfArchive.Save(); epfArchive.Dispose(); using (var savedFile = File.OpenRead(@".\SandBox\ReadWriteValidArchive.epf")) { epfArchive = EPFArchive.ToExtract(savedFile); epfArchive.ExtractEntries(VALID_OUTPUT_EXTRACT_DIR, new string[] { "NewEntry.png" }); } var areSame = Helpers.FileEquals(@".\SandBox\ValidEntry.png", $@"{ VALID_OUTPUT_EXTRACT_DIR}\NewEntry.png"); //Assert Assert.IsTrue(areSame, "Extracted entry should be exact as saved entry"); }
public void ExtractEntries_ValidOutputFolder_EntriesExtracted_Test() { //Arrange var epfArchive = EPFArchive.ToExtract(_validEPFFile); //Act epfArchive.ExtractEntries(VALID_OUTPUT_EXTRACT_DIR, TEST_ENTRIES); //Assert int samefilesNo = 0; foreach (var entryName in TEST_ENTRIES) { if (Helpers.FileEquals($@"{EXPECTED_EXTRACT_DIR}\{entryName}", $@"{VALID_OUTPUT_EXTRACT_DIR}\{entryName}")) { samefilesNo++; } } Assert.IsTrue(samefilesNo == TEST_ENTRIES.Length, "Some of extracted files content is different than templates."); }