diff --git a/src/Noted/Core/ExtractWorkflow.cs b/src/Noted/Core/ExtractWorkflow.cs index a8a7be2..9037a65 100644 --- a/src/Noted/Core/ExtractWorkflow.cs +++ b/src/Noted/Core/ExtractWorkflow.cs @@ -123,7 +123,7 @@ private IEnumerable EnumerateDocuments(string sourcePath, IEnumerable annotations) diff --git a/src/Noted/Core/Models/Document.cs b/src/Noted/Core/Models/Document.cs index 6fd6eab..57b2cd6 100644 --- a/src/Noted/Core/Models/Document.cs +++ b/src/Noted/Core/Models/Document.cs @@ -10,8 +10,8 @@ public class Document : DocumentReference { public Document() { - this.Annotations = new List(); - this.Sections = new List(); + this.Annotations = []; + this.Sections = []; } public string? Subject { get; set; } diff --git a/src/Noted/Extensions/Libraries/Kindle/ClippingAnnotationProvider.cs b/src/Noted/Extensions/Libraries/Kindle/ClippingAnnotationProvider.cs index f7bd977..6ee1367 100644 --- a/src/Noted/Extensions/Libraries/Kindle/ClippingAnnotationProvider.cs +++ b/src/Noted/Extensions/Libraries/Kindle/ClippingAnnotationProvider.cs @@ -29,7 +29,7 @@ public IEnumerable GetAnnotations(string sourcePath) { if (!this.IsAvailable(sourcePath)) { - return Enumerable.Empty(); + return []; } var annotationFile = Path.Combine(sourcePath, ClippingsFile); diff --git a/src/Noted/Extensions/Readers/EpubReader.cs b/src/Noted/Extensions/Readers/EpubReader.cs index 05af349..f1ef527 100644 --- a/src/Noted/Extensions/Readers/EpubReader.cs +++ b/src/Noted/Extensions/Readers/EpubReader.cs @@ -21,7 +21,7 @@ public class EpubReader(ILogger logger) : IDocumentReader { private readonly ILogger logger = logger; - public List SupportedExtensions => new() { "epub" }; + public List SupportedExtensions => ["epub"]; public async Task GetMetadata(Stream stream) { diff --git a/src/Noted/Extensions/Readers/KfxReader.cs b/src/Noted/Extensions/Readers/KfxReader.cs index 635c2d7..d43b8de 100644 --- a/src/Noted/Extensions/Readers/KfxReader.cs +++ b/src/Noted/Extensions/Readers/KfxReader.cs @@ -17,7 +17,7 @@ public class KfxReader(ILogger logger) : IDocumentReader { private readonly ILogger logger = logger; - public List SupportedExtensions => new() { "kfx" }; + public List SupportedExtensions => ["kfx"]; public Task GetMetadata(Stream stream) { diff --git a/src/Noted/Extensions/Readers/MobiReader.cs b/src/Noted/Extensions/Readers/MobiReader.cs index d93f176..4d39bf2 100644 --- a/src/Noted/Extensions/Readers/MobiReader.cs +++ b/src/Noted/Extensions/Readers/MobiReader.cs @@ -20,7 +20,7 @@ public class MobiReader(ILogger logger) : IDocumentReader private readonly ILogger logger = logger; // TODO add support for azw3 - public List SupportedExtensions => new() { "mobi" }; + public List SupportedExtensions => ["mobi"]; public Task GetMetadata(Stream stream) { diff --git a/src/Noted/Extensions/Readers/PdfReader.cs b/src/Noted/Extensions/Readers/PdfReader.cs index 4e6df56..793d651 100644 --- a/src/Noted/Extensions/Readers/PdfReader.cs +++ b/src/Noted/Extensions/Readers/PdfReader.cs @@ -32,15 +32,15 @@ public partial class PdfReader(ILogger logger) : IDocumentReader private readonly ILogger logger = logger; private readonly IWordExtractor wordExtractor = new NearestNeighbourWordExtractor(GetWordExtractOptions()); - public List SupportedExtensions => new() { "pdf" }; + public List SupportedExtensions => ["pdf"]; public Task GetMetadata(Stream stream) { var doc = PdfDocument.Open(stream); var docReference = new DocumentReference { - Title = doc.Information.Title, - Author = doc.Information.Author, + Title = doc.Information.Title ?? "Title unknown", + Author = doc.Information.Author ?? "Author unknown", SupportsEmbeddedAnnotation = true }; @@ -62,8 +62,8 @@ public Task Read( var doc = PdfDocument.Open(stream); var docReference = new DocumentReference { - Title = doc.Information.Title, - Author = doc.Information.Author + Title = doc.Information.Title ?? "Title unknown", + Author = doc.Information.Author ?? "Author unknown", }; // TODO add support for external annotations in pdf @@ -73,7 +73,7 @@ public Task Read( var words = this.wordExtractor .GetWords(letters) .ToList(); - foreach (var annotation in page.ExperimentalAccess.GetAnnotations().Where(a => a.Type.Equals(AnnotationType.Highlight))) + foreach (var annotation in page.GetAnnotations().Where(a => a.Type.Equals(AnnotationType.Highlight))) { // Find highlighted words var highlightedWords = new StringBuilder(); diff --git a/src/Noted/Infra/ConfigurationProvider.cs b/src/Noted/Infra/ConfigurationProvider.cs index f87b525..33298a3 100644 --- a/src/Noted/Infra/ConfigurationProvider.cs +++ b/src/Noted/Infra/ConfigurationProvider.cs @@ -23,9 +23,9 @@ public class ConfigurationProvider public ConfigurationProvider() { - this.annotationReaders = _ => Enumerable.Empty(); - this.documentReaders = _ => Enumerable.Empty(); - this.documentWriters = _ => Enumerable.Empty(); + this.annotationReaders = _ => []; + this.documentReaders = _ => []; + this.documentWriters = _ => []; this.commandLineConfig = new Configuration(); } diff --git a/src/Noted/Noted.csproj b/src/Noted/Noted.csproj index f428cb7..fa9210c 100644 --- a/src/Noted/Noted.csproj +++ b/src/Noted/Noted.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/Noted/Platform/IO/FileSystem.cs b/src/Noted/Platform/IO/FileSystem.cs index ef16f32..926e070 100644 --- a/src/Noted/Platform/IO/FileSystem.cs +++ b/src/Noted/Platform/IO/FileSystem.cs @@ -35,7 +35,7 @@ public IEnumerable GetFiles(string path, string searchPattern) { if (!this.IsDirectory(path)) { - return new[] { path }; + return [path]; } var extRegex = new Regex(searchPattern, RegexOptions.Compiled); diff --git a/src/Noted/Program.cs b/src/Noted/Program.cs index 498690d..45f8a5a 100644 --- a/src/Noted/Program.cs +++ b/src/Noted/Program.cs @@ -20,22 +20,23 @@ public static class Program public static async Task Main(string[] args) { var configurationProvider = new ConfigurationProvider() - .WithAnnotationProviders(config => new List - { + .WithAnnotationProviders(config => + [ new ClippingAnnotationProvider(config.FileSystem, config.Logger), new KOReaderAnnotationProvider(config.FileSystem, config.Logger) - }) - .WithReaders(config => new List - { + ]) + .WithReaders(config => + [ + // new KfxReader(config.Logger), new EpubReader(config.Logger), new PdfReader(config.Logger), new MobiReader(config.Logger) - }) - .WithWriters(config => new List - { + ]) + .WithWriters(config => + [ new MarkdownWriter(config.Logger) - }); + ]); var workflows = new Dictionary> { { "extract", config => new ExtractWorkflow(config.FileSystem, config.Logger) } }; diff --git a/test/Noted.Tests/Core/Models/LineLocationTests.cs b/test/Noted.Tests/Core/Models/LineLocationTests.cs index ef74ca0..500f7cf 100644 --- a/test/Noted.Tests/Core/Models/LineLocationTests.cs +++ b/test/Noted.Tests/Core/Models/LineLocationTests.cs @@ -13,7 +13,7 @@ public class LineLocationTests [TestMethod] public void LineLocationCompareShouldThrowExceptionForInvalidObject() { - Assert.ThrowsException(() => + Assert.ThrowsExactly(() => { new LineLocation(1, 2).CompareTo(string.Empty); }); diff --git a/test/Noted.Tests/Extensions/Libraries/Kindle/ClippingParserTests.cs b/test/Noted.Tests/Extensions/Libraries/Kindle/ClippingParserTests.cs index d671c1b..2f08933 100644 --- a/test/Noted.Tests/Extensions/Libraries/Kindle/ClippingParserTests.cs +++ b/test/Noted.Tests/Extensions/Libraries/Kindle/ClippingParserTests.cs @@ -30,7 +30,7 @@ public void ParseShouldThrowIfStreamIsClosed() { this.stream.Close(); - Assert.ThrowsException(() => ClippingParser.Parse(this.stream).ToList()); + Assert.ThrowsExactly(() => ClippingParser.Parse(this.stream).ToList()); } [TestMethod] @@ -98,7 +98,7 @@ public void ParseBookInfoShouldThrowIfBookInformationIsMalformed() { var line = "\ufeffSample Book"; - Assert.ThrowsException(() => this.clipping.ParseBookInfo(line)); + Assert.ThrowsExactly(() => this.clipping.ParseBookInfo(line)); } [TestMethod] @@ -123,7 +123,7 @@ public void ParseBookInfoShouldStoreBookNameAndAuthorInClipping(string line, str [DataRow("- Your Highlight on page 12 | Location 100-120 | Added on Thursday, August, 2019 10:17:58 AM")] public void ParseAnnotationInfoShouldThrowIfAnnotationInfoIsMissingOrInvalid(string line) { - Assert.ThrowsException( + Assert.ThrowsExactly( () => this.clipping.ParseAnnotationInfo(line)); } @@ -144,7 +144,7 @@ public void ParseAnnotationInfoShouldCaptureAnnotationMetadata(ClippingType type [TestMethod] public void SkipBlankLineShouldThrowIfNonBlankLineIsProvided() { - Assert.ThrowsException(() => + Assert.ThrowsExactly(() => this.clipping.SkipBlankLine("xx")); } diff --git a/test/Noted.Tests/Extensions/Readers/Common/HtmlContextParserTests.cs b/test/Noted.Tests/Extensions/Readers/Common/HtmlContextParserTests.cs index b32a0ed..227c3b0 100644 --- a/test/Noted.Tests/Extensions/Readers/Common/HtmlContextParserTests.cs +++ b/test/Noted.Tests/Extensions/Readers/Common/HtmlContextParserTests.cs @@ -55,7 +55,7 @@ public async Task HtmlContextParserShouldAddContextToAnnotations() var (a, _, _) = await HtmlContextParser.AddContext( this.sampleContentStream, SampleSections, - new[] { (new LineLocation(1, 2), this.annotations[0]) }); + [(new LineLocation(1, 2), this.annotations[0])]); Assert.AreEqual(1, a.Count); Assert.IsTrue(a[0].Context.Content.StartsWith("Never")); @@ -68,7 +68,7 @@ public async Task HtmlContextParserShouldAddContextWhenAnnotationSpansOverElemen var (a, _, _) = await HtmlContextParser.AddContext( this.sampleContentStream, SampleSections, - new[] { (new LineLocation(1, 2), this.annotations[1]) }); + [(new LineLocation(1, 2), this.annotations[1])]); Assert.AreEqual(1, a.Count); Assert.IsTrue(a[0].Context.Content.StartsWith("Thus, ")); diff --git a/test/Noted.Tests/Extensions/Readers/Common/HtmlSectionParserTests.cs b/test/Noted.Tests/Extensions/Readers/Common/HtmlSectionParserTests.cs index dcf1f18..8a10c61 100644 --- a/test/Noted.Tests/Extensions/Readers/Common/HtmlSectionParserTests.cs +++ b/test/Noted.Tests/Extensions/Readers/Common/HtmlSectionParserTests.cs @@ -91,12 +91,12 @@ public async Task ParseShouldCreateDocumentSectionRelationships() await using var stream = new MemoryStream(Encoding.UTF8.GetBytes(TocFragment)); var toc = await HtmlSectionParser.Parse(stream).ToListAsync(); - Assert.AreEqual(null, toc[3].Parent); // 1 -> null + Assert.IsNull(toc[3].Parent); // 1 -> null Assert.AreEqual("Section 1.1", toc[4].Title); Assert.AreEqual(toc[3], toc[4].Parent); // 1.1 -> 1 Assert.AreEqual(toc[4], toc[5].Parent); // 1.1.1 -> 1.1 Assert.AreEqual(toc[3], toc[6].Parent); // 1.2 -> 1 - Assert.AreEqual(null, toc[7].Parent); // 2 -> null + Assert.IsNull(toc[7].Parent); // 2 -> null } } } \ No newline at end of file diff --git a/test/Noted.Tests/Extensions/Readers/PdfReaderTests.cs b/test/Noted.Tests/Extensions/Readers/PdfReaderTests.cs index 92ca271..c739e21 100644 --- a/test/Noted.Tests/Extensions/Readers/PdfReaderTests.cs +++ b/test/Noted.Tests/Extensions/Readers/PdfReaderTests.cs @@ -45,7 +45,7 @@ public void PdfReaderShouldSupportOnlyPdfFileExtension() [TestMethod] public void PdfReaderShouldThrowIfStreamIsInvalid() { - Assert.ThrowsException(() => + Assert.ThrowsExactly(() => this.reader.Read(null, new ReaderOptions(), this.emptyExternalAnnotations)); } @@ -55,7 +55,7 @@ public void PdfReaderShouldThrowIfStreamIsUnreadable() using var stream = new MemoryStream(); stream.Close(); - Assert.ThrowsException(() => + Assert.ThrowsExactly(() => this.reader.Read(stream, new ReaderOptions(), this.emptyExternalAnnotations)); } diff --git a/test/Noted.Tests/Extensions/Writers/MarkdownWriterTests.cs b/test/Noted.Tests/Extensions/Writers/MarkdownWriterTests.cs index bbf8669..20470df 100644 --- a/test/Noted.Tests/Extensions/Writers/MarkdownWriterTests.cs +++ b/test/Noted.Tests/Extensions/Writers/MarkdownWriterTests.cs @@ -24,15 +24,15 @@ public async Task MarkdownWriterShouldNotCrashForDocumentWithoutSections() var stream = new MemoryStream(); var writer = new MarkdownWriter(new NullLogger()); - document.Annotations = new List - { + document.Annotations = + [ new( "dummy annotation", document, AnnotationType.Highlight, new AnnotationContext(), DateTime.Now) - }; + ]; await writer.Write(config, document, stream); } diff --git a/test/Noted.Tests/Noted.Tests.csproj b/test/Noted.Tests/Noted.Tests.csproj index 02aa79c..1a57319 100644 --- a/test/Noted.Tests/Noted.Tests.csproj +++ b/test/Noted.Tests/Noted.Tests.csproj @@ -9,7 +9,7 @@ - +