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()); }
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()); }
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); }
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()); }