File size: 6,334 Bytes
fab29d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
namespace VersOne.Epub.Test.Comparers
{
internal static class EpubContentComparer
{
public static void CompareEpubContents(EpubContent expected, EpubContent actual)
{
CompareEpubLocalByteContentFiles(expected.Cover, actual.Cover);
CompareEpubLocalTextContentFiles(expected.NavigationHtmlFile, actual.NavigationHtmlFile);
CompareContentCollections(expected.Html, actual.Html, CompareEpubLocalTextContentFiles, CompareEpubRemoteTextContentFiles);
CompareContentCollections(expected.Css, actual.Css, CompareEpubLocalTextContentFiles, CompareEpubRemoteTextContentFiles);
CompareContentCollections(expected.Images, actual.Images, CompareEpubLocalByteContentFiles, CompareEpubRemoteByteContentFiles);
CompareContentCollections(expected.Fonts, actual.Fonts, CompareEpubLocalByteContentFiles, CompareEpubRemoteByteContentFiles);
CompareContentCollections(expected.Audio, actual.Audio, CompareEpubLocalByteContentFiles, CompareEpubRemoteByteContentFiles);
CompareContentCollections(expected.AllFiles, actual.AllFiles, CompareLocalEpubContentFilesWithContent, CompareRemoteEpubContentFilesWithContent);
}
public static void CompareEpubLocalTextContentFileLists(List<EpubLocalTextContentFile> expected, List<EpubLocalTextContentFile> actual)
{
CollectionComparer.CompareCollections(expected, actual, CompareEpubLocalTextContentFiles);
}
public static void CompareEpubLocalTextContentFiles(EpubLocalTextContentFile? expected, EpubLocalTextContentFile? actual)
{
CompareEpubLocalContentFiles(expected, actual);
if (expected != null)
{
Assert.NotNull(actual);
Assert.Equal(expected.Content, actual.Content);
}
}
public static void CompareEpubLocalByteContentFiles(EpubLocalByteContentFile? expected, EpubLocalByteContentFile? actual)
{
CompareEpubLocalContentFiles(expected, actual);
if (expected != null)
{
Assert.NotNull(actual);
Assert.Equal(expected.Content, actual.Content);
}
}
public static void CompareEpubRemoteTextContentFiles(EpubRemoteTextContentFile? expected, EpubRemoteTextContentFile? actual)
{
CompareEpubRemoteContentFiles(expected, actual);
if (expected != null)
{
Assert.NotNull(actual);
Assert.Equal(expected.Content, actual.Content);
}
}
public static void CompareEpubRemoteByteContentFiles(EpubRemoteByteContentFile? expected, EpubRemoteByteContentFile? actual)
{
CompareEpubRemoteContentFiles(expected, actual);
if (expected != null)
{
Assert.NotNull(actual);
Assert.Equal(expected.Content, actual.Content);
}
}
private static void CompareEpubContentFiles(EpubContentFile? expected, EpubContentFile? actual)
{
if (expected == null)
{
Assert.Null(actual);
}
else
{
Assert.NotNull(actual);
Assert.Equal(expected.GetType(), actual.GetType());
Assert.Equal(expected.Key, actual.Key);
Assert.Equal(expected.ContentLocation, actual.ContentLocation);
Assert.Equal(expected.ContentType, actual.ContentType);
Assert.Equal(expected.ContentMimeType, actual.ContentMimeType);
}
}
private static void CompareContentCollections<TLocalContentFile, TRemoteContentFile>(
EpubContentCollection<TLocalContentFile, TRemoteContentFile> expected,
EpubContentCollection<TLocalContentFile, TRemoteContentFile> actual,
Action<TLocalContentFile, TLocalContentFile> localContentFileComparer,
Action<TRemoteContentFile, TRemoteContentFile> remoteContentFileComparer)
where TLocalContentFile : EpubLocalContentFile
where TRemoteContentFile : EpubRemoteContentFile
{
CollectionComparer.CompareCollections(expected.Local, actual.Local, localContentFileComparer);
CollectionComparer.CompareCollections(expected.Remote, actual.Remote, remoteContentFileComparer);
}
private static void CompareLocalEpubContentFilesWithContent(EpubLocalContentFile? expected, EpubLocalContentFile? actual)
{
if (expected is EpubLocalTextContentFile)
{
CompareEpubLocalTextContentFiles(expected as EpubLocalTextContentFile, actual as EpubLocalTextContentFile);
}
else if (expected is EpubLocalByteContentFile)
{
CompareEpubLocalByteContentFiles(expected as EpubLocalByteContentFile, actual as EpubLocalByteContentFile);
}
}
private static void CompareRemoteEpubContentFilesWithContent(EpubRemoteContentFile? expected, EpubRemoteContentFile? actual)
{
if (expected is EpubRemoteTextContentFile)
{
CompareEpubRemoteTextContentFiles(expected as EpubRemoteTextContentFile, actual as EpubRemoteTextContentFile);
}
else if (expected is EpubRemoteByteContentFile)
{
CompareEpubRemoteByteContentFiles(expected as EpubRemoteByteContentFile, actual as EpubRemoteByteContentFile);
}
}
private static void CompareEpubLocalContentFiles(EpubLocalContentFile? expected, EpubLocalContentFile? actual)
{
CompareEpubContentFiles(expected, actual);
if (expected != null)
{
Assert.NotNull(actual);
Assert.Equal(expected.FilePath, actual.FilePath);
}
}
private static void CompareEpubRemoteContentFiles(EpubRemoteContentFile? expected, EpubRemoteContentFile? actual)
{
CompareEpubContentFiles(expected, actual);
if (expected != null)
{
Assert.NotNull(actual);
Assert.Equal(expected.Url, actual.Url);
}
}
}
}
|