public void getRandomJokeWithCategorySuccessfully()
        {
            List <string> categories = ChuckNorrisAPI.getCategories();
            string        joke       = ChuckNorrisAPI.getRandomJokeWithCategory(categories[0]);

            Assert.IsNotNull(joke);
            Assert.IsNotEmpty(joke);
            Assert.IsTrue(joke.Contains("Chuck Norris"));
        }
 public void getRandomJokeWithCategoryUnsuccessfully()
 {
     try
     {
         string joke = ChuckNorrisAPI.getRandomJokeWithCategory("not a valid category");
         Assert.IsNull(joke);
     }
     catch (Exception e)
     {
         Assert.IsNotNull(e);
     }
 }
Exemple #3
0
 /// <summary>
 /// <c>create</c> Creates an instance of a Joke with a specific category.
 /// </summary>
 /// <returns>The random Joke within the category.</returns>
 public static Joke create(string category)
 {
     // Create a random joke if the provided category is null.
     if (category == null)
     {
         return(new Joke(ChuckNorrisAPI.getRandomJoke()));
     }
     // Create a joke within a category if the category is found.
     else if (ChuckNorrisAPI.isCategory(category))
     {
         return(new Joke(ChuckNorrisAPI.getRandomJokeWithCategory(category)));
     }
     // throw an exception if the category is invalid.
     else
     {
         throw new Exception("Could not create a Chuck Norris joke... invalid category given.");
     }
 }