Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static void CompareEpubLocalContentFileRefs(EpubLocalContentFileRef? expe
{
Assert.NotNull(actual);
Assert.Equal(expected.FilePath, actual.FilePath);
Assert.Equal(expected.ContentFileEntry, actual.ContentFileEntry);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using VersOne.Epub.Test.Unit.Mocks;
using VersOne.Epub.Environment;
using VersOne.Epub.Test.Unit.Mocks;

namespace VersOne.Epub.Test.Unit.Content.Base
{
Expand All @@ -17,7 +18,7 @@ public class EpubContentFileRefTests
private const EpubContentType BYTE_FILE_CONTENT_TYPE = EpubContentType.IMAGE_JPEG;
private const string BYTE_FILE_CONTENT_MIME_TYPE = "image/jpeg";

private static readonly byte[] BYTE_FILE_CONTENT = new byte[] { 0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46 };
private static readonly byte[] BYTE_FILE_CONTENT = [0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46];

private static EpubContentFileRefMetadata LocalTextFileRefMetadata => new(LOCAL_TEXT_FILE_NAME, TEXT_FILE_CONTENT_TYPE, TEXT_FILE_CONTENT_MIME_TYPE);

Expand All @@ -30,8 +31,11 @@ public class EpubContentFileRefTests
[Fact(DisplayName = "EpubLocalTextContentFileRef constructor should set correct property values")]
public void LocalTextContentFileRefConstructorTest()
{
EpubLocalTextContentFileRef epubLocalTextContentFileRef = new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, new TestEpubContentLoader());
IZipFileEntry testContentFileEntry = new TestZipFileEntry();
EpubLocalTextContentFileRef epubLocalTextContentFileRef =
new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testContentFileEntry, new TestEpubContentLoader());
Assert.Equal(LOCAL_TEXT_FILE_NAME, epubLocalTextContentFileRef.Key);
Assert.Equal(testContentFileEntry, epubLocalTextContentFileRef.ContentFileEntry);
Assert.Equal(TEXT_FILE_CONTENT_TYPE, epubLocalTextContentFileRef.ContentType);
Assert.Equal(TEXT_FILE_CONTENT_MIME_TYPE, epubLocalTextContentFileRef.ContentMimeType);
Assert.Equal(EpubContentLocation.LOCAL, epubLocalTextContentFileRef.ContentLocation);
Expand All @@ -42,8 +46,11 @@ public void LocalTextContentFileRefConstructorTest()
[Fact(DisplayName = "EpubLocalByteContentFileRef constructor should set correct property values")]
public void LocalByteContentFileRefConstructorTest()
{
EpubLocalByteContentFileRef epubLocalByteContentFileRef = new(LocalByteFileRefMetadata, LOCAL_BYTE_FILE_PATH, new TestEpubContentLoader());
IZipFileEntry testContentFileEntry = new TestZipFileEntry();
EpubLocalByteContentFileRef epubLocalByteContentFileRef =
new(LocalByteFileRefMetadata, LOCAL_BYTE_FILE_PATH, testContentFileEntry, new TestEpubContentLoader());
Assert.Equal(LOCAL_BYTE_FILE_NAME, epubLocalByteContentFileRef.Key);
Assert.Equal(testContentFileEntry, epubLocalByteContentFileRef.ContentFileEntry);
Assert.Equal(BYTE_FILE_CONTENT_TYPE, epubLocalByteContentFileRef.ContentType);
Assert.Equal(BYTE_FILE_CONTENT_MIME_TYPE, epubLocalByteContentFileRef.ContentMimeType);
Assert.Equal(EpubContentLocation.LOCAL, epubLocalByteContentFileRef.ContentLocation);
Expand Down Expand Up @@ -78,13 +85,13 @@ public void RemoteByteContentFileRefConstructorTest()
[Fact(DisplayName = "EpubLocalTextContentFileRef constructor should throw ArgumentNullException if the supplied metadata parameter is null")]
public void CreateEpubLocalTextContentFileRefWithNullMetadataTest()
{
Assert.Throws<ArgumentNullException>(() => new EpubLocalTextContentFileRef(null!, LOCAL_TEXT_FILE_PATH, new TestEpubContentLoader()));
Assert.Throws<ArgumentNullException>(() => new EpubLocalTextContentFileRef(null!, LOCAL_TEXT_FILE_PATH, null, new TestEpubContentLoader()));
}

[Fact(DisplayName = "EpubLocalByteContentFileRef constructor should throw ArgumentNullException if the supplied metadata parameter is null")]
public void CreateEpubLocalByteContentFileRefWithNullMetadataTest()
{
Assert.Throws<ArgumentNullException>(() => new EpubLocalByteContentFileRef(null!, LOCAL_BYTE_FILE_PATH, new TestEpubContentLoader()));
Assert.Throws<ArgumentNullException>(() => new EpubLocalByteContentFileRef(null!, LOCAL_BYTE_FILE_PATH, null, new TestEpubContentLoader()));
}

[Fact(DisplayName = "EpubRemoteTextContentFileRef constructor should throw ArgumentNullException if the supplied metadata parameter is null")]
Expand All @@ -102,13 +109,13 @@ public void CreateEpubRemoteByteContentFileRefWithNullMetadataTest()
[Fact(DisplayName = "EpubLocalTextContentFileRef constructor should throw ArgumentNullException if the supplied epubContentLoader parameter is null")]
public void CreateEpubLocalTextContentFileRefWithNullContentLoaderTest()
{
Assert.Throws<ArgumentNullException>(() => new EpubLocalTextContentFileRef(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, null!));
Assert.Throws<ArgumentNullException>(() => new EpubLocalTextContentFileRef(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, null, null!));
}

[Fact(DisplayName = "EpubLocalByteContentFileRef constructor should throw ArgumentNullException if the supplied epubContentLoader parameter is null")]
public void CreateEpubLocalByteContentFileRefWithNullContentLoaderTest()
{
Assert.Throws<ArgumentNullException>(() => new EpubLocalByteContentFileRef(LocalByteFileRefMetadata, LOCAL_BYTE_FILE_PATH, null!));
Assert.Throws<ArgumentNullException>(() => new EpubLocalByteContentFileRef(LocalByteFileRefMetadata, LOCAL_BYTE_FILE_PATH, null, null!));
}

[Fact(DisplayName = "EpubRemoteTextContentFileRef constructor should throw ArgumentNullException if the supplied epubContentLoader parameter is null")]
Expand All @@ -126,103 +133,123 @@ public void CreateEpubRemoteByteContentFileRefWithNullContentLoaderTest()
[Fact(DisplayName = "EpubLocalTextContentFileRef constructor should throw ArgumentNullException if the supplied file path is null")]
public void CreateEpubLocalTextContentFileRefWithNullFilePathTest()
{
Assert.Throws<ArgumentNullException>(() => new EpubLocalTextContentFileRef(LocalTextFileRefMetadata, null!, new TestEpubContentLoader()));
Assert.Throws<ArgumentNullException>(() => new EpubLocalTextContentFileRef(LocalTextFileRefMetadata, null!, null, new TestEpubContentLoader()));
}

[Fact(DisplayName = "EpubLocalByteContentFileRef constructor should throw ArgumentNullException if the supplied file path is null")]
public void CreateEpubLocalByteContentFileRefWithNullFilePathTest()
{
Assert.Throws<ArgumentNullException>(() => new EpubLocalByteContentFileRef(LocalByteFileRefMetadata, null!, new TestEpubContentLoader()));
Assert.Throws<ArgumentNullException>(() => new EpubLocalByteContentFileRef(LocalByteFileRefMetadata, null!, null, new TestEpubContentLoader()));
}

[Fact(DisplayName = "Reading local text content file synchronously should succeed")]
public void LocalTextContentFileRefReadContentTest()
{
TestZipFileEntry testZipFileEntry = new(TEXT_FILE_CONTENT);
TestEpubContentLoader testEpubContentLoader = new(TEXT_FILE_CONTENT);
EpubLocalTextContentFileRef epubLocalTextContentFileRef = new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testEpubContentLoader);
EpubLocalTextContentFileRef epubLocalTextContentFileRef =
new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testZipFileEntry, testEpubContentLoader);
string content = epubLocalTextContentFileRef.ReadContent();
Assert.Equal(TEXT_FILE_CONTENT, content);
}

[Fact(DisplayName = "Reading local text content file asynchronously should succeed")]
public async Task LocalTextContentFileRefReadContentAsyncTest()
{
TestZipFileEntry testZipFileEntry = new(TEXT_FILE_CONTENT);
TestEpubContentLoader testEpubContentLoader = new(TEXT_FILE_CONTENT);
EpubLocalTextContentFileRef epubLocalTextContentFileRef = new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testEpubContentLoader);
EpubLocalTextContentFileRef epubLocalTextContentFileRef =
new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testZipFileEntry, testEpubContentLoader);
string content = await epubLocalTextContentFileRef.ReadContentAsync();
Assert.Equal(TEXT_FILE_CONTENT, content);
}

