Beispiel #1
0
        public void PhpGetTimeServerTaskHint()
        {
            CreatePHPBot();
            string Message = "ts hint";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1, "HINTS:\n" +
                            "For this exercise we'll be creating a raw TCP server. We will be using the core PHP socket_* functions. " +
                            "These functions are a thin wrapper around the C libraries.\n\n To create a server you need to use the functions socket_create," +
                            " socket_bind & socket_listen. Once the socket is listening, you can accept connections from it, which will return a new socket" +
                            " connected to the client whenever a client connects.\n\n socket_create returns a server resource. You must bind it to a host and" +
                            " port and then start listening.\n\n A typical PHP TCP server looks like this:\n\n" +
                            "<?php\n $server = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); \n socket_bind($server, '127.0.0.1', 8000); \n\n socket_listen($sock);\n\n" +
                            "$client = socket_accept($server);\n\n" +
                            "Remember to use the IP address & port number supplied to you as the first and second command-line argument.\n\n" +
                            "You can read and write to the socket by using socket_read and socket_write. For this exercise we only need " +
                            "to write data and then close the socket.\n\n" +
                            "Use socket_write($client, $data, strlen($data)) to write data to the socket and then socket_close($socket) to close the socket.\n\n" +
                            "Documentation on PHP streams can be found by pointing your browser here: http://php.net/manual/en/sockets.examples.php " +
                            "http://php.net/manual/en/function.stream-socket-server.php \n\n To create the date you'll need to create a custom format from the " +
                            "PHP DateTime object. The various parameters to format() will help you. " +
                            "You can find the documentation here: http://php.net/manual/en/class.datetime.php"
                            );
        }
Beispiel #2
0
        public async Task <JsonResult> ChatAsync([FromBody] ChatRequestBody body, [FromHeader] string sessionId)
        {
            IRestChatSession currentChatSession = null;

            Domain.ChatBot chatBot = await GetChatBotAsync();

            Domain.ChatSession chatSession = null;
            if (String.IsNullOrEmpty(sessionId))
            {
                chatSession = await _chatSessionService.Create(new Domain.ChatSession()
                {
                    ChatBotId = chatBot.ChatBotId
                });

                currentChatSession = new RestChatSession();
            }
            else
            {
                if (await _chatSessionService.Exists(session => session.ChatSessionId == Int32.Parse(sessionId)))
                {
                    chatSession = await _chatSessionService.FindBy(session => session.ChatSessionId == Int32.Parse(sessionId));
                }
                else
                {
                    chatSession = await _chatSessionService.Create(new Domain.ChatSession()
                    {
                        ChatBotId = chatBot.ChatBotId
                    });
                }

                Dictionary <string, string> sessionData = null;
                if (String.IsNullOrEmpty(chatSession.Data))
                {
                    sessionData = new Dictionary <string, string>();
                }
                else
                {
                    sessionData = JsonConvert.DeserializeObject <Dictionary <string, string> >(chatSession.Data);
                }

                currentChatSession = new RestChatSession(chatSession.ChatSessionId, sessionData);
            }
            Tuple <string, object> chatBotResponse = _chatBot.FindAnswer(currentChatSession, body.Message);

            string messageResponse = chatBotResponse.Item1;
            object responseObject  = chatBotResponse.Item2;

            await SaveSessionDataAsync(currentChatSession);

            sessionId = chatSession.ChatSessionId.ToString();

            if (responseObject != null && responseObject.GetType() == typeof(ExerciseResponse))
            {
                return(Json(new { sessionId = sessionId, chatbotResponse = messageResponse, exercise = responseObject }));
            }
            else
            {
                return(Json(new { sessionId = sessionId, chatbotResponse = messageResponse }));
            }
        }
Beispiel #3
0
        public void JavaGiveTask()
        {
            CreateJavaBot();
            string Message = "give me task";
            ChatSessionInterface session = new RestChatSession();

            Console.WriteLine(javaChatBot.FindAnswer(session, Message).Item1);
        }
Beispiel #4
0
        public void JavaLearning()
        {
            CreateJavaBot();
            string Message = "suggest me java learning sites";
            ChatSessionInterface session = new RestChatSession();

            Console.WriteLine(javaChatBot.FindAnswer(session, Message).Item1);
        }
