Exemplo n.º 1
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.");
     }
 }
 public void verifyIsCategoryNullCategoryUnsuccessfully()
 {
     Assert.IsFalse(ChuckNorrisAPI.isCategory(null));
 }
 public void verifyIsCategoryInvalidCategoryUnsuccessfully()
 {
     Assert.IsFalse(ChuckNorrisAPI.isCategory("not a category"));
 }
        public void verifyIsCategoryProperCategorySuccessfully()
        {
            List <string> categories = ChuckNorrisAPI.getCategories();

            Assert.IsTrue(ChuckNorrisAPI.isCategory(categories[0]));
        }