< Summary

Information
Class: GistBackend.Handlers.RssFeedHandler.Feeds.GolemSecurity
Assembly: GistBackend
File(s): /home/runner/work/the-gist-of-it-sec/the-gist-of-it-sec/backend/GistBackend/Handlers/RssFeedHandler/Feeds/GolemSecurity.cs
Line coverage
4%
Covered lines: 1
Uncovered lines: 21
Coverable lines: 22
Total lines: 54
Line coverage: 4.5%
Branch coverage
0%
Covered branches: 0
Total branches: 10
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%11100%
get_Language()100%210%
get_Type()100%210%
ExtractText(...)0%7280%
CheckForSponsoredContent(...)0%620%

File(s)

/home/runner/work/the-gist-of-it-sec/the-gist-of-it-sec/backend/GistBackend/Handlers/RssFeedHandler/Feeds/GolemSecurity.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;
 7using static GistBackend.Utils.RssFeedUtils;
 8
 9namespace GistBackend.Handlers.RssFeedHandler.Feeds;
 10
 11public record GolemSecurity : RssFeed
 12{
 2313    public override Uri RssUrl { get; } = new("https://rss.golem.de/rss.php?ms=security&feed=ATOM1.0");
 014    public override Language Language => De;
 015    public override FeedType Type => News;
 16
 17    public override string ExtractText(string content)
 18    {
 019        var doc = new HtmlDocument();
 020        doc.LoadHtml(content);
 21
 022        var entryContainer = doc.DocumentNode.SelectSingleNode($"//article[{ContainsClassSpecifier("go-article")}]");
 023        if (entryContainer == null)
 24        {
 025            throw new ExtractingEntryTextException("Missing container element");
 26        }
 27
 028        var paragraphsAndHeadings = entryContainer.SelectNodes(".//p | .//h1 | .//h2 | .//h3 | .//h4 | .//h5 | .//h6");
 029        if (paragraphsAndHeadings == null || paragraphsAndHeadings.Count == 0)
 30        {
 031            throw new ExtractingEntryTextException("Missing paragraph or heading elements");
 32        }
 33
 034        var combinedTextContents = string.Join("\n", paragraphsAndHeadings.Select(node => node.InnerText));
 035        if (string.IsNullOrWhiteSpace(combinedTextContents))
 36        {
 037            throw new ExtractingEntryTextException("No text found in container");
 38        }
 39
 040        var decodedText = HtmlDecode(combinedTextContents);
 041        return decodedText;
 42    }
 43
 44    public override bool CheckForSponsoredContent(string content)
 45    {
 046        var doc = new HtmlDocument();
 047        doc.LoadHtml(content);
 048        var kickerSpan =
 049            doc.DocumentNode.SelectSingleNode($"//span[{ContainsClassSpecifier("go-article-header__kicker")}]");
 50        // ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
 051        var sponsoredLabel = kickerSpan?.SelectSingleNode($".//span[{ContainsClassSpecifier("go-label--sponsored")}]");
 052        return sponsoredLabel != null;
 53    }
 54}