Ejemplo n.º 1
0
        public void getListOfCategoriesSuccessfully()
        {
            List <string> categories = Joke.getCategories();

            Assert.NotNull(categories);
            Assert.True(categories.Count > 0);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// <c>listCategories</c> lists the available categories for the jokes that can
 /// be retrieved from the Chuck Norris API.
 /// </summary>
 private static void listCategories()
 {
     Console.WriteLine("Here are the categories...");
     foreach (string category in Joke.getCategories())
     {
         Console.WriteLine("--> " + category);
     }
 }
Ejemplo n.º 3
0
        /// <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");
            }
        }