public void CreateQuery_argumentsTextOnly_nameSearch()
 {
     var expected = new PhoneBookQuery() {
         SearchType = PhoneBookSearcher.Library.Enums.SearchType.Name,
         StringToSearch = "bla bla bla"
     };
     var args = new string[] { "bla", "bla", "bla" };
     var handler = new ConsolePhoneBookArgumentsHandler( args );
     var actual = handler.CreateQuery();
     Assert.AreEqual( expected.SearchType, actual.SearchType, "Search type" );
     Assert.AreEqual( expected.StringToSearch, actual.StringToSearch, "String to search" );
 }
 public void CreateQuery_argumentsSwitchDSetAndNoText_departmentSearch_stringToSearchEmpty()
 {
     var expected = new PhoneBookQuery() {
         SearchType = PhoneBookSearcher.Library.Enums.SearchType.Department,
         StringToSearch = string.Empty
     };
     var args = new string[] { "-d" };
     var handler = new ConsolePhoneBookArgumentsHandler( args );
     var actual = handler.CreateQuery();
     Assert.AreEqual( expected.SearchType, actual.SearchType, "Search type" );
     Assert.AreEqual( expected.StringToSearch, actual.StringToSearch, "String to search" );
 }
 public void Search_querySetSearchTypeName_returnsResults()
 {
     List<PhoneBookSearchResult> expected = new List<PhoneBookSearchResult>();
     expected.Add( new PhoneBookSearchResult() );
     var provider = new Mock<IPhoneBookSearchProvider>();
     provider.Setup( p => p.GetEntriesForQuery( It.IsAny<string>() ) ).Returns( expected );
     var search = new PhoneBookSearch( provider.Object );
     var query = new PhoneBookQuery() {
         SearchType = Library.Enums.SearchType.Name,
         StringToSearch = "test"
     };
     var results = search.Search( query );
     provider.Verify( p => p.GetEntriesForQuery( "test" ), Times.Once() );
     Assert.AreEqual( expected.Count, results.Count );
 }
 /// <summary>
 /// Performs search using provider passed with constructor and PhoneBookQuery object
 /// </summary>
 /// <param name="query">PhoneBookQuery object which contains query(ies) to execute</param>
 /// <returns></returns>
 public List<PhoneBookSearchResult> Search( PhoneBookQuery query )
 {
     if (null == query)
         throw new ArgumentNullException( "Query" );
     return this.Provider.GetEntriesForQuery( query.StringToSearch );
 }
 private List<PhoneBookSearchResult> TriggerSearchForType( Library.Enums.SearchType type )
 {
     var query = new PhoneBookQuery() {
         SearchType = type,
         StringToSearch = tbSearch.Text
     };
     switch (type) {
         case Library.Enums.SearchType.Department:
             m_searcher = new PhoneBookSearch( new DepartmentADPhoneBookSearchProvider( m_config ) );
             break;
         case Library.Enums.SearchType.PhoneNumber:
             m_searcher = new PhoneBookSearch( new PhoneNumberADPhoneBookSearchProvider( m_config ) );
             break;
         case Library.Enums.SearchType.Name:
         default:
             m_searcher = new PhoneBookSearch( new NameADPhoneBookSearchProvider( m_config ) );
             break;
     }
     return m_searcher.Search( query );
 }