public void GetSports_ShouldNot_EmptyCollection_IfHttpStatusNotOk() { HttpResponseMessage responseMessage = new HttpResponseMessage(HttpStatusCode.InternalServerError); var httpMessageHandler = new HttpMessageHandlerMock(responseMessage); RedditClient redditCleint = new RedditClient(httpMessageHandler); var redditResponse = redditCleint.GetSports().Result.ToList(); Assert.IsInstanceOfType(redditResponse, typeof(List <SportPost>)); Assert.IsTrue(redditResponse.Count == 0); }
public void GetSports_ShouldReturn_ProperlyDeserielizedReditResponse() { HttpResponseMessage responseMessage = new HttpResponseMessage(System.Net.HttpStatusCode.OK); responseMessage.Content = new StringContent(RedditClientTest.SportPostsJson); responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(@"application/json"); var httpMessageHandler = new HttpMessageHandlerMock(responseMessage); RedditClient redditCleint = new RedditClient(httpMessageHandler); var redditResponse = redditCleint.GetSports().Result.ToList(); var jsonObjectFromRedit = new StringContent(RedditClientTest.SportPostsJson, Encoding.UTF8, new MediaTypeHeaderValue(@"application/json").ToString()).ReadAsAsync <JObject>(); var serializer = JsonSerializer.Create(); var expectedResult = serializer .Deserialize <ICollection <RedditSportPost> >(jsonObjectFromRedit.Result["data"]["children"].CreateReader()) .Select(rs => rs.Data) .ToList(); Assert.IsTrue(expectedResult.SequenceEqual(redditResponse, new SportPostComparer())); }