public void createARandomJokeForANullCategorySuccessfully() { Joke joke = Joke.create(null); Assert.IsNotNull(joke); Assert.IsNotEmpty(joke.ToString()); Assert.IsTrue(joke.ToString().Contains("Chuck Norris")); }
public void createARandomJokeAndSubstituteNameSuccessfully() { Joke joke = Joke.create(); joke.substituteName(); Assert.IsNotNull(joke); Assert.IsNotEmpty(joke.ToString()); Assert.IsFalse(joke.ToString().Contains("Chuck Norris")); }
/// <summary> /// <c>startJoke</c> starts the flow for getting a joke for the user. /// This function will also prompt the user about additional commands for /// how they would like to get a joke from the API. /// </summary> private static void startJoke() { // Ask the user if they would like to substitute Chuck Norris with a random name Console.WriteLine("Do you want to use a random name?"); bool includeRandomName = CommandLineUtils.listenForCharacterInput(getYesNoCommands()) == (char)YesNoCommand.Yes; // Ask the user if they would like to specify a category for the Chuck Norris joke Console.WriteLine("Do you want to specify a category?"); bool includeCategory = CommandLineUtils.listenForCharacterInput(getYesNoCommands()) == (char)YesNoCommand.Yes; // If the user wants to include a category, get the specific category from the user string category = null; if (includeCategory) { Console.WriteLine("Enter a category: "); category = CommandLineUtils.listenForStringInput(Joke.getCategories()); Console.WriteLine(category); } // Ask the user how many jokes that they want to retrieve from the API Console.WriteLine("How many jokes do you want? (1-9)"); int numberOfJokes = CommandLineUtils.listenForSingleDigitValue(); for (int i = 0; i < numberOfJokes; i++) { // Create a new joke... note that if the category is null, a regular random joke will be made. Joke joke = Joke.create(category); // Substitute Chuck Norris for random name, if requested if (includeRandomName) { joke.substituteName(); } // Print the final joke to the console Console.WriteLine("\n" + joke.ToString() + "\n"); } }