Beispiel #1
0
        public async Task GivenValidApi_Get_CommentsReturned()
        {
            const string        expectedBaseAddress     = "https://reddit.com/r/all/comments.json";
            string              expectedResponseContent = JsonConvert.SerializeObject(GetFakeRedditComments());
            ICommentsRepository repository = new CommentsRepository(new HttpClient(GetMockedHttpMessageHandler(expectedResponseContent)), new Uri(expectedBaseAddress));

            var actual = await repository.Get();

            Assert.IsTrue(actual.Any());
            Assert.AreEqual(2, actual.Count());
        }
Beispiel #2
0
        public async Task GivenInvalidResponse_Get_RedditCommentsFormatExceptionThrown()
        {
            const string        expectedBaseAddress     = "https://reddit.com/r/all/comments.json";
            string              expectedResponseContent = JsonConvert.SerializeObject(new { UnexpectedProperty = "InvalidObject" });
            ICommentsRepository repository = new CommentsRepository(new HttpClient(GetMockedHttpMessageHandler(expectedResponseContent)), new Uri(expectedBaseAddress));

            var actual = await repository.Get();

            Assert.IsTrue(actual.Any());
            Assert.AreEqual(2, actual.Count());
        }
Beispiel #3
0
        private Comment Get(int id)
        {
            //NOTE If you do not null check you could get a 204 (No Context) if the Comment was not found
            Comment found = _repo.Get(id);

            if (found == null)
            {
                throw new Exception("Invalid Id");
            }
            return(found);
        }
Beispiel #4
0
        public async Task StartAsync()
        {
            Stopwatch s = Stopwatch.StartNew();

            var comments = await _repository.Get();

            Parallel.ForEach(comments, (comment) =>
            {
                if (_ohShitWaddupDetector.IsWorthyOhShitWaddup(comment.Body))
                {
                    Console.WriteLine($"[{comment.Body}] by [{comment.Author}]");
                }
            });

            s.Stop();

            Console.WriteLine($"Comments analyzed ({s.ElapsedMilliseconds} ms).");
        }
 public IEnumerable <Comment> Get()
 {
     return(_repo.Get());
 }