Skip to content

Commit

Permalink
Nullable reference type annotations (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
vers-one authored Nov 18, 2022
1 parent 4431b0a commit d740400
Show file tree
Hide file tree
Showing 202 changed files with 10,777 additions and 7,236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.45.0.54064">
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.48.0.56517">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Source/VersOne.Epub.Test/Comparers/CollectionComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void CompareDictionaries<TKey, TValue>(IDictionary<TKey, TValue> e
{
TKey expectedKey = expectedKeyValuePair.Key;
TValue expectedValue = expectedKeyValuePair.Value;
if (actual.TryGetValue(expectedKey, out TValue actualValue))
if (actual.TryGetValue(expectedKey, out TValue? actualValue))
{
elementValueComprarer(expectedValue, actualValue);
}
Expand Down
125 changes: 75 additions & 50 deletions Source/VersOne.Epub.Test/Comparers/Epub2NcxComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace VersOne.Epub.Test.Comparers
{
internal static class Epub2NcxComparer
{
public static void CompareEpub2Ncxes(Epub2Ncx expected, Epub2Ncx actual)
public static void CompareEpub2Ncxes(Epub2Ncx? expected, Epub2Ncx? actual)
{
if (expected == null)
{
Expand All @@ -18,47 +18,23 @@ public static void CompareEpub2Ncxes(Epub2Ncx expected, Epub2Ncx actual)
Assert.Equal(expected.DocAuthors, actual.DocAuthors);
CompareEpub2NcxNavigationMaps(expected.NavMap, actual.NavMap);
CompareEpub2NcxPageLists(expected.PageList, actual.PageList);
CollectionComparer.CompareCollections(expected.NavLists, actual.NavLists, CompareEpub2NcxNavigationLists);
CompareEpub2NcxNavigationListLists(expected.NavLists, actual.NavLists);
}
}

private static void CompareEpub2NcxHeads(Epub2NcxHead expected, Epub2NcxHead actual)
public static void CompareEpub2NcxHeads(Epub2NcxHead expected, Epub2NcxHead actual)
{
Assert.NotNull(actual);
CollectionComparer.CompareCollections(expected.Items, actual.Items, ComprareEpub2NcxHeadMetas);
}

private static void ComprareEpub2NcxHeadMetas(Epub2NcxHeadMeta expected, Epub2NcxHeadMeta actual)
{
Assert.Equal(expected.Name, actual.Name);
Assert.Equal(expected.Content, actual.Content);
Assert.Equal(expected.Scheme, actual.Scheme);
}

private static void CompareEpub2NcxNavigationMaps(Epub2NcxNavigationMap expected, Epub2NcxNavigationMap actual)
{
Assert.NotNull(actual);
CollectionComparer.CompareCollections(expected.Items, actual.Items, CompareEpub2NcxNavigationPoints);
}

private static void CompareEpub2NcxNavigationPoints(Epub2NcxNavigationPoint expected, Epub2NcxNavigationPoint actual)
public static void CompareEpub2NcxNavigationMaps(Epub2NcxNavigationMap expected, Epub2NcxNavigationMap actual)
{
Assert.NotNull(actual);
Assert.Equal(expected.Id, actual.Id);
Assert.Equal(expected.Class, actual.Class);
Assert.Equal(expected.PlayOrder, actual.PlayOrder);
CollectionComparer.CompareCollections(expected.NavigationLabels, actual.NavigationLabels, CompareEpub2NcxNavigationLabels);
CompareEpub2NcxContents(expected.Content, actual.Content);
CollectionComparer.CompareCollections(expected.ChildNavigationPoints, actual.ChildNavigationPoints, CompareEpub2NcxNavigationPoints);
}

private static void CompareEpub2NcxNavigationLabels(Epub2NcxNavigationLabel expected, Epub2NcxNavigationLabel actual)
{
Assert.NotNull(actual);
Assert.Equal(expected.Text, actual.Text);
CompareEpub2NcxNavigationPointLists(expected.Items, actual.Items);
}

private static void CompareEpub2NcxContents(Epub2NcxContent expected, Epub2NcxContent actual)
public static void CompareEpub2NcxPageLists(Epub2NcxPageList? expected, Epub2NcxPageList? actual)
{
if (expected == null)
{
Expand All @@ -67,51 +43,100 @@ private static void CompareEpub2NcxContents(Epub2NcxContent expected, Epub2NcxCo
else
{
Assert.NotNull(actual);
Assert.Equal(expected.Id, actual.Id);
Assert.Equal(expected.Source, actual.Source);
CompareEpub2NcxPageTargetLists(expected.Items, actual.Items);
}
}

private static void CompareEpub2NcxPageLists(Epub2NcxPageList expected, Epub2NcxPageList actual)
public static void CompareEpub2NcxNavigationTargetLists(List<Epub2NcxNavigationTarget> expected, List<Epub2NcxNavigationTarget> actual)
{
if (expected == null)
{
Assert.Null(actual);
}
else
{
Assert.NotNull(actual);
CollectionComparer.CompareCollections(expected.Items, actual.Items, CompareEpub2NcxPageTargets);
}
CollectionComparer.CompareCollections(expected, actual, CompareEpub2NcxNavigationTargets);
}

private static void CompareEpub2NcxPageTargets(Epub2NcxPageTarget expected, Epub2NcxPageTarget actual)
public static void CompareEpub2NcxNavigationTargets(Epub2NcxNavigationTarget expected, Epub2NcxNavigationTarget actual)
{
Assert.Equal(expected.Id, actual.Id);
Assert.Equal(expected.Value, actual.Value);
Assert.Equal(expected.Class, actual.Class);
Assert.Equal(expected.PlayOrder, actual.PlayOrder);
CompareEpub2NcxNavigationLabelLists(expected.NavigationLabels, actual.NavigationLabels);
CompareEpub2NcxContents(expected.Content, actual.Content);
}

public static void CompareEpub2NcxPageTargetLists(List<Epub2NcxPageTarget> expected, List<Epub2NcxPageTarget> actual)
{
CollectionComparer.CompareCollections(expected, actual, CompareEpub2NcxPageTargets);
}

public static void CompareEpub2NcxPageTargets(Epub2NcxPageTarget expected, Epub2NcxPageTarget actual)
{
Assert.Equal(expected.Id, actual.Id);
Assert.Equal(expected.Value, actual.Value);
Assert.Equal(expected.Type, actual.Type);
Assert.Equal(expected.Class, actual.Class);
Assert.Equal(expected.PlayOrder, actual.PlayOrder);
CollectionComparer.CompareCollections(expected.NavigationLabels, actual.NavigationLabels, CompareEpub2NcxNavigationLabels);
CompareEpub2NcxNavigationLabelLists(expected.NavigationLabels, actual.NavigationLabels);
CompareEpub2NcxContents(expected.Content, actual.Content);
}

private static void CompareEpub2NcxNavigationLists(Epub2NcxNavigationList expected, Epub2NcxNavigationList actual)
public static void ComprareEpub2NcxHeadMetas(Epub2NcxHeadMeta expected, Epub2NcxHeadMeta actual)
{
Assert.Equal(expected.Name, actual.Name);
Assert.Equal(expected.Content, actual.Content);
Assert.Equal(expected.Scheme, actual.Scheme);
}

public static void CompareEpub2NcxNavigationListLists(List<Epub2NcxNavigationList> expected, List<Epub2NcxNavigationList> actual)
{
CollectionComparer.CompareCollections(expected, actual, CompareEpub2NcxNavigationLists);
}

public static void CompareEpub2NcxNavigationLists(Epub2NcxNavigationList expected, Epub2NcxNavigationList actual)
{
Assert.Equal(expected.Id, actual.Id);
Assert.Equal(expected.Class, actual.Class);
CollectionComparer.CompareCollections(expected.NavigationLabels, actual.NavigationLabels, CompareEpub2NcxNavigationLabels);
CollectionComparer.CompareCollections(expected.NavigationTargets, actual.NavigationTargets, CompareEpub2NcxNavigationTargets);
CompareEpub2NcxNavigationLabelLists(expected.NavigationLabels, actual.NavigationLabels);
CompareEpub2NcxNavigationTargetLists(expected.NavigationTargets, actual.NavigationTargets);
}

public static void CompareEpub2NcxNavigationLabelLists(List<Epub2NcxNavigationLabel> expected, List<Epub2NcxNavigationLabel> actual)
{
CollectionComparer.CompareCollections(expected, actual, CompareEpub2NcxNavigationLabels);
}

public static void CompareEpub2NcxNavigationLabels(Epub2NcxNavigationLabel expected, Epub2NcxNavigationLabel actual)
{
Assert.NotNull(actual);
Assert.Equal(expected.Text, actual.Text);
}

private static void CompareEpub2NcxNavigationTargets(Epub2NcxNavigationTarget expected, Epub2NcxNavigationTarget actual)
public static void CompareEpub2NcxNavigationPointLists(List<Epub2NcxNavigationPoint> expected, List<Epub2NcxNavigationPoint> actual)
{
CollectionComparer.CompareCollections(expected, actual, CompareEpub2NcxNavigationPoints);
}

public static void CompareEpub2NcxNavigationPoints(Epub2NcxNavigationPoint expected, Epub2NcxNavigationPoint actual)
{
Assert.NotNull(actual);
Assert.Equal(expected.Id, actual.Id);
Assert.Equal(expected.Value, actual.Value);
Assert.Equal(expected.Class, actual.Class);
Assert.Equal(expected.PlayOrder, actual.PlayOrder);
CollectionComparer.CompareCollections(expected.NavigationLabels, actual.NavigationLabels, CompareEpub2NcxNavigationLabels);
CompareEpub2NcxNavigationLabelLists(expected.NavigationLabels, actual.NavigationLabels);
CompareEpub2NcxContents(expected.Content, actual.Content);
CompareEpub2NcxNavigationPointLists(expected.ChildNavigationPoints, actual.ChildNavigationPoints);
}

public static void CompareEpub2NcxContents(Epub2NcxContent? expected, Epub2NcxContent? actual)
{
if (expected == null)
{
Assert.Null(actual);
}
else
{
Assert.NotNull(actual);
Assert.Equal(expected.Id, actual.Id);
Assert.Equal(expected.Source, actual.Source);
}
}
}
}
27 changes: 19 additions & 8 deletions Source/VersOne.Epub.Test/Comparers/Epub3NavDocumentComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace VersOne.Epub.Test.Comparers
{
internal static class Epub3NavDocumentComparer
{
public static void CompareEpub3NavDocuments(Epub3NavDocument expected, Epub3NavDocument actual)
public static void CompareEpub3NavDocuments(Epub3NavDocument? expected, Epub3NavDocument? actual)
{
if (expected == null)
{
Expand All @@ -14,11 +14,16 @@ public static void CompareEpub3NavDocuments(Epub3NavDocument expected, Epub3NavD
{
Assert.NotNull(actual);
Assert.NotNull(actual.Navs);
CollectionComparer.CompareCollections(expected.Navs, actual.Navs, CompareEpub3Navs);
CompareEpub3NavLists(expected.Navs, actual.Navs);
}
}

private static void CompareEpub3Navs(Epub3Nav expected, Epub3Nav actual)
public static void CompareEpub3NavLists(List<Epub3Nav> expected, List<Epub3Nav> actual)
{
CollectionComparer.CompareCollections(expected, actual, CompareEpub3Navs);
}

public static void CompareEpub3Navs(Epub3Nav expected, Epub3Nav actual)
{
Assert.NotNull(actual);
Assert.Equal(expected.Type, actual.Type);
Expand All @@ -27,7 +32,7 @@ private static void CompareEpub3Navs(Epub3Nav expected, Epub3Nav actual)
CompareEpub3NavOls(expected.Ol, actual.Ol);
}

private static void CompareEpub3NavOls(Epub3NavOl expected, Epub3NavOl actual)
public static void CompareEpub3NavOls(Epub3NavOl? expected, Epub3NavOl? actual)
{
if (expected == null)
{
Expand All @@ -37,19 +42,24 @@ private static void CompareEpub3NavOls(Epub3NavOl expected, Epub3NavOl actual)
{
Assert.NotNull(actual);
Assert.Equal(expected.IsHidden, actual.IsHidden);
CollectionComparer.CompareCollections(expected.Lis, actual.Lis, CompareEpub3NavLis);
CompareEpub3NavLiLists(expected.Lis, actual.Lis);
}
}

private static void CompareEpub3NavLis(Epub3NavLi expected, Epub3NavLi actual)
public static void CompareEpub3NavLiLists(List<Epub3NavLi> expected, List<Epub3NavLi> actual)
{
CollectionComparer.CompareCollections(expected, actual, CompareEpub3NavLis);
}

public static void CompareEpub3NavLis(Epub3NavLi expected, Epub3NavLi actual)
{
Assert.NotNull(actual);
CompareEpub3NavAnchors(expected.Anchor, actual.Anchor);
CompareEpub3NavSpans(expected.Span, actual.Span);
CompareEpub3NavOls(expected.ChildOl, actual.ChildOl);
}

private static void CompareEpub3NavAnchors(Epub3NavAnchor expected, Epub3NavAnchor actual)
public static void CompareEpub3NavAnchors(Epub3NavAnchor? expected, Epub3NavAnchor? actual)
{
if (expected == null)
{
Expand All @@ -66,14 +76,15 @@ private static void CompareEpub3NavAnchors(Epub3NavAnchor expected, Epub3NavAnch
}
}

private static void CompareEpub3NavSpans(Epub3NavSpan expected, Epub3NavSpan actual)
private static void CompareEpub3NavSpans(Epub3NavSpan? expected, Epub3NavSpan? actual)
{
if (expected == null)
{
Assert.Null(actual);
}
else
{
Assert.NotNull(actual);
Assert.Equal(expected.Text, actual.Text);
Assert.Equal(expected.Title, actual.Title);
Assert.Equal(expected.Alt, actual.Alt);
Expand Down
4 changes: 2 additions & 2 deletions Source/VersOne.Epub.Test/Comparers/EpubBookComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public static void CompareEpubBooks(EpubBook expected, EpubBook actual)
Assert.Equal(expected.AuthorList, actual.AuthorList);
Assert.Equal(expected.Description, actual.Description);
Assert.Equal(expected.CoverImage, actual.CoverImage);
CollectionComparer.CompareCollections(expected.ReadingOrder, actual.ReadingOrder, EpubContentComparer.CompareEpubLocalTextContentFiles);
EpubContentComparer.CompareEpubLocalTextContentFileLists(expected.ReadingOrder, actual.ReadingOrder);
EpubNavigationItemComparer.CompareNavigationItemLists(expected.Navigation, actual.Navigation);
EpubContentComparer.CompareEpubContents(expected.Content, actual.Content);
EpubSchemaComparer.CompareEpubSchemas(expected.Schema, actual.Schema);
EpubContentComparer.CompareEpubContents(expected.Content, actual.Content);
}
}
}
29 changes: 20 additions & 9 deletions Source/VersOne.Epub.Test/Comparers/EpubContentComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,52 @@ public static void CompareEpubContents(EpubContent expected, EpubContent actual)
CompareContentCollections(expected.AllFiles, actual.AllFiles, CompareLocalEpubContentFilesWithContent, CompareRemoteEpubContentFilesWithContent);
}

public static void CompareEpubLocalTextContentFiles(EpubLocalTextContentFile expected, EpubLocalTextContentFile actual)
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)
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)
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)
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)
private static void CompareEpubContentFiles(EpubContentFile? expected, EpubContentFile? actual)
{
if (expected == null)
{
Expand Down Expand Up @@ -78,7 +87,7 @@ private static void CompareContentCollections<TLocalContentFile, TRemoteContentF
CollectionComparer.CompareDictionaries(expected.Remote, actual.Remote, remoteContentFileComparer);
}

private static void CompareLocalEpubContentFilesWithContent(EpubLocalContentFile expected, EpubLocalContentFile actual)
private static void CompareLocalEpubContentFilesWithContent(EpubLocalContentFile? expected, EpubLocalContentFile? actual)
{
if (expected is EpubLocalTextContentFile)
{
Expand All @@ -90,7 +99,7 @@ private static void CompareLocalEpubContentFilesWithContent(EpubLocalContentFile
}
}

private static void CompareRemoteEpubContentFilesWithContent(EpubRemoteContentFile expected, EpubRemoteContentFile actual)
private static void CompareRemoteEpubContentFilesWithContent(EpubRemoteContentFile? expected, EpubRemoteContentFile? actual)
{
if (expected is EpubRemoteTextContentFile)
{
Expand All @@ -102,20 +111,22 @@ private static void CompareRemoteEpubContentFilesWithContent(EpubRemoteContentFi
}
}

private static void CompareEpubLocalContentFiles(EpubLocalContentFile expected, EpubLocalContentFile actual)
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)
private static void CompareEpubRemoteContentFiles(EpubRemoteContentFile? expected, EpubRemoteContentFile? actual)
{
CompareEpubContentFiles(expected, actual);
if (expected != null)
{
Assert.NotNull(actual);
Assert.Equal(expected.Url, actual.Url);
}
}
Expand Down
Loading

0 comments on commit d740400

Please sign in to comment.