Skip to content

Commit

Permalink
NavigationReader fix: get content files via absolute file paths (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
vers-one authored May 19, 2023
1 parent 0f18a20 commit 67fadc9
Show file tree
Hide file tree
Showing 75 changed files with 2,605 additions and 1,394 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7
dotnet-version: 7.0.203
- name: Setup MSBuild
uses: microsoft/[email protected]
- name: Restore dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7
dotnet-version: 7.0.203
- name: Restore dependencies
run: dotnet restore .\Source\VersOne.Epub\VersOne.Epub.csproj
- name: Install DocFX
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Install .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7
dotnet-version: 7.0.203
- name: Setup MSBuild
uses: microsoft/[email protected]
- name: Restore dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7
dotnet-version: 7.0.203
- name: Setup MSBuild
uses: microsoft/[email protected]
- name: Restore dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7
dotnet-version: 7.0.203
- name: Build test project and its dependencies
run: dotnet build Source\VersOne.Epub.Test -c $env:Configuration
- name: Run unit tests
Expand Down
4 changes: 2 additions & 2 deletions Source/VersOne.Epub.Test/Comparers/CollectionComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static void CompareCollections<T>(IList<T> expected, IList<T> actual, Act
}
}

public static void CompareDictionaries<TKey, TValue>(IDictionary<TKey, TValue> expected, IDictionary<TKey, TValue> actual, Action<TValue, TValue> elementValueComprarer)
public static void CompareDictionaries<TKey, TValue>(IDictionary<TKey, TValue> expected, IDictionary<TKey, TValue> actual, Action<TValue, TValue> elementValueComparer)
{
Assert.Equal(expected.Count, actual.Count);
foreach (KeyValuePair<TKey, TValue> expectedKeyValuePair in expected)
Expand All @@ -20,7 +20,7 @@ public static void CompareDictionaries<TKey, TValue>(IDictionary<TKey, TValue> e
TValue expectedValue = expectedKeyValuePair.Value;
if (actual.TryGetValue(expectedKey, out TValue? actualValue))
{
elementValueComprarer(expectedValue, actualValue);
elementValueComparer(expectedValue, actualValue);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Source/VersOne.Epub.Test/Comparers/EpubContentComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ private static void CompareContentCollections<TLocalContentFile, TRemoteContentF
where TLocalContentFile : EpubLocalContentFile
where TRemoteContentFile : EpubRemoteContentFile
{
CollectionComparer.CompareDictionaries(expected.Local, actual.Local, localContentFileComprarer);
CollectionComparer.CompareDictionaries(expected.Remote, actual.Remote, remoteContentFileComparer);
CollectionComparer.CompareCollections(expected.Local, actual.Local, localContentFileComprarer);
CollectionComparer.CompareCollections(expected.Remote, actual.Remote, remoteContentFileComparer);
}

private static void CompareLocalEpubContentFilesWithContent(EpubLocalContentFile? expected, EpubLocalContentFile? actual)
Expand Down
4 changes: 2 additions & 2 deletions Source/VersOne.Epub.Test/Comparers/EpubContentRefComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private static void CompareContentCollectionRefs<TLocalContentFileRef, TRemoteCo
where TLocalContentFileRef : EpubLocalContentFileRef
where TRemoteContentFileRef : EpubRemoteContentFileRef
{
CollectionComparer.CompareDictionaries(expected.Local, actual.Local, CompareEpubLocalContentFileRefs);
CollectionComparer.CompareDictionaries(expected.Remote, actual.Remote, CompareEpubRemoteContentFileRefs);
CollectionComparer.CompareCollections(expected.Local, actual.Local, CompareEpubLocalContentFileRefs);
CollectionComparer.CompareCollections(expected.Remote, actual.Remote, CompareEpubRemoteContentFileRefs);
}

private static void CompareEpubContentFileRefs(EpubContentFileRef? expected, EpubContentFileRef? actual)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void CompareNavigationItemLinks(EpubNavigationItemLink? expected,
else
{
Assert.NotNull(actual);
Assert.Equal(expected.ContentFileName, actual.ContentFileName);
Assert.Equal(expected.ContentFileUrl, actual.ContentFileUrl);
Assert.Equal(expected.ContentFilePath, actual.ContentFilePath);
Assert.Equal(expected.Anchor, actual.Anchor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,24 +471,24 @@ private static IEnumerable<CustomType> CreateTypes()
(
optionalProperties: new()
{
{ nameof(EpubContentCollection<EpubLocalContentFile, EpubRemoteContentFile>.Local), PropertyDefaultValue.EMPTY_DICTIONARY },
{ nameof(EpubContentCollection<EpubLocalContentFile, EpubRemoteContentFile>.Remote), PropertyDefaultValue.EMPTY_DICTIONARY }
{ nameof(EpubContentCollection<EpubLocalContentFile, EpubRemoteContentFile>.Local), PropertyDefaultValue.EMPTY_ARRAY },
{ nameof(EpubContentCollection<EpubLocalContentFile, EpubRemoteContentFile>.Remote), PropertyDefaultValue.EMPTY_ARRAY }
}
);
yield return CreateType<EpubContentCollection<EpubLocalTextContentFile, EpubRemoteTextContentFile>>
(
optionalProperties: new()
{
{ nameof(EpubContentCollection<EpubLocalTextContentFile, EpubRemoteTextContentFile>.Local), PropertyDefaultValue.EMPTY_DICTIONARY },
{ nameof(EpubContentCollection<EpubLocalTextContentFile, EpubRemoteTextContentFile>.Remote), PropertyDefaultValue.EMPTY_DICTIONARY }
{ nameof(EpubContentCollection<EpubLocalTextContentFile, EpubRemoteTextContentFile>.Local), PropertyDefaultValue.EMPTY_ARRAY },
{ nameof(EpubContentCollection<EpubLocalTextContentFile, EpubRemoteTextContentFile>.Remote), PropertyDefaultValue.EMPTY_ARRAY }
}
);
yield return CreateType<EpubContentCollection<EpubLocalByteContentFile, EpubRemoteByteContentFile>>
(
optionalProperties: new()
{
{ nameof(EpubContentCollection<EpubLocalByteContentFile, EpubRemoteByteContentFile>.Local), PropertyDefaultValue.EMPTY_DICTIONARY },
{ nameof(EpubContentCollection<EpubLocalByteContentFile, EpubRemoteByteContentFile>.Remote), PropertyDefaultValue.EMPTY_DICTIONARY }
{ nameof(EpubContentCollection<EpubLocalByteContentFile, EpubRemoteByteContentFile>.Local), PropertyDefaultValue.EMPTY_ARRAY },
{ nameof(EpubContentCollection<EpubLocalByteContentFile, EpubRemoteByteContentFile>.Remote), PropertyDefaultValue.EMPTY_ARRAY }
}
);
yield return CreateType<EpubLocalByteContentFile>
Expand All @@ -515,7 +515,8 @@ private static IEnumerable<CustomType> CreateTypes()
ignoredProperties: new()
{
nameof(EpubRemoteByteContentFile.ContentFileType),
nameof(EpubRemoteByteContentFile.ContentLocation)
nameof(EpubRemoteByteContentFile.ContentLocation),
nameof(EpubRemoteByteContentFile.Url)
}
);
yield return CreateType<EpubRemoteTextContentFile>
Expand All @@ -524,7 +525,8 @@ private static IEnumerable<CustomType> CreateTypes()
ignoredProperties: new()
{
nameof(EpubRemoteTextContentFile.ContentFileType),
nameof(EpubRemoteTextContentFile.ContentLocation)
nameof(EpubRemoteTextContentFile.ContentLocation),
nameof(EpubRemoteTextContentFile.Url)
}
);
yield return CreateType<EpubReaderOptions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
using System.Collections;
using System.Collections.ObjectModel;
using System.Text.Json;

namespace VersOne.Epub.Test.Integration.JsonUtils.Deserializers
{
internal class ListDeserializer : TypeDeserializer
{
private readonly Type listType;
private readonly bool isReadOnlyCollection;
private readonly Type listItemType;
private readonly Lazy<TypeDeserializer> listItemTypeDeserializer;

public ListDeserializer(Type listType, TypeDeserializerCollection typeDeserializerCollection)
{
if (!listType.IsGenericType)
{
throw new ArgumentException($"{listType.Name} is not a generic List<T> type.");
}
this.listType = listType;
Type listItemType = listType.IsGenericType ? listType.GetGenericArguments().First() : throw new ArgumentException($"{listType.Name} is not a generic List<T> type.");
isReadOnlyCollection = listType.GetGenericTypeDefinition() == typeof(ReadOnlyCollection<>);
listItemType = listType.GetGenericArguments().First();
listItemTypeDeserializer = new Lazy<TypeDeserializer>(() => typeDeserializerCollection.GetDeserializer(listItemType));
}

public override object? Deserialize(JsonElement jsonElement, JsonSerializationContext jsonSerializationContext)
{
Assert.Equal(JsonValueKind.Array, jsonElement.ValueKind);
IList? result = Activator.CreateInstance(listType, new object[] { jsonElement.GetArrayLength() }) as IList;
Assert.NotNull(result);
IList? list = Activator.CreateInstance(isReadOnlyCollection ? typeof(List<>).MakeGenericType(listItemType) : listType,
new object[] { jsonElement.GetArrayLength() }) as IList;
Assert.NotNull(list);
foreach (JsonElement serializedListItem in jsonElement.EnumerateArray())
{
result.Add(listItemTypeDeserializer.Value.Deserialize(serializedListItem, jsonSerializationContext));
list.Add(listItemTypeDeserializer.Value.Deserialize(serializedListItem, jsonSerializationContext));
}
object? result = isReadOnlyCollection ? Activator.CreateInstance(listType, new object[] { list }) : list;
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@
},
"Content": {
"AllFiles": {
"Local": {
"toc.ncx": {
"Local": [
{
"$ref": 1
}
}
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@
},
"Content": {
"AllFiles": {
"Local": {
"toc.ncx": {
"Local": [
{
"$ref": 1
}
}
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
},
"Content": {
"AllFiles": {
"Local": {
"toc.ncx": {
"Local": [
{
"$ref": 1
}
}
]
}
}
}
Expand Down
Loading

0 comments on commit 67fadc9

Please sign in to comment.