Ejemplo n.º 1
0
        public async Task StartAsync(IDialogContext context)
        {
            _joke = KnockKnockJokes.GetRandomJoke();
            // start by giving the intro, "Knock! Knock!", of course
            await context.PostAsync(_joke.Introduction);

            context.Wait(WaitForWhoseThere);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            while (true)
            {
                Jokes knockKnock = new KnockKnockJokes();
                Jokes oneLiner   = new OneLinerJokes();
                Jokes dadJokes   = new DadJokes();

                Console.WriteLine("Welcome to the Joke Generator! What type of joke would you like to hear?");
                Console.WriteLine("[1] Knock-Knock Joke");
                Console.WriteLine("[2] One-Liner");
                Console.WriteLine("[3] Dad Joke");
                Console.WriteLine("[4] Any Type");
                Console.WriteLine("Please select a joke type >>> ");
                string userChoice = Console.ReadLine();
                Console.WriteLine();

                switch (userChoice)
                {
                case "1":
                    knockKnock.TellJoke(GetRandomIndexValue(knockKnock.JokeList.Count));
                    Console.WriteLine();
                    ReturnToMenu();
                    break;

                case "2":
                    oneLiner.TellJoke(GetRandomIndexValue(oneLiner.JokeList.Count));
                    Console.WriteLine();
                    ReturnToMenu();
                    break;

                case "3":
                    dadJokes.TellJoke(GetRandomIndexValue(dadJokes.JokeList.Count));
                    Console.WriteLine();
                    ReturnToMenu();
                    break;

                case "4":
                    Console.WriteLine(TellRandomJokeOfAnyType(knockKnock.JokeList, oneLiner.JokeList, dadJokes.JokeList));
                    Console.WriteLine();
                    ReturnToMenu();
                    break;

                default:
                    Console.WriteLine("Selection was invalid, so you get a random joke!");
                    Console.WriteLine();
                    Console.WriteLine(TellRandomJokeOfAnyType(knockKnock.JokeList, oneLiner.JokeList, dadJokes.JokeList));
                    Console.WriteLine();
                    ReturnToMenu();
                    break;
                }
            }
Ejemplo n.º 3
0
        public void Normal_Joke_State_2_Test()
        {
            // Arrange
            string input    = "Dozen who?";
            string expected = "Dozen anybody want to let me in?";
            var    session  = new Dictionary <string, Object>();

            session["jokeID"]     = 0;
            session["jokeStatus"] = 2;
            // Act
            KnockKnockJokes program = new KnockKnockJokes();
            string          actual  = program.ProcessRequest(input, ref session);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
        public void Normal_Joke_State_1_Test()
        {
            // Arrange
            string input    = "Who's there?";
            string expected = "Dozen.";
            var    session  = new Dictionary <string, Object>();

            session["jokeID"]     = 0;
            session["jokeStatus"] = 1;
            // Act
            KnockKnockJokes program = new KnockKnockJokes();
            string          actual  = program.ProcessRequest(input, ref session);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        public void Normal_Joke_State_0_Test()
        {
            // Arrange
            string input    = "Tell me a knock-knock joke.";
            string expected = "Knock knock";
            var    session  = new Dictionary <string, Object>();

            session["jokeID"]     = 0;
            session["jokeStatus"] = 0;
            // Act
            KnockKnockJokes program = new KnockKnockJokes();
            string          actual  = program.ProcessRequest(input, ref session);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
        public void Normal_Joke_All_States_Test()
        {
            // Arrange
            var session = new Dictionary <string, Object>();

            session["jokeID"]     = 9;
            session["jokeStatus"] = 0;
            // Act
            KnockKnockJokes program = new KnockKnockJokes();
            string          actual  = program.ProcessRequest("Tell me a knock-knock joke.", ref session);

            session["jokeID"] = 9;
            string actual1 = program.ProcessRequest("Who's there?", ref session);
            string actual2 = program.ProcessRequest("Spell who?", ref session);

            // Assert
            Assert.AreEqual("Knock knock", actual);
            Assert.AreEqual("Spell.", actual1);
            Assert.AreEqual("W-H-O", actual2);
        }
Ejemplo n.º 7
0
        public void Give_Hint_Test()
        {
            // Arrange
            var session = new Dictionary <string, Object>();

            session["jokeID"]     = 9;
            session["jokeStatus"] = 0;
            // Act
            KnockKnockJokes program = new KnockKnockJokes();
            string          actual  = program.ProcessRequest("Tell me a knock-knock joke.", ref session);

            session["jokeID"] = 9;
            string actual1 = program.ProcessRequest("What do I do now?", ref session);
            string actual2 = program.ProcessRequest("Who's there?", ref session);

            // Assert
            Assert.AreEqual("Knock knock", actual);
            Assert.AreEqual("Try asking me \"Who's there?\"", actual1);
            Assert.AreEqual("Spell.", actual2);
        }
Ejemplo n.º 8
0
        public TwiMLResult Index()
        {
            string requestBody = Request.Form["Body"];

            // using Dictionary to pass in session variables
            // because the get/set syntax is the same as HttpSessionStateBase
            Dictionary <string, Object> sessionVars = new Dictionary <string, Object>();

            sessionVars["jokeStatus"] = Session["jokeStatus"];
            sessionVars["jokeID"]     = Session["jokeID"];

            KnockKnockJokes program        = new KnockKnockJokes();
            string          responseString = program.ProcessRequest(requestBody, ref sessionVars);

            Session["jokeStatus"] = sessionVars["jokeStatus"];
            Session["jokeID"]     = sessionVars["jokeID"];

            var messagingResponse = new MessagingResponse();

            messagingResponse.Message(responseString);
            return(TwiML(messagingResponse));
        }