Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var validInput = false;

            while (!validInput)
            {
                var searchCriteria = new SearchCriteria();

                Console.WriteLine("Please enter the keyword to search");
                searchCriteria.KeyWord = Console.ReadLine();

                Console.WriteLine("Please enter the URL to search");
                searchCriteria.InputURL = Console.ReadLine();

                if (searchCriteria.HasError)
                {
                    Console.Clear();
                    var errors = string.Join(Environment.NewLine, searchCriteria.ErrorMessages);
                    Console.WriteLine(errors + Environment.NewLine);
                }
                else
                {
                    validInput = true;
                }
                var downloadedHTML = HTMLDownloader.GetHTML(new Configuration(), searchCriteria.KeyWord);
                var(isURLRanked, urlPositionList) = HTMLParser.FindPosition(downloadedHTML, searchCriteria.InputURL);
                var result = isURLRanked ?
                             $"Found {urlPositionList.Count} occurances for {searchCriteria.InputURL} at positions: {string.Join(", ", urlPositionList)}" :
                             $"Found no occurances for {searchCriteria.InputURL}";
                Console.WriteLine(result);
                Console.ReadLine();
            }
        }
Exemplo n.º 2
0
        public void TestGetHTML_EmptySearchKeyword()
        {
            var searchKeyword = string.Empty;
            var result        = HTMLDownloader.GetHTML(new TestConfiguration(), searchKeyword);

            Assert.IsTrue(string.IsNullOrEmpty(result));
        }
Exemplo n.º 3
0
        public void TestGetHTML_ValidInput()
        {
            var searchKeyword = "software";
            var result        = HTMLDownloader.GetHTML(new TestConfiguration(), searchKeyword);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Length > 0);
        }
        private void Initialize()
        {
            ipAddress = DEFAULT_IP_ADDRESS;
            port      = DEFAULT_PORT;
            // Default location for the window
            Size screenSize = Screen.GetBounds(this).Size;

            this.Location = new Point(screenSize.Width - this.Width, screenSize.Height - this.Height);
            mainTabControl.SelectedTab = inputTabPage;

            //init HTML downloaders
            searchDownloader = new HTMLDownloader();
            searchDownloader.RunRepeatedly       = false;
            portfolioDownloader                  = new HTMLDownloader();
            portfolioDownloader.RunRepeatedly    = true;
            portfolioDownloader.DownloadInterval = 20000000;


            //init event handlers for fetching data
            searchDownloader.NewDataAvailable    += new EventHandler(HandleSearchResponseReceived);
            searchDownloader.Error               += new EventHandler <ErrorEventArgs>(HandleErrorSearchResponse);
            portfolioDownloader.NewDataAvailable += new EventHandler(HandlePortfolioResponseReceived);
        }
Exemplo n.º 5
0
        public void TestGetHTML_TestWithInvalidConfiguration()
        {
            var searchKeyword = "software";

            HTMLDownloader.GetHTML(new DummyConfiguration(), searchKeyword);
        }