using VersOne.Epub.Internal; using VersOne.Epub.Options; using VersOne.Epub.Test.Unit.Mocks; namespace VersOne.Epub.Test.Unit.Readers { public class RootFilePathReaderTests { private const string EPUB_CONTAINER_FILE_PATH = "META-INF/container.xml"; private const string ROOT_FILE_PATH_FOR_CORRECT_CONTAINER_FILE = "OEBPS/content.opf"; private const string CORRECT_CONTAINER_FILE = $""" """; private const string INCORRECT_CONTAINER_FILE_NO_FULL_PATH_ATTRIBUTE = $""" """; private const string INCORRECT_CONTAINER_FILE_NO_ROOTFILE_ELEMENT = $""" """; private const string INCORRECT_CONTAINER_FILE_NO_ROOTFILES_ELEMENT = $""" """; private const string INCORRECT_CONTAINER_FILE_NO_CONTAINER_ELEMENT = $""" """; [Fact(DisplayName = "Constructing a RootFilePathReader instance with a non-null epubReaderOptions parameter should succeed")] public void ConstructorWithNonNullEpubReaderOptionsTest() { _ = new RootFilePathReader(new EpubReaderOptions()); } [Fact(DisplayName = "Constructing a RootFilePathReader instance with a null epubReaderOptions parameter should succeed")] public void ConstructorWithNullEpubReaderOptionsTest() { _ = new RootFilePathReader(null); } [Fact(DisplayName = "Getting root file path from a ZIP archive with a correct container file should succeed")] public async Task TestGetRootFilePathAsyncWithCorrectContainerFile() { TestZipFile testZipFile = new(); testZipFile.AddEntry(EPUB_CONTAINER_FILE_PATH, CORRECT_CONTAINER_FILE); RootFilePathReader rootFilePathReader = new(); string actualRootFilePath = await rootFilePathReader.GetRootFilePathAsync(testZipFile); Assert.Equal(ROOT_FILE_PATH_FOR_CORRECT_CONTAINER_FILE, actualRootFilePath); } [Fact(DisplayName = "Getting root file path from a ZIP archive without a container file should throw EpubContainerException")] public async Task TestGetRootFilePathAsyncWithNoContainerFile() { TestZipFile testZipFile = new(); RootFilePathReader rootFilePathReader = new(); await Assert.ThrowsAsync(() => rootFilePathReader.GetRootFilePathAsync(testZipFile)); } [Theory(DisplayName = "Getting root file path from a ZIP archive with an incorrect container file should throw EpubContainerException")] [InlineData(INCORRECT_CONTAINER_FILE_NO_FULL_PATH_ATTRIBUTE)] [InlineData(INCORRECT_CONTAINER_FILE_NO_ROOTFILE_ELEMENT)] [InlineData(INCORRECT_CONTAINER_FILE_NO_ROOTFILES_ELEMENT)] [InlineData(INCORRECT_CONTAINER_FILE_NO_CONTAINER_ELEMENT)] public async Task TestGetRootFilePathAsyncWithIncorrectContainerFile(string containerFileContent) { TestZipFile testZipFile = new(); testZipFile.AddEntry(EPUB_CONTAINER_FILE_PATH, containerFileContent); RootFilePathReader rootFilePathReader = new(); await Assert.ThrowsAsync(() => rootFilePathReader.GetRootFilePathAsync(testZipFile)); } } }