using System.Text; namespace VersOne.Epub.Test.Unit.Mocks { internal class TestEpubContentLoader : IEpubContentLoader { private readonly byte[]? byteContent; private readonly Stream? stream; public TestEpubContentLoader() { byteContent = Array.Empty(); stream = null; } public TestEpubContentLoader(string textContent) { byteContent = Encoding.UTF8.GetBytes(textContent); stream = null; } public TestEpubContentLoader(byte[] byteContent) { this.byteContent = byteContent; stream = null; } public TestEpubContentLoader(Stream stream) { byteContent = null; this.stream = stream; } public byte[] LoadContentAsBytes(EpubContentFileRefMetadata contentFileRefMetadata) { return byteContent ?? Array.Empty(); } public Task LoadContentAsBytesAsync(EpubContentFileRefMetadata contentFileRefMetadata) { return Task.FromResult(LoadContentAsBytes(contentFileRefMetadata)); } public string LoadContentAsText(EpubContentFileRefMetadata contentFileRefMetadata) { return byteContent != null ? Encoding.UTF8.GetString(byteContent) : String.Empty; } public Task LoadContentAsTextAsync(EpubContentFileRefMetadata contentFileRefMetadata) { return Task.FromResult(LoadContentAsText(contentFileRefMetadata)); } public Stream GetContentStream(EpubContentFileRefMetadata contentFileRefMetadata) { if (stream != null) { return stream; } else if (byteContent != null) { return new MemoryStream(byteContent); } else { return new MemoryStream(); } } public Task GetContentStreamAsync(EpubContentFileRefMetadata contentFileRefMetadata) { return Task.FromResult(GetContentStream(contentFileRefMetadata)); } } }