public void Constructor_IsCalledWithArguments_ShouldReturnNewInstance() { //act arrange var search = new DocumentSearchEngine(_fileData, new DocumentSearchCriteria() { Keywords = new List<string>(1) { "Test" }, Operator = BooleanOperator.Or }); //assert Assert.IsNotNull(search); }
public void ExecuteSearch_CareQualityCommissionadmission_BooleanOperatorAnd_ShouldReturnItem1() { //arrange var expectedSearchResultIndexValues = new List<int> { 1 }; var searchEngine = new DocumentSearchEngine( _fileData, new DocumentSearchCriteria { Keywords = new List<string>(4) { "Care", "Quality", "Commission", "admission" }, Operator = BooleanOperator.And }); //act var searchResults = searchEngine.ExecuteSearch(); //assert MakeAssertions(searchResults, expectedSearchResultIndexValues, 1); }
public void ExecuteSearch_CareCommissioningAdmission_BooleanOperatorOr_ShouldReturnItems_0_1_2_3_4_5_6() { //arrange var expectedSearchResultIndexValues = new List<int> { 0, 1, 2, 3, 4, 5, 6 }; var searchEngine = new DocumentSearchEngine( _fileData, new DocumentSearchCriteria { Keywords = new List<string>(3) { "Care", "Quality", "Commission" }, Operator = BooleanOperator.Or }); //act var searchResults = searchEngine.ExecuteSearch(); //assert MakeAssertions(searchResults, expectedSearchResultIndexValues, 7); }
public void ExecuteSearch_generalpopulationAlzheimer_BooleanOperatorAnd_ShouldReturnItem6() { //arrange var expectedSearchResultIndexValues = new List<int> { 6 }; var searchEngine = new DocumentSearchEngine( _fileData, new DocumentSearchCriteria { Keywords = new List<string>(3) { "general", "population", "Alzheimer" }, Operator = BooleanOperator.And }); //act var searchResults = searchEngine.ExecuteSearch(); //assert MakeAssertions(searchResults, expectedSearchResultIndexValues, 1); }
public void Constructor_IsCalledWithNullArguments_ShouldThrowException() { var search = new DocumentSearchEngine(null, null); }
public void ExecuteSearch_September2004_BooleanOperatorOr_ShouldReturnItem9() { //arrange var expectedSearchResultIndexValues = new List<int> { 9 }; var searchEngine = new DocumentSearchEngine( _fileData, new DocumentSearchCriteria { Keywords = new List<string>(2) { "September", "2004"}, Operator = BooleanOperator.Or }); //act var searchResults = searchEngine.ExecuteSearch(); //assert MakeAssertions(searchResults, expectedSearchResultIndexValues, 1); }
/// <summary> /// Runs the search application which allows a user to search by keywords from a text file for any relevant entries. /// </summary> private static void Run() { try { var dataRecords = File.ReadLines("hscic-news.txt"); while (true) { Console.WriteLine( "Please type the words you would like to search for (separated by a space) and press Enter."); var userInput = Console.ReadLine(); var keywordsParseResult = DocumentSearchCriteriaHelper.TryParseKeywords(userInput); if (keywordsParseResult == null) { WriteErrorMessageToConsole( "Input validation failed. Please enter the keywords you would like to search for again e.g. Care Summary"); continue; } BooleanOperator? searchOperator; do { Console.WriteLine( "Please enter 1 to search using the 'AND' search type or enter 2 to search using the 'OR' search type."); userInput = Console.ReadLine(); searchOperator = DocumentSearchCriteriaHelper.TryParseBooleanOperator(userInput); if (searchOperator == null) WriteErrorMessageToConsole("Input validation failed. Unrecognised search type."); } while (searchOperator == null); var searchCriteria = new DocumentSearchCriteria { Keywords = new List<string>(keywordsParseResult), Operator = searchOperator.Value }; var searchResults = new DocumentSearchEngine(dataRecords, searchCriteria).ExecuteSearch(); DisplaySearchResults(searchResults); Console.WriteLine("Type 'E' to exit or 'Enter' to continue"); var readLine = Console.ReadLine(); if (readLine != null && readLine.Equals("e", StringComparison.InvariantCultureIgnoreCase)) break; } } catch (FileNotFoundException ex) { Logger.Log(ex.Message); WriteErrorMessageToConsole( "File not found. Please make sure that the 'hscic-news.txt' is in the same directory as the application."); Console.ReadLine(); } catch (Exception ex) { Logger.Log(ex.Message); WriteErrorMessageToConsole("An error has occured please refer to the log file for more information."); Console.ReadLine(); } }