Beispiel #5
0
        public void JavaAllCourses()
        {
            CreateJavaBot();
            string Message = "show me tasks";
            ChatSessionInterface session = new RestChatSession();

            Console.WriteLine(javaChatBot.FindAnswer(session, Message).Item1);
        }
Beispiel #6
0
        public void JavaFact()
        {
            CreateJavaBot();
            string Message = "tell me interesting fact about java";
            ChatSessionInterface session = new RestChatSession();

            Console.WriteLine(javaChatBot.FindAnswer(session, Message).Item1);
        }
Beispiel #7
0
        public void JavaCourseAskTest()
        {
            CreateJavaBot();
            string Message = "What course name";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(javaChatBot.FindAnswer(session, Message).Item1, "I do not know course name");
        }
Beispiel #8
0
        public void PhpCourseNameTest()
        {
            CreatePHPBot();
            string Message = "What course name";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1, "I do not know course name");
        }
Beispiel #9
0
        public void BotTest_HaveError()
        {
            chatBot = new RestChatBot(_errorBotRules);
            string Message = "I have exception";
            ChatSessionInterface session = new RestChatSession();
            var answer = chatBot.FindAnswer(session, Message);

            Assert.AreEqual(answer.Item1, "Whats the problem ?");
        }
Beispiel #10
0
        public void BotTest_FindSolutionForError()
        {
            chatBot = new RestChatBot(_errorBotRules);
            string Message = "find the solution to this error";
            ChatSessionInterface session = new RestChatSession();
            var answer = chatBot.FindAnswer(session, Message);

            Assert.AreEqual(answer.Item1, "try this.  google.com");
        }
Beispiel #11
0
        public void BotTest_Goodbye()
        {
            chatBot = new RestChatBot(_goodByeBotRules);
            string Message = "ate";

            ChatSessionInterface session = new RestChatSession();
            var answer = chatBot.FindAnswer(session, Message);

            Assert.AreEqual(answer.Item1, "bye bye");
        }
Beispiel #12
0
        public void PhpGetHelloWorldTask()
        {
            CreatePHPBot();
            string Message = "give me hello world task";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1,
                            "Write a program that prints the text \"Hello World\" to the console (stdout).");
        }
Beispiel #13
0
        public void JavaCourseAskTestSucces()
        {
            CreateJavaBot();
            string Message = "Course name is Java Course";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(javaChatBot.FindAnswer(session, Message).Item1, "Course name now is Java Course");

            Console.WriteLine(javaChatBot.FindAnswer(session, Message).Item1);
        }
Beispiel #14
0
        public void BotTest_GetJoke()
        {
            chatBot = new RestChatBot(_jokeBotRules);
            string               Message = "tell me a joke";
            List <string>        jokes   = JokeRuleSet.jokeList;
            ChatSessionInterface session = new RestChatSession();
            var answer = chatBot.FindAnswer(session, Message);

            Console.WriteLine(answer.Item1);
            Assert.IsTrue(jokes.Contains(answer.Item1));
        }
Beispiel #15
0
        public void PhpGetBabyStepsTask()
        {
            CreatePHPBot();
            string Message = "give me baby steps task";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1,
                            "Write a program that accepts one or more numbers as command-line arguments " +
                            "and prints the sum of those numbers to the console (stdout)."
                            );
        }
Beispiel #16
0
        public void PhpGetMyFirstIOTask()
        {
            CreatePHPBot();
            string Message = "my-first-io";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1,
                            "Write a program that uses a single filesystem operation to read a file and print the number of newlines (\\n) " +
                            "it contains to the console (stdout), similar to running cat file | wc -l.\n" +
                            "The full path to the file to read will be provided as the first command-line argument. You do not need to make your own test file."
                            );
        }
Beispiel #17
0
        public void PhpGetExceptionalCodingTaskHint()
        {
            CreatePHPBot();
            string Message = "ec hint";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1, "HINTS:\n" +
                            "You are urged to use try... catch logic here along with the SplFileObject contruct which " +
                            "throws a RuntimeException when a file does not exist.\n\n" +
                            "Documentation on the SplFileObject class can be found by pointing your browser here:\n http://php.net/manual/en/class.splfileobject.php"
                            );
        }
