< Summary

Information
Class: GistBackend.Handlers.RssFeedHandler.Feeds.DarkReading
Assembly: GistBackend
File(s): /home/runner/work/the-gist-of-it-sec/the-gist-of-it-sec/backend/GistBackend/Handlers/RssFeedHandler/Feeds/DarkReading.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 21
Coverable lines: 21
Total lines: 57
Line coverage: 0%
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%210%
get_Language()100%210%
get_Type()100%210%
ExtractText(...)0%110100%

File(s)

/home/runner/work/the-gist-of-it-sec/the-gist-of-it-sec/backend/GistBackend/Handlers/RssFeedHandler/Feeds/DarkReading.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 DarkReading : RssFeed
 12{
 013    public override Uri RssUrl => new("https://www.darkreading.com/rss.xml");
 014    public override Language Language => En;
 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 entryContentSingleNode =
 023            doc.DocumentNode.SelectSingleNode($"//div[{ContainsClassSpecifier("ArticleBase-BodyContent")}]");
 24        string textContent;
 25
 26        // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
 027        if (entryContentSingleNode == null)
 28        {
 029            var entryContentMultiNode =
 030                doc.DocumentNode.SelectNodes(
 031                    $"//div[{ContainsClassSpecifier("ArticleMultiSectionBody-SectionContainer")}]");
 032            if (entryContentMultiNode == null || entryContentMultiNode.Count == 0)
 33            {
 034                throw new ExtractingEntryTextException("Missing single and multi node container elements");
 35            }
 36
 037            textContent = string.Join("", entryContentMultiNode.Select(node => node.InnerText));
 038            if (string.IsNullOrWhiteSpace(textContent))
 39            {
 040                throw new ExtractingEntryTextException("No text found in multi node container");
 41            }
 42        }
 43        else
 44        {
 045            textContent = entryContentSingleNode.InnerText;
 46        }
 47
 048        if (string.IsNullOrWhiteSpace(textContent))
 49        {
 050            throw new ExtractingEntryTextException("No text found in container");
 51        }
 52
 053        var decodedText = HtmlDecode(textContent);
 054        return decodedText.Trim();
 55    }
 56}
 57