[Fact(DisplayName = "Reading local byte content file synchronously should succeed")]
public void LocalByteContentFileRefReadContentTest()
{
TestZipFileEntry testZipFileEntry = new(BYTE_FILE_CONTENT);
TestEpubContentLoader testEpubContentLoader = new(BYTE_FILE_CONTENT);
EpubLocalByteContentFileRef epubLocalByteContentFileRef = new(LocalByteFileRefMetadata, LOCAL_BYTE_FILE_PATH, testEpubContentLoader);
EpubLocalByteContentFileRef epubLocalByteContentFileRef =
new(LocalByteFileRefMetadata, LOCAL_BYTE_FILE_PATH, testZipFileEntry, testEpubContentLoader);
byte[] content = epubLocalByteContentFileRef.ReadContent();
Assert.Equal(BYTE_FILE_CONTENT, content);
}

[Fact(DisplayName = "Reading local byte content file asynchronously should succeed")]
public async Task LocalByteContentFileRefReadContentAsyncTest()
{
TestZipFileEntry testZipFileEntry = new(BYTE_FILE_CONTENT);
TestEpubContentLoader testEpubContentLoader = new(BYTE_FILE_CONTENT);
EpubLocalByteContentFileRef epubLocalByteContentFileRef = new(LocalByteFileRefMetadata, LOCAL_BYTE_FILE_PATH, testEpubContentLoader);
EpubLocalByteContentFileRef epubLocalByteContentFileRef =
new(LocalByteFileRefMetadata, LOCAL_BYTE_FILE_PATH, testZipFileEntry, testEpubContentLoader);
byte[] content = await epubLocalByteContentFileRef.ReadContentAsync();
Assert.Equal(BYTE_FILE_CONTENT, content);
}

