public void Constructor_argumentsSet_argumentsSet()
 {
     var expected = new string[] { "bla" };
     var handler = new ConsolePhoneBookArgumentsHandler( expected );
     Assert.IsNotNull( handler.Arguments );
     Assert.AreEqual( expected, handler.Arguments );
 }
 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" );
 }
コード例 #4
0
 static void Main( string[] args )
 {
     PhoneBookQuery query = null;
     try {
         var handlerArgs = new ConsolePhoneBookArgumentsHandler( args );
         query = handlerArgs.CreateQuery();
     }
     catch (Exception ex) {
         System.Console.WriteLine( "Error:\n{0}", ex.Message );
         PrintUsage();
         Environment.Exit( 0 );
     }
     if (string.IsNullOrWhiteSpace( query.StringToSearch )) {
         PrintUsage();
         Environment.Exit( 0 );
     }
     var config = new ADConfiguration() {
         RootEntryUri = new Uri( Settings.Default.AdDirectoryEntry )
     };
     var searcher = GenerateSearcherForQueryType(config, query.SearchType );
     var results = searcher.Search( query );
     PrintResultsForSearchType( results, query.SearchType );
 }
 public void CreateQuery_argumentsInvalidSwitch_throwsOperationCanceledException()
 {
     var args = new string[] { "-", "bla", "bla", "bla" };
     var handler = new ConsolePhoneBookArgumentsHandler( args );
     var actual = handler.CreateQuery();
 }
 public void Constructor_argumentsNull_throwArgumentNullException()
 {
     var handler = new ConsolePhoneBookArgumentsHandler( null );
 }
 public void Constructor_argumentsEmpty_throwArgumentNullException()
 {
     var handler = new ConsolePhoneBookArgumentsHandler( new string[] { } );
 }