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
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install .NET (v8.0)
- name: Install .NET (v10.0)
uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: 8.0.x
dotnet-version: 10.0.x
- name: Test
run: |
dotnet test --configuration Debug
Expand Down Expand Up @@ -66,10 +66,10 @@ jobs:
HUSKY: 0
steps:
- uses: actions/checkout@v3
- name: Install .NET (v8.0)
- name: Install .NET (v10.0)
uses: actions/setup-dotnet@v3.2.0
with:
dotnet-version: 8.x
dotnet-version: 10.x
- name: Build
run: |
dotnet publish src/Noted -c Release --self-contained false -r win-x64 -o ./src/Noted/bin/Portable.win-x64
Expand Down
4 changes: 3 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@

CS1573: Parameter 'parameter' has no matching param tag in the XML comment for 'parameter' (but other parameters do)
CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member'
NU1510: PackageReference will not be pruned. We need few packages because of dependencies, e.g. JTForks.MiscUtil.
NU1902: vulnerable package references should be updated. We are overriding some transitive dependencies.
-->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn),1573,1591,1712</NoWarn>
<NoWarn>$(NoWarn),1573,1591,1712,NU1510,NU1902,NU1903</NoWarn>

<!-- Show full paths for the warnings and errors -->
<GenerateFullPaths>true</GenerateFullPaths>
Expand Down
4 changes: 1 addition & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<Project>
<ItemGroup>
<PackageReference Include="Stylecop.Analyzers" Condition="$(StylecopEnabled) == '' or $(StylecopEnabled) != 'false'">
<Version>1.2.0-beta.556</Version>
</PackageReference>
<PackageReference Include="Stylecop.Analyzers" Condition="$(StylecopEnabled) == '' or $(StylecopEnabled) != 'false'" />
</ItemGroup>
<Target Name="husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High"/>
Expand Down
38 changes: 38 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
<!-- Core Libraries -->
<PackageVersion Include="AngleSharp" Version="1.4.0" />
<PackageVersion Include="AngleSharp.XPath" Version="2.0.5" />
<PackageVersion Include="Ephemerality.Unpack" Version="0.0.7" />
<PackageVersion Include="JTForks.MiscUtil" Version="1.285.0" />
<PackageVersion Include="Markdig" Version="0.44.0" />
<PackageVersion Include="nlua" Version="1.7.8" />
<PackageVersion Include="PdfPig" Version="0.1.13" />
<PackageVersion Include="Spectre.Console" Version="0.54.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.Linq.Async" Version="7.0.0" />
<PackageVersion Include="VersOne.Epub" Version="3.3.3" />

<!-- Workaround for publish because of JTForks.MiscUtil -->
<PackageVersion Include="Microsoft.Win32.Primitives" Version="4.3.0" />
<PackageVersion Include="System.Net.Primitives" Version="4.3.1" />
<PackageVersion Include="System.IO.FileSystem" Version="4.3.0" />

<!-- Test Dependencies -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.10.5" />
<PackageVersion Include="MSTest.TestFramework" Version="3.10.5" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
<PackageVersion Include="Moq" Version="4.20.72" />

<!-- Code Analysis -->
<PackageVersion Include="Stylecop.Analyzers" Version="1.2.0-beta.556" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/Noted/Core/Models/DocumentReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ private SortedSet<string> AuthorVector
return this.authorVector;
}

this.authorVector = new SortedSet<string>(this.Author
this.authorVector = [.. this.Author
.Split(' ')
.Select(x => x.Trim(' ', ',', '.').ToLower()));
.Select(x => x.Trim(' ', ',', '.').ToLower())];
return this.authorVector;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public IEnumerable<Annotation> GetAnnotations(string sourcePath)

var annotationFile = Path.Combine(sourcePath, ClippingsFile);
using var stream = this.fileSystem.OpenPathForRead(annotationFile);
return ClippingParser.Parse(stream).Select(c => c.ToAnnotation()).ToList();
return [.. ClippingParser.Parse(stream).Select(c => c.ToAnnotation())];
}
}
}
7 changes: 6 additions & 1 deletion src/Noted/Extensions/Readers/Mobi/Mobi7Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ public static async Task<Stream> GetNavigationStream(Stream contentStream)
// Prepare the table of contents stream for return
contentStream.Seek(tocFilePos, SeekOrigin.Begin);
var bytes = new byte[tocContentEnd];
await contentStream.ReadAsync(bytes);
int bytesRead = await contentStream.ReadAsync(bytes);
if (bytesRead != tocContentEnd)
{
throw new IOException("Expected to read " + tocContentEnd + " bytes but only read " + bytesRead + " bytes from TOC stream");
}

return new MemoryStream(bytes);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Noted/Infra/ConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public Configuration Build()
: new NullLogger();

