private static IList <string> GetCategoriesDeserializedResponse(HttpStatusCode statusCode = HttpStatusCode.OK, string json = RealCategoryResponse) { var handlerMock = CreateMessageHandlerMock(statusCode, json, CategoriesUri); var feed = new ChuckNorrisJsonFeed(handlerMock.Object); return(feed.GetCategories()); }
private static RandomJokeResponse GetRandomJokeDeserializedResponse(HttpStatusCode statusCode = HttpStatusCode.OK, string category = null, string jokeText = null) { var uri = category == null ? RandomJokesUri : RandomJokesWithCategoryUri + category; var handlerMock = CreateMessageHandlerMock(statusCode, jokeText ?? BuildRandomJokeResponse(), uri); var feed = new ChuckNorrisJsonFeed(handlerMock.Object); return(feed.GetRandomJokeResponse(category)); }
public void GetHttpClientWorksWithoutProvidedHandler() { // This can also be proven working properly by manually running the integration tests for this feed. var feed = new ChuckNorrisJsonFeed(); Assert.IsNull(feed.Handler); feed.GetHttpClient(); Assert.Pass("No exception was thrown, so HttpClient was constructed successfully."); }
public void GetCategoriesWorksAgainstLiveApi() { var feed = new ChuckNorrisJsonFeed(); var categories = feed.GetCategories(); Assert.IsTrue(categories.Any(), "No categories were retrieved."); // Test for a known category, but don't bother with entire set as it can change. Assert.IsTrue(categories.Contains("animal"), "Categories did not contain expected category"); }
public void GetRandomJokeWorksAgainstLiveApi() { var feed = new ChuckNorrisJsonFeed(); var joke = feed.GetRandomJoke(); Assert.IsNotNull(joke, "Returned joke was null."); // Since we don't know what the live server will return, just do a very simple test. StringAssert.Contains("Chuck Norris", joke); }
public void GetRandomJokeWithBadCategoryAgainstLiveApiGetsException() { var feed = new ChuckNorrisJsonFeed(); Assert.That(() => feed.GetRandomJokeResponse("badCategory"), Throws.TypeOf <JsonFeedException>()); }