Beispiel #18
0
        public void PhpGetArrayWeGoTask()
        {
            CreatePHPBot();
            string Message = "array we go task";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1,
                            "Write a program that takes an array of filepaths as arguments, filtering " +
                            "out files that do not exist and mapping existing files to SplFileObject's.\n\n" +
                            "Finally output the basename of the files, each on a new line.\n\n " +
                            "The full path of the files to read will be provided as the command line arguments. You do not need to make your own test files."
                            );
        }
Beispiel #19
0
        public void PhpGetArrayWeGoTaskHint()
        {
            CreatePHPBot();
            string Message = "array-we-go hint";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1, "HINTS:\n" +
                            "Remember the first argument will be the programs file path and not an argument passed to the program.\n\n" +
                            "You will be expected to make use of core array functions, array_shift, array_filter and array_map.\n\n" +
                            "To check a file exists you will need to use file_exists($filePath). This method will return a boolean true or false.\n\n" +
                            "Documentation on the SplFileObject class can be found by pointing your browser here:\n http://php.net/manual/en/class.splfileobject.php"
                            );
        }
Beispiel #20
0
        public void PhpGetExceptionalCodingTask()
        {
            CreatePHPBot();
            string Message = "exceptional-coding";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1,
                            "Write a program that takes an array of filepaths as arguments and outputs the basename of each, separated by a new line.\n\n" +
                            "Every file should exist but under exceptional circumstances some files may not. If this occurs, output a message similar to the below.\n\n" +
                            "Unable to open file at path '/file/path'\n\n" +
                            "The full path of the files to read will be provided as the command line arguments. You do not need to make your own test files."
                            );
        }
Beispiel #21
0
        public void PhpGetTimeServerTask()
        {
            CreatePHPBot();
            string Message = "time-server";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1,
                            "Write a TCP time server!\n\n Your server should listen to TCP connections on the IP address provided as the first argument" +
                            " and the port provided by the second argument to your program. For each connection you must write the current date & " +
                            "24 hour time in the format:\n\n \"YYYY-MM-DD hh:mm:ss\"\n\n followed by a newline character. Month, day, hour, minute and " +
                            "second must be zero-filled to 2 integers. For example:\n\n \"2013-07-06 17:42:30\""
                            );
        }
Beispiel #22
0
        public void PhpGetExercisesListWithTeachMePHPMessageTest()
        {
            CreatePHPBot();
            string Message = "teach me php";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1, "Choose excersise from list bellow\n\n" +
                            "PHP EXCERCISES: \n" + "-------------------\n" + "Hello World\n" + "Baby Steps\n" +
                            "My First IO\n" + "Filtered LS\n" + "Concerned about Separation?\n" + "Array We Go!\n" +
                            "Exceptional Coding\n" + "Database Read\n" + "Time server\n" + "HTTP JSON API\n" +
                            "Dependency Heaven\n"
                            );
        }
Beispiel #23
0
        public void PhpGetDatabaseReadTask()
        {
            CreatePHPBot();
            string Message = "db read";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1,
                            "Write a program that receives a database connection string (DSN). Connect to the database, query it and update some data.\n\n" +
                            "Display the information of all the users in the database table users whose age is over 30. Print out each row on a new line formatted like:" +
                            "\n\nUser: Jim Morrison Age: 27 Sex: male\n\n" +
                            "Finally you will be given a random name as the second argument to your program, you should update the row in the users table " +
                            "which corresponds to this name. You should change the name to David Attenborough"
                            );
        }
Beispiel #24
0
        public void PhpGetExercisesListTest()
        {
            CreatePHPBot();
            string Message = "show excersices";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1, "PHP EXCERCISES: \n" + "-------------------\n" + "Hello World\n" + "Baby Steps\n" +
                            "My First IO\n" + "Filtered LS\n" + "Concerned about Separation?\n" + "Array We Go!\n" +
                            "Exceptional Coding\n" + "Database Read\n" + "Time server\n" + "HTTP JSON API\n" +
                            "Dependency Heaven\n"
                            );

            Console.WriteLine(PhpChatBot.FindAnswer(session, Message).Item1);
        }
Beispiel #25
0
        public void PhpGetDependencyHeavenApiTaskHint()
        {
            CreatePHPBot();
            string Message = "dh hint";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1, "HINTS:\n" +
                            "Point your browser to https://getcomposer.org/doc/00-intro.md which will walk you through Installing Composer if you haven't already!\n\n" +
                            "Use composer init to create your composer.json file with interactive search. \n\n" +
                            "For more details look at the docs for... \n\n" +
                            "Composer - https://getcomposer.org/doc/01-basic-usage.md Klein - https://github.com/chriso/klein.php " +
                            "Stringy - https://github.com/danielstjules/Stringy \n\n Oh, and don't forget to use the Composer autoloader with: \n\n" +
                            "require_once __DIR__ . '/vendor/autoload.php';"
                            );
        }
