public Comment Transform(ResponseComment x)
        {
            var updated        = DateTimes.UnixTimeStampToDateTime(x.CreatedUtc);
            var url            = $"https://www.reddit.com{x.Permalink}";
            var parentRedditId = ids.ExtractIdFromTypeAndId(x.ParentId);
            var parentUrl      = ids.ParentUrlFromChildDetails(
                childUrl: url,
                childId: x.Id,
                parentId: parentRedditId
                );
            var generatedParentId = ids.IdFromUrl(parentUrl);
            var postUrl           = ids.PostUrlFromChildDetails(
                childUrl: url,
                childId: x.Id
                );
            var generatedPostId = ids.IdFromUrl(postUrl);

            var id = ids.IdFromUrl(url);

            if (new string[] { parentRedditId, parentUrl, generatedParentId, postUrl, generatedPostId }.Any(
                    string.IsNullOrEmpty))
            {
                log.Error(
                    $"One or more of the essential structure providing details was null or empty: [parentRedditId={parentRedditId}], [parentUrl={parentUrl}], [generatedParentId={generatedParentId}], [postUrl={postUrl}], [generatedPostId={generatedPostId}]");
                log.Error("This entry will not be saved to the database!");

                return(new InvalidComment()
                {
                    Id = id
                });
            }
            else
            {
                return(new Comment
                {
                    Id = id,
                    Author = x.Author.Truncate(100),
                    Content = x.Body,
                    Score = x.Score,
                    Controversiality = x.Controversiality,
                    Gilded = x.Gilded,
                    Subreddit = ids.ExtractSubredditIdFromUrl(url) ?? string.Empty,
                    PublishedMonthPrecision = updated.MonthPrecision(),
                    PublishedWeekPrecision = updated.DayOfWeekPrecision(),
                    PublishedDayPrecision = updated.DayPrecision(),
                    PublishedHourPrecision = updated.HourPrecision(),
                    PublishedMinutePrecision = updated.MinutePrecision(),
                    PublishedTimestamp = updated,
                    IngestedTimestamp = DateTime.UtcNow,
                    Url = url,
                    ParentId = generatedParentId,
                    PostId = generatedPostId,
                    ParentUrl = parentUrl,
                    PostUrl = postUrl,
                });
            }
        }
Beispiel #2
0
        public void PostUrlFromChildDetails_empty_url()
        {
            const string childUrl = "";
            const string childId  = "dmo8j8n";

            logger.Setup(x => x.Error(It.IsAny <string>(), null, null));
            ids = new Ids(logger.Object);
            var returned = ids.PostUrlFromChildDetails(childUrl, childId);

            Assert.IsNull(returned, $"Expected a null value, somehow got a real one [{returned}]");
            logger.Verify();
        }
Beispiel #3
0
        public void PostUrlFromChildDetails_child_id_not_in_url()
        {
            const string childUrl =
                "https://www.reddit.com/r/Competitiveoverwatch/comments/6xzuk2/doomfists_new_hitbox_analysis_xpost_from/";
            const string childId = "dmo8j8n";

            logger.Setup(x => x.Error(It.IsAny <string>(), null, null));
            ids = new Ids(logger.Object);
            var returned = ids.PostUrlFromChildDetails(childUrl, childId);

            Assert.IsNull(returned, $"Expected a null value, somehow got a real one [{returned}]");
            logger.Verify();
        }
Beispiel #4
0
        public void PostUrlFromChildDetails_child_id_no_trailing_slash()
        {
            const string childUrl =
                "https://www.reddit.com/r/Competitiveoverwatch/comments/6xzuk2/doomfists_new_hitbox_analysis_xpost_from/dmo8j8n";
            const string childId  = "dmo8j8n";
            const string expected =
                "https://www.reddit.com/r/Competitiveoverwatch/comments/6xzuk2/doomfists_new_hitbox_analysis_xpost_from/";

            logger.Setup(x => x.Error(It.IsAny <string>(), null, null));
            ids = new Ids(logger.Object);
            var returned = ids.PostUrlFromChildDetails(childUrl, childId);

            Assert.AreEqual(expected, returned, $"Expected {expected} but got {returned}");
            logger.Verify();
        }