[Fact(DisplayName = "Reading local content file as text synchronously should succeed")]
public void LocalContentFileRefReadContentAsTextTest()
{
TestZipFileEntry testZipFileEntry = new(TEXT_FILE_CONTENT);
TestEpubContentLoader testEpubContentLoader = new(TEXT_FILE_CONTENT);
EpubLocalTextContentFileRef epubLocalTextContentFileRef = new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testEpubContentLoader);
EpubLocalTextContentFileRef epubLocalTextContentFileRef =
new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testZipFileEntry, testEpubContentLoader);
string content = epubLocalTextContentFileRef.ReadContentAsText();
Assert.Equal(TEXT_FILE_CONTENT, content);
}

[Fact(DisplayName = "Reading local content file as text asynchronously should succeed")]
public async Task LocalContentFileRefReadContentAsTextAsyncTest()
{
TestZipFileEntry testZipFileEntry = new(TEXT_FILE_CONTENT);
TestEpubContentLoader testEpubContentLoader = new(TEXT_FILE_CONTENT);
EpubLocalTextContentFileRef epubLocalTextContentFileRef = new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testEpubContentLoader);
EpubLocalTextContentFileRef epubLocalTextContentFileRef =
new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testZipFileEntry, testEpubContentLoader);
string content = await epubLocalTextContentFileRef.ReadContentAsTextAsync();
Assert.Equal(TEXT_FILE_CONTENT, content);
}

