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(); } }
public void TestGetHTML_EmptySearchKeyword() { var searchKeyword = string.Empty; var result = HTMLDownloader.GetHTML(new TestConfiguration(), searchKeyword); Assert.IsTrue(string.IsNullOrEmpty(result)); }
public void TestGetHTML_ValidInput() { var searchKeyword = "software"; var result = HTMLDownloader.GetHTML(new TestConfiguration(), searchKeyword); Assert.IsNotNull(result); Assert.IsTrue(result.Length > 0); }
public void TestGetHTML_TestWithInvalidConfiguration() { var searchKeyword = "software"; HTMLDownloader.GetHTML(new DummyConfiguration(), searchKeyword); }