static void Main()
        {
            StringCollection strcoll = new StringCollection();

            strcoll.Add("This");
            strcoll.Add("is");
            strcoll.Add("string");
            strcoll.Add("collection");
            strcoll.Add("demo");

            Console.WriteLine("String Collection");
            foreach (var item in strcoll)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("count of string collection");
            int x = strcoll.Count;

            Console.WriteLine(x);

            Console.WriteLine("****copy to array****");
            string[] str1 = new string[strcoll.Count];
            strcoll.CopyTo(str1, 0);
            foreach (var item1 in str1)
            {
                Console.WriteLine(item1);
            }

            Console.WriteLine("***Add range method***");
            string[] str2 = new string[] { "All", "the", "best" };
            strcoll.AddRange(str2);
            foreach (var item2 in strcoll)
            {
                Console.WriteLine(item2);
            }

            Console.WriteLine("contains method");
            bool x1 = strcoll.Contains("collection");

            Console.WriteLine(x1);

            strcoll.Insert(5, "dear");
            foreach (var item3 in strcoll)
            {
                Console.WriteLine(item3);
            }


            bool b = strcoll.Equals("dear");

            Console.WriteLine("equals 'dear':{0}", b);


            Type t = strcoll.GetType();

            Console.WriteLine(t);

            Console.WriteLine("remove element at index 1");
            strcoll.RemoveAt(1);
            foreach (var item4 in strcoll)
            {
                Console.WriteLine(item4);
            }
        }
 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     StringCollection sc; 
     try
     {
         Console.WriteLine("--- default ctor ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sc = new StringCollection();
         Console.WriteLine("1. compare to null");
         iCountTestcases++;
         if (sc == null) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0001, collection is null after default ctor");
         } 
         Console.WriteLine("2. check Count");
         iCountTestcases++;
         if (sc.Count != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002, Count = {0} after default ctor", sc.Count);
         }
         Console.WriteLine("3. check Contains()");
         iCountTestcases++;
         if (sc.Contains("string")) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003, Contains() returned true after default ctor");
         }
         Console.WriteLine("4. check ToString()");
         iCountTestcases++;
         string temp = sc.ToString();
         Console.WriteLine(" ToString(): " + temp);
         if (temp.IndexOf("StringCollection") == -1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004, ToString() doesn't contain \"StringCollection\"");
         }
         Console.WriteLine("5. check returned Type");
         iCountTestcases++;
         temp = sc.GetType().ToString().Trim();
         Console.WriteLine(" GetType(): " + temp);
         if (temp.IndexOf("StringCollection") == -1) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0005: returned type doesn't contain \"StringCollection\"");
         }
         Console.WriteLine("6. compare returned Type of two collection");
         iCountTestcases++;
         string temp1 = (new StringCollection()).GetType().ToString().Trim();
         if (String.Compare(temp, temp1) != 0) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0006: returned types of two collections differ");
         }
         Console.WriteLine("7. check IsReadOnly");
         iCountTestcases++;
         Console.WriteLine(" IsReadOnly: " + sc.IsReadOnly);
         if (sc.IsReadOnly) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0007: IsReadOnly returned {0}", sc.IsReadOnly);
         }
         Console.WriteLine("8. check IsSynchronized");
         iCountTestcases++;
         Console.WriteLine(" IsSynchronized: " + sc.IsSynchronized);
         if (sc.IsSynchronized) 
         {  
             iCountErrors++;
             Console.WriteLine("Err_0008: IsSynchronized returned {0}", sc.IsSynchronized);
         }
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_general!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "Pass.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("Fail!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
Esempio n. 3
0
    public virtual bool runTest()
    {
        Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
        int              iCountErrors    = 0;
        int              iCountTestcases = 0;
        String           strLoc          = "Loc_000oo";
        StringCollection sc;

        try
        {
            Console.WriteLine("--- default ctor ---");
            strLoc = "Loc_001oo";
            iCountTestcases++;
            sc = new StringCollection();
            Console.WriteLine("1. compare to null");
            iCountTestcases++;
            if (sc == null)
            {
                iCountErrors++;
                Console.WriteLine("Err_0001, collection is null after default ctor");
            }
            Console.WriteLine("2. check Count");
            iCountTestcases++;
            if (sc.Count != 0)
            {
                iCountErrors++;
                Console.WriteLine("Err_0002, Count = {0} after default ctor", sc.Count);
            }
            Console.WriteLine("3. check Contains()");
            iCountTestcases++;
            if (sc.Contains("string"))
            {
                iCountErrors++;
                Console.WriteLine("Err_0003, Contains() returned true after default ctor");
            }
            Console.WriteLine("4. check ToString()");
            iCountTestcases++;
            string temp = sc.ToString();
            Console.WriteLine(" ToString(): " + temp);
            if (temp.IndexOf("StringCollection") == -1)
            {
                iCountErrors++;
                Console.WriteLine("Err_0004, ToString() doesn't contain \"StringCollection\"");
            }
            Console.WriteLine("5. check returned Type");
            iCountTestcases++;
            temp = sc.GetType().ToString().Trim();
            Console.WriteLine(" GetType(): " + temp);
            if (temp.IndexOf("StringCollection") == -1)
            {
                iCountErrors++;
                Console.WriteLine("Err_0005: returned type doesn't contain \"StringCollection\"");
            }
            Console.WriteLine("6. compare returned Type of two collection");
            iCountTestcases++;
            string temp1 = (new StringCollection()).GetType().ToString().Trim();
            if (String.Compare(temp, temp1) != 0)
            {
                iCountErrors++;
                Console.WriteLine("Err_0006: returned types of two collections differ");
            }
            Console.WriteLine("7. check IsReadOnly");
            iCountTestcases++;
            Console.WriteLine(" IsReadOnly: " + sc.IsReadOnly);
            if (sc.IsReadOnly)
            {
                iCountErrors++;
                Console.WriteLine("Err_0007: IsReadOnly returned {0}", sc.IsReadOnly);
            }
            Console.WriteLine("8. check IsSynchronized");
            iCountTestcases++;
            Console.WriteLine(" IsSynchronized: " + sc.IsSynchronized);
            if (sc.IsSynchronized)
            {
                iCountErrors++;
                Console.WriteLine("Err_0008: IsSynchronized returned {0}", sc.IsSynchronized);
            }
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            Console.WriteLine(s_strTFAbbrev + " : Error Err_general!  strLoc==" + strLoc + ", exc_general==\n" + exc_general.ToString());
        }
        if (iCountErrors == 0)
        {
            Console.WriteLine("Pass.   " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases);
            return(true);
        }
        else
        {
            Console.WriteLine("Fail!   " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums);
            return(false);
        }
    }