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 ExtractIdFromTypeAndId_empty_after_splitting()
        {
            const string typeAndId = "t1_  ";

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

            Assert.IsNull(returned, $"Expected a null value, somehow got a real one [{returned}]");
            logger.Verify();
        }
Exemple #3
0
        public void ExtractIdFromTypeAndId_expected_success()
        {
            const string typeAndId = "t1_dmjuw52";
            const string expected  = "dmjuw52";

            ids = new Ids(logger.Object);
            var returned = ids.ExtractIdFromTypeAndId(typeAndId);

            Assert.AreEqual(expected, returned, $"{expected} did not match {returned}");
            logger.Verify();
        }
Exemple #4
0
        public void ExtractIdFromTypeAndId_not_enough_underscores()
        {
            const string typeAndId = "dmjuw52";

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

            Assert.IsNull(returned, $"Expected a null value, somehow got a real one [{returned}]");
            logger.Verify();
        }