Beispiel #26
0
        public void PhpGetMyFirstiIOTaskHint()
        {
            CreatePHPBot();
            string Message = "mfio hint";
            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1, "HINTS:\n" +
                            "To perform a filesystem operation you can use the global PHP functions.\n\n" +
                            "To read a file, you'll need to use file_get_contents('/path/to/file'). This method will return" +
                            " a string containing the complete contents of the file.\n\n" +
                            "Documentation on the file_get_contents function can be found by pointing your browser " +
                            "here: http://php.net/manual/en/function.file-get-contents.php \n\n" +
                            "If you're looking for an easy way to count the number of newlines in a string, recall the PHP " +
                            "function substr_count can be used to count the number of substring occurrences."
                            );
        }
Beispiel #27
0
        public void PhpGetFilterLSTask()
        {
            CreatePHPBot();
            string Message = "fls task";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1,
                            "Create a program that prints a list of files in a given directory, filtered by the extension of the files. " +
                            "You will be provided a directory name as the first argument to your program (e.g. '/path/to/dir/') and a file" +
                            " extension to filter by as the second argument.\n\n" +
                            "For example, if you get 'txt' as the second argument then you will need to filter the list to only files that end with .txt. " +
                            "Note that the second argument will not come prefixed with a '.'.\n\n" +
                            "The list of files should be printed to the console, one file per line."
                            );
        }
Beispiel #28
0
        public void PhpGetHelloWorldTaskHint()
        {
            CreatePHPBot();
            string Message = "hw hint";
            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1, "HINTS:\n" +
                            "To make a PHP program, create a new file with a .php extension and start writing PHP! " +
                            "Execute your program by running it with the php command. e.g.:\n" +
                            "\n$ php program.php\n\n" +
                            "You can write to the console from a PHP program with the following code" +
                            "\n\n<?php \n echo \"text\"\n" +
                            "\n The first line tells the PHP to interpret the code following it. It is required before any PHP code is written." +
                            "Read more here: http://php.net/manual/en/language.basic-syntax.phptags.php The second line is the instruction to print out some text."
                            );
        }
Beispiel #29
0
        public void PhpGetBabyStepsTaskHint()
        {
            CreatePHPBot();
            string Message = "bs hint";
            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1, "HINTS:\n" +
                            "You can access command-line arguments via the global $argv array.\n" +
                            "To get started, write a program that simply contains:\n" +
                            "\nvar_dump($argv);\n\n" +
                            "Run it with php program.php and some numbers as arguments. e.g:\n\n" +
                            "$ php program.php 1 2 3\n\n" +
                            "You'll need to think about how to loop through the number of arguments so you can output just their sum. " +
                            "The first element of the $argv array is always the name of your script. eg program.php, " +
                            "so you need to start at the 2nd element (index 1), adding each item to the total until you reach the end of the array."
                            );
        }
Beispiel #30
0
        public void PhpGetHttpJsonApiTask()
        {
            CreatePHPBot();
            string Message = "http json api";

            ChatSessionInterface session = new RestChatSession();

            Assert.AreEqual(PhpChatBot.FindAnswer(session, Message).Item1,
                            "Write an HTTP server that serves JSON data when it receives a GET request to the path '/api/parsetime'. " +
                            "Expect the request to contain a query string with a key 'iso' and an ISO-format time as the value.\n\n" +
                            "For example:\n\n /api/parsetime?iso=2015-11-15T20:18:04+0000 \n\n The JSON response should contain only 'hour', " +
                            "'minute' and 'second' properties. For example:\n\n" +
                            "{\n \"hour\": 14, \n \"minute\": 23, \n \"second\": 15 \n } \n\n" +
                            "Add a second endpoint for the path '/api/unixtime' which accepts the same query string but returns UNIX epoch time in milliseconds " +
                            "(the number of milliseconds since 1 Jan 1970 00:00:00 UTC) under the property 'unixtime'. \n\n For example: \n\n" +
                            "{ \"unixtime\": 1376136615474 }"
                            );
        }