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,
                });
            }
        }
Exemple #2
0
        public void ParentUrlFromChildDetails_null_child_url()
        {
            logger.Setup(x => x.Error(It.IsAny <string>(), null, null));
            ids = new Ids(logger.Object);
            var returned = ids.ParentUrlFromChildDetails(
                childUrl: null,
                childId: "dmo8j8n",
                parentId: "dmjuw52"
                );

            Assert.IsNull(returned, "The returned value should have been null");
            logger.Verify();
        }
Exemple #3
0
        public void ParentUrlFromChildDetails_null_child_id()
        {
            logger.Setup(x => x.Error(It.IsAny <string>(), null, null));
            ids = new Ids(logger.Object);
            var returned = ids.ParentUrlFromChildDetails(
                childUrl:
                "https://www.reddit.com/r/Competitiveoverwatch/comments/6xzuk2/doomfists_new_hitbox_analysis_xpost_from/dmo8j8n/",
                childId: null,
                parentId: "dmjuw52"
                );

            Assert.IsNull(returned, "The returned value should have been null");
            logger.Verify();
        }
Exemple #4
0
        public void ParentUrlFromChildDetails_expected_success()
        {
            ids = new Ids(logger.Object);
            const string parentUrl =
                "https://www.reddit.com/r/Competitiveoverwatch/comments/6xzuk2/doomfists_new_hitbox_analysis_xpost_from/dmjuw52/";
            var returned = ids.ParentUrlFromChildDetails(
                childUrl:
                "https://www.reddit.com/r/Competitiveoverwatch/comments/6xzuk2/doomfists_new_hitbox_analysis_xpost_from/dmo8j8n/",
                childId: "dmo8j8n",
                parentId: "dmjuw52"
                );

            Assert.AreEqual(parentUrl, returned, $"The generated URL {parentUrl} did not match {returned}");
            logger.Verify();
        }
Exemple #5
0
        public void ParentUrlFromChildDetails_unexpected_url()
        {
            const string childId  = "dmo8j8n";
            const string parentId = "dmjuw52";
            const string childUrl =
                "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.ParentUrlFromChildDetails(
                childUrl: childUrl,
                childId: childId,
                parentId: parentId
                );

            Assert.IsNull(returned, $"Somehow an ID was generated: {returned}");
        }