< Summary

Information
Class: GistBackend.Handlers.RssFeedHandler.Feeds.SecurityInsiderNews
Assembly: GistBackend
File(s): /home/runner/work/the-gist-of-it-sec/the-gist-of-it-sec/backend/GistBackend/Handlers/RssFeedHandler/Feeds/SecurityInsiderNews.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 30
Coverable lines: 30
Total lines: 63
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%
CheckForSponsoredContent(...)100%210%

File(s)

/home/runner/work/the-gist-of-it-sec/the-gist-of-it-sec/backend/GistBackend/Handlers/RssFeedHandler/Feeds/SecurityInsiderNews.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 SecurityInsiderNews : RssFeed
 12{
 013    public override Uri RssUrl => new("https://www.security-insider.de/rss/news.xml");
 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[@class='inf-article-detail']");
 023        if (entryContainer == null)
 24        {
 025            throw new ExtractingEntryTextException("Missing container element");
 26        }
 27
 028        var textContainerSelectors = new List<string>
 029        {
 030            ".//p[contains(@class, 'inf-text-')]",
 031            $".//h1[{ContainsClassSpecifier("inf-xheading")}]",
 032            $".//h2[{ContainsClassSpecifier("inf-xheading")}]",
 033            $".//h3[{ContainsClassSpecifier("inf-xheading")}]",
 034            $".//h4[{ContainsClassSpecifier("inf-xheading")}]",
 035            $".//h5[{ContainsClassSpecifier("inf-xheading")}]",
 036            $".//h6[{ContainsClassSpecifier("inf-xheading")}]"
 037        };
 038        var textContainers = entryContainer.SelectNodes(string.Join(" | ", textContainerSelectors));
 039        if (textContainers == null || textContainers.Count == 0)
 40        {
 041            throw new ExtractingEntryTextException("Missing text container elements");
 42        }
 43
 044        var textContent = string.Join("\n", textContainers.Select(node => node.InnerText));
 045        if (string.IsNullOrWhiteSpace(textContent))
 46        {
 047            throw new ExtractingEntryTextException("No text found in containers");
 48        }
 49
 050        var decodedText = HtmlDecode(textContent);
 051        return decodedText.Trim();
 52    }
 53
 54    public override bool CheckForSponsoredContent(string content)
 55    {
 056        var doc = new HtmlDocument();
 057        doc.LoadHtml(content);
 058        var companiesSection = doc.DocumentNode.SelectSingleNode("//section[contains(@class, 'inf-companies-rel')]");
 59        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 060        return companiesSection is not null;
 61    }
 62}
 63