< Summary

Information
Class: GistBackend.Handlers.RssFeedHandler.Feeds.HeiseSecurity
Assembly: GistBackend
File(s): /home/runner/work/the-gist-of-it-sec/the-gist-of-it-sec/backend/GistBackend/Handlers/RssFeedHandler/Feeds/HeiseSecurity.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 16
Coverable lines: 16
Total lines: 43
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_RssUrl()100%210%
get_Language()100%210%
get_Type()100%210%
ExtractText(...)0%7280%

File(s)

/home/runner/work/the-gist-of-it-sec/the-gist-of-it-sec/backend/GistBackend/Handlers/RssFeedHandler/Feeds/HeiseSecurity.cs

#LineLine coverage
 1using GistBackend.Exceptions;
 2using GistBackend.Types;
 3using HtmlAgilityPack;
 4using static System.Net.WebUtility;
 5using static GistBackend.Types.FeedType;
 6using static GistBackend.Types.Language;
 7
 8namespace GistBackend.Handlers.RssFeedHandler.Feeds;
 9
 10public record HeiseSecurity : RssFeed
 11{
 012    public override Uri RssUrl => new("https://www.heise.de/security/feed.xml");
 013    public override Language Language => De;
 014    public override FeedType Type => News;
 15
 16    public override string ExtractText(string content)
 17    {
 018        var doc = new HtmlDocument();
 019        doc.LoadHtml(content);
 20
 021        var entryContainer = doc.DocumentNode.SelectSingleNode("//div[@class='article-content']");
 022        if (entryContainer == null)
 23        {
 024            throw new ExtractingEntryTextException("Missing container element");
 25        }
 26
 027        var paragraphsAndHeadings = entryContainer.SelectNodes(".//p | .//h1 | .//h2 | .//h3 | .//h4 | .//h5 | .//h6");
 028        if (paragraphsAndHeadings == null || paragraphsAndHeadings.Count == 0)
 29        {
 030            throw new ExtractingEntryTextException("Missing paragraph or heading elements");
 31        }
 32
 033        var combinedTextContents = string.Join("\n", paragraphsAndHeadings.Select(node => node.InnerText));
 034        if (string.IsNullOrWhiteSpace(combinedTextContents))
 35        {
 036            throw new ExtractingEntryTextException("No text found in container");
 37        }
 38
 039        var decodedText = HtmlDecode(combinedTextContents);
 040        return decodedText.Trim();
 41    }
 42}
 43