< Summary

Information
Class: GistBackend.Handlers.RssFeedHandler.Feeds.T3N
Assembly: GistBackend
File(s): /home/runner/work/the-gist-of-it-sec/the-gist-of-it-sec/backend/GistBackend/Handlers/RssFeedHandler/Feeds/T3N.cs
Line coverage
4%
Covered lines: 1
Uncovered lines: 22
Coverable lines: 23
Total lines: 55
Line coverage: 4.3%
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
.ctor()100%11100%
get_RssUrl()100%210%
get_Language()100%210%
get_Type()100%210%
get_ForbiddenCategories()100%210%
CheckForPaywall(...)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/T3N.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
 2311public record T3N() : RssFeed
 12{
 013    public override Uri RssUrl => new("https://t3n.de/tag/security/rss.xml");
 014    public override Language Language => De;
 015    public override FeedType Type => News;
 016    public override IEnumerable<string> ForbiddenCategories => ["jobs der woche"];
 17
 18    public override bool CheckForPaywall(string content)
 19    {
 020        var doc = new HtmlDocument();
 021        doc.LoadHtml(content);
 22
 023        var paywallDiv = doc.DocumentNode.SelectSingleNode($"//div[{ContainsClassSpecifier("c-paywall__wrapper")}]");
 24        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 025        return paywallDiv is not null;
 26    }
 27
 28    public override string ExtractText(string content)
 29    {
 030        var doc = new HtmlDocument();
 031        doc.LoadHtml(content);
 32
 033        var entryContainer = doc.DocumentNode.SelectSingleNode("//div[@class='c-entry']");
 034        if (entryContainer == null)
 35        {
 036            throw new ExtractingEntryTextException("Missing container element");
 37        }
 38
 039        var paragraphsAndHeadings =
 040            entryContainer.SelectNodes($".//p | .//div[{ContainsClassSpecifier("c-article__headline")}]");
 041        if (paragraphsAndHeadings == null || paragraphsAndHeadings.Count == 0)
 42        {
 043            throw new ExtractingEntryTextException("Missing paragraph or heading elements");
 44        }
 45
 046        var combinedTextContents = string.Join("\n", paragraphsAndHeadings.Select(node => node.InnerText));
 047        if (string.IsNullOrWhiteSpace(combinedTextContents))
 48        {
 049            throw new ExtractingEntryTextException("No text found in container");
 50        }
 51
 052        var decodedText = HtmlDecode(combinedTextContents);
 053        return decodedText.Trim();
 54    }
 55}