Exemplo n.º 1
0
        public void TestSearch()
        {
            MountainProjectDataSearch.InitMountainProjectData(@"..\..\MountainProjectDBBuilder\bin\MountainProjectAreas.xml");

            for (int i = 0; i < testCriteria_search.GetLength(0); i++)
            {
                string   query       = testCriteria_search[i, 0];
                string   expectedUrl = testCriteria_search[i, 1];
                MPObject result      = MountainProjectDataSearch.SearchMountainProject(query);

                Assert.AreEqual(Utilities.MPBASEURL + expectedUrl, result.URL);
            }
        }
Exemplo n.º 2
0
        private static void ParseInputString()
        {
            MountainProjectDataSearch.InitMountainProjectData(serializationPath);
            if (MountainProjectDataSearch.DestAreas.Count() == 0)
            {
                Console.WriteLine("The xml either doesn't exist or is empty");
                Environment.Exit(0);
            }

            Console.WriteLine("File read.");

            bool keepSearching = true;

            while (keepSearching)
            {
                Console.WriteLine("\n\nPlease input the string you would like to parse: ");
                string input = Console.ReadLine();

                Stopwatch stopwatch = Stopwatch.StartNew();
                MPObject  result    = MountainProjectDataSearch.SearchMountainProject(input);
                stopwatch.Stop();

                if (result == null)
                {
                    Console.WriteLine("Nothing found matching \"" + input + "\"");
                }
                else
                {
                    string resultStr = "";
                    if (result is Area)
                    {
                        resultStr = (result as Area).ToString();
                    }
                    else if (result is Route)
                    {
                        resultStr = (result as Route).ToString();
                    }

                    Console.WriteLine("The following was found: " + resultStr + " (Found in " + stopwatch.ElapsedMilliseconds + " ms)");
                    Console.WriteLine($"Parent: {MountainProjectDataSearch.GetParent(result, -1).Name}");
                    Console.WriteLine("\nOpen result? (y/n) ");
                    if (Console.ReadKey().Key == ConsoleKey.Y)
                    {
                        Process.Start(result.URL);
                    }
                }

                Console.WriteLine("\nSearch something else? (y/n) ");
                keepSearching = Console.ReadKey().Key == ConsoleKey.Y;
            }
        }
Exemplo n.º 3
0
        public static string GetReplyForCommentBody(string commentBody)
        {
            string queryText = commentBody.Split(new string[] { BOTKEYWORD }, StringSplitOptions.None)[1].Trim();

            MPObject searchResult = MountainProjectDataSearch.SearchMountainProject(queryText);
            string   replyText    = GetFormattedString(searchResult);

            if (string.IsNullOrEmpty(replyText))
            {
                replyText = $"I could not find anything for \"{queryText}\". Please use the Feedback button below if you think this is a bug";
            }

            return(replyText);
        }
Exemplo n.º 4
0
        public void TestLocationString()
        {
            MountainProjectDataSearch.InitMountainProjectData(@"..\..\MountainProjectDBBuilder\bin\MountainProjectAreas.xml");

            for (int i = 0; i < testCriteria_location.GetLength(0); i++)
            {
                string query            = testCriteria_location[i, 0];
                string expectedLocation = testCriteria_location[i, 1];
                string resultLocation   = BotReply.GetLocationString(MountainProjectDataSearch.SearchMountainProject(query));
                resultLocation = resultLocation.Replace("\n\n", "");        //Remove markdown newline
                resultLocation = resultLocation.Replace("Located in ", ""); //Simplify results for unit test

                Assert.AreEqual(expectedLocation, resultLocation);
            }
        }