this.commandLineConfig.AnnotationProviders =
this.annotationReaders(this.commandLineConfig).ToList();
[.. this.annotationReaders(this.commandLineConfig)];
this.commandLineConfig.Readers =
this.documentReaders(this.commandLineConfig).ToList();
[.. this.documentReaders(this.commandLineConfig)];
this.commandLineConfig.Writers =
this.documentWriters(this.commandLineConfig).ToList();
[.. this.documentWriters(this.commandLineConfig)];

return this.commandLineConfig;
}
Expand Down
32 changes: 16 additions & 16 deletions src/Noted/Noted.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AngleSharp" Version="1.4.0" />
<PackageReference Include="AngleSharp.XPath" Version="2.0.5" />
<PackageReference Include="Ephemerality.Unpack" Version="0.0.5" />
<PackageReference Include="JTForks.MiscUtil" Version="1.285.0" />
<PackageReference Include="Markdig" Version="0.44.0" />
<PackageReference Include="nlua" Version="1.7.8" />
<PackageReference Include="PdfPig" Version="0.1.11" />
<PackageReference Include="Spectre.Console" Version="0.54.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.Linq.Async" Version="7.0.0" />
<PackageReference Include="VersOne.Epub" Version="3.3.3" />
<PackageReference Include="AngleSharp" />
<PackageReference Include="AngleSharp.XPath" />
<PackageReference Include="Ephemerality.Unpack" />
<PackageReference Include="JTForks.MiscUtil" />
<PackageReference Include="Markdig" />
<PackageReference Include="nlua" />
<PackageReference Include="PdfPig" />
<PackageReference Include="Spectre.Console" />
<PackageReference Include="System.CommandLine" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" />
<PackageReference Include="System.Linq.Async" />
<PackageReference Include="VersOne.Epub" />

<!-- Workaround for publish because of JTForks.MiscUtil -->
<PackageReference Include="Microsoft.Win32.Primitives" Version="4.3.0" />
<PackageReference Include="System.Net.Primitives" Version="4.3.1" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
<PackageReference Include="Microsoft.Win32.Primitives" />
<PackageReference Include="System.Net.Primitives" />
<PackageReference Include="System.IO.FileSystem" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void KOReaderAnnotationProviderShouldReturnZeroAnnotations()
var annotations =
this.annotationProvider.GetAnnotations(AssetFactory.GetKindleLibrary()).ToList();

Assert.AreEqual(0, annotations.Count);
Assert.IsEmpty(annotations);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void GetClippingsShouldRetrieveDocumentAnnotations()
var kindle = new ClippingAnnotationProvider(fileSystem.Object, new NullLogger());
var clippings = kindle.GetAnnotations("dummyPath").ToList();

Assert.AreEqual(3, clippings.Count);
Assert.HasCount(3, clippings);
}

[TestMethod]
Expand All @@ -70,7 +70,7 @@ public void GetClippingsShouldReturnZeroAnnotationsIfPathIsNotAccessible()
var kindle = new ClippingAnnotationProvider(fileSystem.Object, new NullLogger());
var clippings = kindle.GetAnnotations("dummyPath").ToList();

Assert.AreEqual(0, clippings.Count);
Assert.IsEmpty(clippings);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public void ParseShouldExtractAllClippings()

var clippings = ClippingParser.Parse(this.stream).ToList();

Assert.AreEqual(2, clippings.Count);
Assert.HasCount(2, clippings);
Assert.AreEqual("The Design of Everyday Things: Revised and Expanded Edition", clippings[0].Book);
Assert.AreEqual("Norman, Don", clippings[0].Author);
Assert.AreEqual(ClippingType.Highlight, clippings[0].Type);
Assert.AreEqual(145, clippings[0].PageNumber);
Assert.AreEqual(3015, clippings[0].Location.Start);
Assert.AreEqual(3016, clippings[0].Location.End);
Assert.AreEqual(new DateTime(2019, 08, 15, 10, 14, 40), clippings[0].CreationDate);
Assert.IsTrue(clippings[0].Content.StartsWith("Forcing functions can be"));
Assert.StartsWith("Forcing functions can be", clippings[0].Content);

Assert.AreEqual(ClippingType.Note, clippings[1].Type);
}
Expand All @@ -83,7 +83,7 @@ public void ParseShouldExtractClippingsWithLocationWithoutPage()

var clippings = ClippingParser.Parse(this.stream).ToList();

Assert.AreEqual(2, clippings.Count);
Assert.HasCount(2, clippings);
Assert.AreEqual(-1, clippings[0].PageNumber);
Assert.AreEqual(3026, clippings[0].Location.Start);
Assert.AreEqual(3026, clippings[0].Location.End);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public async Task HtmlContextParserShouldAddContextToAnnotations()
SampleSections,
[(new LineLocation(1, 2), this.annotations[0])]);

Assert.AreEqual(1, a.Count);
Assert.IsTrue(a[0].Context.Content.StartsWith("Never"));
Assert.HasCount(1, a);
Assert.StartsWith("Never", a[0].Context.Content);
Assert.AreEqual("Ch1", a[0].Context.DocumentSection.Title);
}

