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, }); } }
public Post Transform(ResponsePost x) { var updated = DateTimes.UnixTimeStampToDateTime(x.CreatedUtc); var possibleMediaPreviewUrl = GetMediaPreviewUrl(x); return(new Post { Id = ids.IdFromUrl(x.Url), Author = x.Author.Truncate(100), Content = x.Selftext, Score = x.Score, Controversiality = null, Gilded = x.Gilded, Title = x.Title.Truncate(200), Subreddit = ids.ExtractSubredditIdFromUrl(x.Url) ?? string.Empty, PublishedMonthPrecision = updated.MonthPrecision(), PublishedWeekPrecision = updated.DayOfWeekPrecision(), PublishedDayPrecision = updated.DayPrecision(), PublishedHourPrecision = updated.HourPrecision(), PublishedMinutePrecision = updated.MinutePrecision(), PublishedTimestamp = updated, IngestedTimestamp = DateTime.UtcNow, Url = x.Url, MediaPreviewUrl = possibleMediaPreviewUrl, }); }
public void IdFromUrl_good_value() { ids = new Ids(logger.Object); var returned = ids.IdFromUrl("http://google.com"); Assert.AreEqual("aa2239c17609b21eba034c564af878f3eec8ce83ed0f2768597d2bc2fd4e4da5", returned, "Returned value didn't match the SHA256 generated via http://www.xorbin.com/tools/sha256-hash-calculator"); logger.Verify(); }
public void IdFromUrl_empty_url() { logger.Setup(x => x.Error(It.IsAny <string>(), null, null)); ids = new Ids(logger.Object); var returned = ids.IdFromUrl(""); Assert.IsNull(returned, "The returned value should have been null"); logger.Verify(); }