[Fact(DisplayName = "Reading local content file as bytes synchronously should succeed")]
public void LocalContentFileRefReadContentAsBytesTest()
{
TestZipFileEntry testZipFileEntry = new(BYTE_FILE_CONTENT);
TestEpubContentLoader testEpubContentLoader = new(BYTE_FILE_CONTENT);
EpubLocalByteContentFileRef epubLocalByteContentFileRef = new(LocalByteFileRefMetadata, LOCAL_BYTE_FILE_PATH, testEpubContentLoader);
EpubLocalByteContentFileRef epubLocalByteContentFileRef =
new(LocalByteFileRefMetadata, LOCAL_BYTE_FILE_PATH, testZipFileEntry, testEpubContentLoader);
byte[] content = epubLocalByteContentFileRef.ReadContentAsBytes();
Assert.Equal(BYTE_FILE_CONTENT, content);
}

[Fact(DisplayName = "Reading local content file as bytes asynchronously should succeed")]
public async Task LocalContentFileRefReadContentAsBytesAsyncTest()
{
TestZipFileEntry testZipFileEntry = new(BYTE_FILE_CONTENT);
TestEpubContentLoader testEpubContentLoader = new(BYTE_FILE_CONTENT);
EpubLocalByteContentFileRef epubLocalByteContentFileRef = new(LocalByteFileRefMetadata, LOCAL_BYTE_FILE_PATH, testEpubContentLoader);
EpubLocalByteContentFileRef epubLocalByteContentFileRef =
new(LocalByteFileRefMetadata, LOCAL_BYTE_FILE_PATH, testZipFileEntry, testEpubContentLoader);
byte[] content = await epubLocalByteContentFileRef.ReadContentAsBytesAsync();
Assert.Equal(BYTE_FILE_CONTENT, content);
}

[Fact(DisplayName = "Getting local content file stream synchronously should succeed")]
public void LocalContentFileRefGetContentStreamTest()
{
TestZipFileEntry testZipFileEntry = new(TEXT_FILE_CONTENT);
using MemoryStream testStream = new();
TestEpubContentLoader testEpubContentLoader = new(testStream);
EpubLocalTextContentFileRef epubLocalTextContentFileRef = new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testEpubContentLoader);
EpubLocalTextContentFileRef epubLocalTextContentFileRef =
new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testZipFileEntry, testEpubContentLoader);
Stream contentStream = epubLocalTextContentFileRef.GetContentStream();
Assert.Equal(testStream, contentStream);
}

[Fact(DisplayName = "Getting local content file stream asynchronously should succeed")]
public async Task LocalContentFileRefGetContentStreamAsyncTest()
{
TestZipFileEntry testZipFileEntry = new(TEXT_FILE_CONTENT);
using MemoryStream testStream = new();
TestEpubContentLoader testEpubContentLoader = new(testStream);
EpubLocalTextContentFileRef epubLocalTextContentFileRef = new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testEpubContentLoader);
EpubLocalTextContentFileRef epubLocalTextContentFileRef =
new(LocalTextFileRefMetadata, LOCAL_TEXT_FILE_PATH, testZipFileEntry, testEpubContentLoader);
Stream contentStream = await epubLocalTextContentFileRef.GetContentStreamAsync();
Assert.Equal(testStream, contentStream);
}
Expand Down
Loading
Loading