private void OpenArchive(object argument) { try { var archiveFilePath = argument as string; var fileStream = File.Open(archiveFilePath, FileMode.Open, FileAccess.ReadWrite); _epfArchive = EPFArchive.ToUpdate(fileStream); _epfArchive.EntryChanged += _epfArchive_EntryChanged; _epfArchive.PropertyChanged += _epfArchive_PropertyChanged; dispatcher.Invoke(RefreshEntries); ArchiveFilePath = archiveFilePath; AppLabel = $"{APP_NAME} - {ArchiveFilePath}"; IsReadOnly = false; HasHiddenData = _epfArchive.HasHiddenData; IsArchiveOpened = true; IsArchiveSaveAllowed = true; Status.Log.Success($"Archive '{ Path.GetFileName(ArchiveFilePath)}' opened."); } catch (Exception ex) { Status.Log.Error($"Unable to open archive. Reason: {ex.Message}"); } }
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.ToUpdate(null); //Assert }
public void EPFArchive_ReadOnlyInputStream_Throws_Test() { //Arrange //Act var epfArchive = EPFArchive.ToUpdate(_readonlyEPFArchiveFile); //Assert }
public void EPFArchive_InvalidInputStream_Throws_Test() { //Arrange //Act var epfArchive = EPFArchive.ToUpdate(_notEPFArchiveFile); //Assert }
public void ReplaceEntry_NotExistingEntryName_NotExistingInputFile_Throws() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act epfArchive.ReplaceEntry("Huh.txt", @".\SandBox\Huh.png"); //Assert }
public void ExtractEntries_InvalidOutputFolder_Throws_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act epfArchive.ExtractEntries(MISSING_OUTPUT_EXTRACT_DIR, TEST_ENTRIES); //Assert }
public void CreateEntry_ExistingEntryName_InvalidInputFile_Throws_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act epfArchive.CreateEntry("Huh.txt", @".\SandBox\Huh.txt"); //Assert }
public void ReplaceEntry_NotExistingEntryName_ExistingInputFile_ThrowsArgumentException() { //Arrange Helpers.DeployResource(@".\SandBox\ValidEntry.png", "ValidEntry.png"); var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act epfArchive.ReplaceEntry("Huh.txt", @".\SandBox\ValidEntry.png"); //Assert }
public void FindEntry_NotExistingEntry_ReturnsNull_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act var entry = epfArchive.FindEntry("Huh.txt"); //Assert Assert.IsTrue(entry == null, "Entry should not exist."); }
public void FindEntry_ExistingEntry_ReturnsEntryObject_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act var entry = epfArchive.FindEntry("TFile1.txt"); //Assert Assert.IsTrue(entry != null, "Entry supose to exist in archive."); }
public void ExtractTo_InvalidOutputFolder_Throws_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); var epfArchiveEntry = epfArchive.FindEntry(EXISTING_ENTRY_NAME_A); //Act epfArchiveEntry.ExtractTo(INVALID_OUTPUT_EXTRACT_DIR); //Assert }
public void Dispose_LeaveInputStreamOpen_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile, true); //Act epfArchive.Dispose(); //Assert Assert.IsTrue(_readWriteEPFArchiveFile.CanRead, "Input stream should be left open"); }
public void Dispose_CloseInputStream_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act epfArchive.Dispose(); //Assert Assert.IsTrue(!_readWriteEPFArchiveFile.CanRead, "Input stream should be closed"); }
public void CreateEntry_ExistingEntryName_ValidInputFile_Throws_Test() { //Arrange Helpers.DeployResource(@".\SandBox\ValidEntry.png", "ValidEntry.png"); var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act epfArchive.CreateEntry("TFile1.txt", @".\SandBox\ValidEntry.png"); //Assert }
public void CreateEntry_NotExistingEntryName_ValidInputFile_ReturnsEntryObject_Test() { //Arrange Helpers.DeployResource(@".\SandBox\ValidEntry.png", "ValidEntry.png"); var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act var entry = epfArchive.CreateEntry("VALID_ENTRY", @".\SandBox\ValidEntry.png"); //Assert Assert.IsTrue(entry != null, "Created entry object should not be null."); }
public void ReplaceEntry_ExistingEntryName_ExistingInputFile_ReturnsEntryObjectTest() { //Arrange Helpers.DeployResource(@".\SandBox\ValidEntry.png", "ValidEntry.png"); var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act var result = epfArchive.ReplaceEntry("TFile1.txt", @".\SandBox\ValidEntry.png"); //Assert Assert.IsTrue(result != null, "Entry supose to exist in archive."); }
public void RemoveEntry_ExistingEntryName_EntryRemoved_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act var beforeRemove = epfArchive.Entries.Count; var result = epfArchive.RemoveEntry("TFile1.txt"); var afterRemove = epfArchive.Entries.Count; //Assert Assert.IsTrue(result, "RemoveEntry should return true."); Assert.IsTrue(beforeRemove > afterRemove, "There should be less entries after remove."); }
public void RemoveEntry_NotExistingEntryName_ReturnsFalse_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act var beforeRemove = epfArchive.Entries.Count; var result = epfArchive.RemoveEntry("Huh.txt"); var afterRemove = epfArchive.Entries.Count; //Assert Assert.IsFalse(result, "RemoveEntry should return false."); Assert.IsTrue(beforeRemove == afterRemove, "Entries number should not change."); }
public void get_IsModified_ReturnsTrue_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //Act var isModifiedBefore = epfArchive.IsModified; epfArchive.RemoveEntry("TFile1.txt"); var isModifiedAfter = epfArchive.IsModified; //Assert Assert.IsTrue(!isModifiedBefore && isModifiedAfter, "Extracted entry should be exact as saved entry"); }
public void ExtractTo_ValidOutputFolder_ExtractsEntry_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); var epfArchiveEntry = epfArchive.FindEntry(EXISTING_ENTRY_NAME_A); //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_A}"); //Assert Assert.IsTrue(areSame, "Extracted entry file should be exact as expected file"); }
public void set_ToCompress_Changes_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); var epfArchiveEntry = epfArchive.FindEntry(EXISTING_ENTRY_NAME_B); var isModifiedBefore = epfArchiveEntry.IsModified; epfArchiveEntry.ToCompress = !epfArchiveEntry.ToCompress; var isModifiedAfter = epfArchiveEntry.IsModified; //Assert Assert.IsTrue(!isModifiedBefore && isModifiedAfter, "IsModified should have changed to true."); }
internal EPFArchive GetArchive(string archivePath) { string normalizedPath = IOHelper.GetNormalizedPath(archivePath); EPFArchive archive = null; if (!_openedArchives.TryGetValue(normalizedPath, out archive)) { File.Copy(normalizedPath, normalizedPath + ".bkp", true); archive = EPFArchive.ToUpdate(File.Open(normalizedPath, FileMode.Open), false); _openedArchives.Add(normalizedPath, archive); logger.Verbose($"EPF Archive data source '{normalizedPath}' opened for update."); } return(archive); }
public void ExtractEntries_ValidOutputFolder_EntriesExtracted_Test() { //Arrange var epfArchive = EPFArchive.ToUpdate(_readWriteEPFArchiveFile); //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."); }
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"); }