Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        public void EPFArchive_NullInputStream_Throws_Test()
        {
            //Arrange
            //Act
            var epfArchive = EPFArchive.ToExtract(null);

            //Assert
        }
Exemplo n.º 3
0
        public void EPFArchive_InvalidInputStream_Throws_Test()
        {
            //Arrange
            //Act
            var epfArchive = EPFArchive.ToExtract(_invalidEPFFile);

            //Assert
        }
Exemplo n.º 4
0
        public void Save_ThrowsInvalidOperationException_Test()
        {
            //Arrange
            var epfArchive = EPFArchive.ToExtract(_validEPFFile);

            //Act
            epfArchive.Save();

            //Assert
        }
Exemplo n.º 5
0
        public void ReplaceEntry_Throws()
        {
            //Arrange
            var epfArchive = EPFArchive.ToExtract(_validEPFFile);

            //Act
            epfArchive.ReplaceEntry("Huh.txt", @".\SandBox\Huh.png");

            //Assert
        }
Exemplo n.º 6
0
        public void RemoveEntry_Throws_Test()
        {
            //Arrange
            var epfArchive = EPFArchive.ToExtract(_validEPFFile);

            //Act
            var result = epfArchive.RemoveEntry("TFile1.txt");

            //Assert
        }
Exemplo n.º 7
0
        public void ExtractEntries_InvalidOutputFolder_Throws_Test()
        {
            //Arrange
            var epfArchive = EPFArchive.ToExtract(_validEPFFile);

            //Act
            epfArchive.ExtractEntries(MISSING_OUTPUT_EXTRACT_DIR, TEST_ENTRIES);

            //Assert
        }
Exemplo n.º 8
0
        public void ExtractAll_InvalidOutputFolder_Throws_Test()
        {
            //Arrange
            var epfArchive = EPFArchive.ToExtract(_validEPFFile);

            //Act
            epfArchive.ExtractAll(MISSING_OUTPUT_EXTRACT_DIR);

            //Assert
        }
Exemplo n.º 9
0
        public void Dispose_NoException_Test()
        {
            //Arrange
            var epfArchive = EPFArchive.ToExtract(_validEPFFile);

            //Act
            epfArchive.Dispose();

            //Assert
        }
Exemplo n.º 10
0
        public void CreateEntry_Throws_Test()
        {
            //Arrange
            var epfArchive = EPFArchive.ToExtract(_validEPFFile);

            //Act
            epfArchive.CreateEntry("TFile1.txt", @".\SandBox\ValidEntry.png");

            //Assert
        }
Exemplo n.º 11
0
        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.");
        }
Exemplo n.º 12
0
        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
        }
Exemplo n.º 13
0
        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.");
        }
Exemplo n.º 14
0
        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.");
        }
Exemplo n.º 15
0
        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.");
        }
Exemplo n.º 16
0
        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");
        }
Exemplo n.º 17
0
        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}");
            }
        }
Exemplo n.º 18
0
        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");
        }
Exemplo n.º 19
0
        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.");
        }