Expand All @@ -70,8 +70,8 @@ public async Task HtmlContextParserShouldAddContextWhenAnnotationSpansOverElemen
SampleSections,
[(new LineLocation(1, 2), this.annotations[1])]);

Assert.AreEqual(1, a.Count);
Assert.IsTrue(a[0].Context.Content.StartsWith("Thus, "));
Assert.HasCount(1, a);
Assert.StartsWith("Thus, ", a[0].Context.Content);
Assert.AreEqual("Ch2", a[0].Context.DocumentSection.Title);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ public HtmlSectionParserTests()
this.parser = new HtmlSectionParser();
}

public TestContext TestContext { get; set; }

[TestMethod]
public async Task ParseShouldReturnTableOfContentWithDepth()
{
await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(TocFragment));
var toc = await HtmlSectionParser.Parse(stream).ToListAsync();
var toc = await HtmlSectionParser.Parse(stream).ToListAsync(this.TestContext.CancellationTokenSource.Token);

Assert.AreEqual(11, toc.Count);
Assert.HasCount(11, toc);
Assert.AreEqual("Preface", toc[0].Title);
Assert.AreEqual(1, toc[0].Level);
Assert.AreEqual(3859, toc[0].Location);
Expand All @@ -89,7 +91,7 @@ public async Task ParseShouldReturnTableOfContentWithDepth()
public async Task ParseShouldCreateDocumentSectionRelationships()
{
await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(TocFragment));
var toc = await HtmlSectionParser.Parse(stream).ToListAsync();
var toc = await HtmlSectionParser.Parse(stream).ToListAsync(this.TestContext.CancellationTokenSource.Token);

Assert.IsNull(toc[3].Parent); // 1 -> null
Assert.AreEqual("Section 1.1", toc[4].Title);
Expand Down
4 changes: 2 additions & 2 deletions test/Noted.Tests/Extensions/Readers/EpubReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task EpubReaderShouldParseDocumentWithAnnotations()
var document = await new EpubReader(this.logger).Read(stream, new Noted.Core.Extensions.ReaderOptions(), [annotation]);

var annotations = document.Annotations.ToList();
Assert.AreEqual(1, annotations.Count);
Assert.HasCount(1, annotations);
Assert.AreEqual("On Giving", annotations[0].Context.DocumentSection.Title);
Assert.AreNotEqual(0, annotations[0].Context.DocumentSection.Location);
Assert.AreEqual(0, annotations[0].Context.Location);
Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task EpubReaderShouldParseEpub3DocumentWithAnnotations()
var document = await new EpubReader(this.logger).Read(stream, new Noted.Core.Extensions.ReaderOptions(), [annotation]);

var annotations = document.Annotations.ToList();
Assert.AreEqual(1, annotations.Count);
Assert.HasCount(1, annotations);
Assert.AreEqual("XVII", annotations[0].Context.DocumentSection.Title);
Assert.AreNotEqual(0, annotations[0].Context.DocumentSection.Location);
Assert.AreEqual(0, annotations[0].Context.Location); // Annotation Location is not updated by EpubReader
Expand Down
4 changes: 2 additions & 2 deletions test/Noted.Tests/Extensions/Readers/PdfReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async Task ReadShouldParseSingleColumnLayoutDocument()
var document = await this.reader.Read(fs, new ReaderOptions(), this.emptyExternalAnnotations);

var annotations = document.Annotations.ToList();
Assert.AreEqual(2, annotations.Count);
Assert.HasCount(2, annotations);
Assert.AreEqual(
"Nam id ante vitae erat consequat bibendum quis vitae sapien. Etiam ac quam ac felis gravida rutrum. ",
annotations[0].Content);
Expand All @@ -102,7 +102,7 @@ public async Task ReadShouldParseTwoColumnLayoutDocument()
var document = await this.reader.Read(fs, new ReaderOptions(), this.emptyExternalAnnotations);

var annotations = document.Annotations.ToList();
Assert.AreEqual(5, annotations.Count);
Assert.HasCount(5, annotations);

// Multiple paragraphs are joined in context because there isn't much
// space between paragraph formatting
Expand Down
24 changes: 13 additions & 11 deletions test/Noted.Tests/Noted.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>

<WarningsAsErrors>true</WarningsAsErrors>
<EnableCodeAnalysis>true</EnableCodeAnalysis>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="PdfPig" Version="0.1.11" />
<PackageReference Include="Ephemerality.Unpack" Version="0.0.5" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.10.5" />
<PackageReference Include="MSTest.TestFramework" Version="3.8.3" />
<PackageReference Include="coverlet.collector" Version="6.0.4" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="System.Linq.Async" Version="7.0.0" />
<PackageReference Include="PdfPig" />
<PackageReference Include="Ephemerality.Unpack" />

<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="Moq" />
<PackageReference Include="System.Linq.Async" />
</ItemGroup>



<ItemGroup>
<ProjectReference Include="..\..\src\Noted\Noted.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
<PackageReference Include="coverlet.msbuild">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down