Exemple #1
0
        private RootRedditObject GetFakeRedditComments()
        {
            var expectedComments = new RootRedditObject
            {
                Data = new Data
                {
                    Comments = new List <CommentAndKind>
                    {
                        new CommentAndKind
                        {
                            Comment = new Util.Comment
                            {
                                Author = "Snoo",
                                Body   = "Frontpage of the internet."
                            }
                        },
                        new CommentAndKind
                        {
                            Comment = new Util.Comment
                            {
                                Author = "Pao",
                                Body   = "Burn everything."
                            }
                        }
                    }
                }
            };

            return(expectedComments);
        }
        private async Task <IEnumerable <Comment> > ToComments(HttpResponseMessage response)
        {
            RootRedditObject rootRedditObject = new RootRedditObject();

            try
            {
                rootRedditObject = JsonConvert.DeserializeObject <RootRedditObject>(await response.Content.ReadAsStringAsync());

                return(rootRedditObject.Data.Comments.Select(c => new Comment(c.Comment.Author, c.Comment.Body)));
            }
            catch (Exception e)
            {
                throw new RedditCommentsFormatException("The comments returned are not in the expected format", e);
            }
        }