Example #1
0
        public void LoadList()
        {
            ReflectionHelper.CallMethod(typeof(MruProjects), "LoadList", new object[] { null });
            Assert.AreEqual(0, _paths.Count);

            // Load some non existant paths into our collection of paths.

            var prjFile = Path.Combine(Path.GetTempPath(), "~frog");

            prjFile = Path.Combine(prjFile, "~frog.sprj");
            _prjFiles.Insert(0, prjFile);

            prjFile = Path.Combine(Path.GetTempPath(), "~lizard");
            prjFile = Path.Combine(prjFile, "~lizard.sprj");
            _prjFiles.Insert(0, prjFile);

            prjFile = Path.Combine(Path.GetTempPath(), "~toad");
            prjFile = Path.Combine(prjFile, "~toad.sprj");
            _prjFiles.Insert(0, prjFile);

            Assert.IsTrue(_prjFiles.Count > MruProjects.MaxMRUListSize);
            ReflectionHelper.CallMethod(typeof(MruProjects), "LoadList", _prjFiles);
            Assert.AreEqual(MruProjects.MaxMRUListSize, _paths.Count);

            // Make sure only the first MaxMRUListSize valid paths in our collection were loaded.
            for (int i = 0; i < MruProjects.MaxMRUListSize; i++)
            {
                Assert.AreEqual(_prjFiles[i + 3], _paths[i]);
            }
        }
Example #2
0
        public static void Insert_ArgumentInvalidTest(StringCollection collection, string[] data)
        {
            Assert.Throws <ArgumentOutOfRangeException>(() => collection.Insert(-1, ElementNotPresent));
            Assert.Throws <ArgumentOutOfRangeException>(() => collection.Insert(data.Length + 1, ElementNotPresent));

            // And as explicit interface implementation
            Assert.Throws <ArgumentOutOfRangeException>(() => ((IList)collection).Insert(-1, ElementNotPresent));
            Assert.Throws <ArgumentOutOfRangeException>(() => ((IList)collection).Insert(data.Length + 1, ElementNotPresent));
        }
Example #3
0
        public void Insert()
        {
            StringCollection list = BuildList();

            list.Insert(1, "QUACK");
            Assert.AreEqual("ABC,QUACK,DEF,GHI", list.ToString(","));
        }
Example #4
0
        private void AddCard(object sender, RoutedEventArgs args)
        {
            Button b     = sender as Button;
            int    index = _randomizer.Next(_dataSource.Count);

            if (b.Name == "_regular")
            {
                _dataSource.Insert(index, "Images/01.jpg");
            }
            else
            {
                _dataSource.Insert(index, string.Format("Images/{0:00}", _randomizer.Next(1, 12)) + ".jpg");
            }
            // Update selectedindex slider
            _selectedIndexSlider.Maximum = _elementFlow.Items.Count - 1;
        }
Example #5
0
        private void button_moveLanguageDown_Click(object sender, EventArgs e)
        {
            int ilevel = 0;

            if (listBox_selectedLanguages.SelectedItems.Count > 0)
            {
                ListBox.SelectedIndexCollection selectedItems = listBox_selectedLanguages.SelectedIndices;
                int[] index_selectedItems = new int[selectedItems.Count];

                for (int i = 0; i < selectedItems.Count; i++)
                {
                    index_selectedItems[i] = selectedItems[i];
                }

                for (int i = index_selectedItems.Length - 1; i >= 0; i--)
                {
                    ilevel = index_selectedItems[i];

                    if ((ilevel + 1 >= 0) && (ilevel + 1 <= listBox_selectedLanguages.Items.Count - (index_selectedItems.Length - i)))
                    {
                        String lvitem = (String)listBox_selectedLanguages.Items[ilevel];
                        listBox_selectedLanguages.Items.Remove(lvitem);
                        listBox_selectedLanguages.Items.Insert(ilevel + 1, lvitem);
                        listBox_selectedLanguages.SetSelected(ilevel + 1, true);

                        // Do the same on the Property.
                        StringCollection languages = this.userSettingService.GetUserSetting <StringCollection>(UserSettingConstants.SelectedLanguages);
                        languages.Remove(lvitem);
                        languages.Insert(ilevel + 1, lvitem);
                        this.userSettingService.SetUserSetting(UserSettingConstants.SelectedLanguages, languages);
                    }
                }
            }
        }
Example #6
0
        public override void Stop()
        {
            base.Stop();

            if (_saveRequested)
            {
                var hasChanged = false;
                if (AIMDataServiceSettings.Default.AIMDataServiceUrl != _aimDataServiceUrl)
                {
                    AIMDataServiceSettings.Default.AIMDataServiceUrl = _aimDataServiceUrl;
                    hasChanged = true;
                    if (!string.IsNullOrEmpty(_aimDataServiceUrl) && !CollectionUtils.Contains(_aimDataServiceUrlList, p => (string)p == _aimDataServiceUrl))
                    {
                        _aimDataServiceUrlList.Insert(0, _aimDataServiceUrl);
                    }
                }

                if (!hasChanged && !IsEqual(AIMDataServiceSettings.Default.AIMDataServiceUrlList, _aimDataServiceUrlList))
                {
                    hasChanged = true;
                }

                if (hasChanged)
                {
                    AIMDataServiceSettings.Default.AIMDataServiceUrlList = _aimDataServiceUrlList;
                    AIMDataServiceSettings.Default.Save();
                }
            }
        }
Example #7
0
        static void Main(string[] args)
        {
            StringCollection str = new StringCollection();

            str.Add("Bringal");
            str.Add("Bottle_Gaurd");
            str.Add("Cauliflower");
            str.Add("Cabbage");
            str.Add("Okra");

            Console.WriteLine("The Elements of the StringCollection is---------");

            foreach (var item in str)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("Copying the above StringCollection list to string array--------------");
            string[] str1 = new string[str.Count];
            str.CopyTo(str1, 0);

            Console.WriteLine("Printing the copied list into the array");
            foreach (var i in str)
            {
                Console.WriteLine(i);
            }

            Console.WriteLine("Checking weather Tomato element is present in the StringCollection:{0}",
                              str.Contains("Tomato"));


            Console.WriteLine("Checking the index of the element : {0} ", str.IndexOf("Cauliflower"));

            str.Insert(4, "Tomato");

            Console.WriteLine("Printing the list after inserting the new value");
            foreach (var item1 in str)
            {
                Console.WriteLine(item1);
            }

            str.Remove("Bringal");
            Console.WriteLine("List of the elements after removing----------");

            foreach (var item2 in str)
            {
                Console.WriteLine(item2);
            }

            Console.WriteLine("Removing element from the index value--------");
            str.RemoveAt(3);

            Console.WriteLine("Elements list after removing values from index 3");
            foreach (var item3 in str)
            {
                Console.WriteLine(item3);
            }

            Console.Read();
        }
Example #8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds the specified file path to top of list of most recently used files if it
        /// exists (returns false if it doesn't exist)
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static bool AddNewPath(string path, bool addToEnd)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            if (!File.Exists(path))
            {
                return(false);
            }

            // Remove the path from the list if it exists already.
            s_paths.Remove(path);

            // Make sure inserting a new path at the beginning will not exceed our max.
            if (s_paths.Count >= MaxMRUListSize)
            {
                s_paths.RemoveAt(s_paths.Count - 1);
            }

            if (addToEnd)
            {
                s_paths.Add(path);
            }
            else
            {
                s_paths.Insert(0, path);
            }

            return(true);
        }
Example #9
0
        public void AddToHistory(string data, int positiondiff)
        {
            /*
             * // BUG: this code doesnt work well
             * // _History.Count-1 is the last entry, which should be always empty
             * if ((_History.Count > 1) &&
             *  (data == _History[_History.Count-2])) {
             *  // don't add the same value
             *  return;
             * }
             */

            _History.Insert(_History.Count - 1, data);
#if LOG4NET
            _Logger.Debug("added: '" + data + "' to history");
#endif

            if (_History.Count > Settings.CommandHistorySize)
            {
                _History.RemoveAt(0);
            }
            else
            {
                _HistoryPosition += positiondiff;
            }
        }
Example #10
0
        public void AddFile(string strFilename)
        {
            // Does the file already exist in the list?
            int nIndex = 0;
            int nFound = -1;

            foreach (string s in m_files)
            {
                if (s == strFilename)
                {
                    nFound = nIndex;
                }
                nIndex++;
            }
            if (nFound != -1)
            {
                m_files.RemoveAt(nFound);
            }

            // Add file to top of list.
            m_files.Insert(0, strFilename);

            // Remove files from bottom if we have too many.
            if (m_files.Count > MaxRecentFiles)
            {
                m_files.RemoveAt(MaxRecentFiles);
            }

            BuildRecentMenu();

            Properties.Settings.Default.RecentFiles = m_files;
            Properties.Settings.Default.Save();
        }
Example #11
0
 private static void AddFileDropListToClipboard(string driveKey, StringCollection fileDropList, bool cut)
 {
     if (cut || fileDropList[0].StartsWith("hdfs://"))
     {
         if (cut)
         {
             fileDropList.Insert(0, MoveModeToken);
         }
         fileDropList.Insert(0, driveKey);
         Clipboard.SetData(ClipboardDataType, fileDropList);
     }
     else
     {
         Clipboard.SetFileDropList(fileDropList);
     }
 }
Example #12
0
 public static void InsertHeaderFieldIfNeed(StringCollection source, string name, string theValue)
 {
     if (!StringUtils.IsEmpty(theValue))
     {
         HeaderFieldList fieldList = new HeaderFieldList();
         int             index     = GetHeaderFieldList(0, source, fieldList);
         if (!fieldList.ContainsField(name))
         {
             if ((index < 0) || (index > source.Count))
             {
                 index = source.Count;
             }
             theValue = theValue.Replace("\r\n", "\r\n\t");
             if (theValue[theValue.Length - 1] == '\t')
             {
                 theValue = theValue.Substring(0, theValue.Length - 1);
             }
             foreach (string str in StringUtils.GetStringArray(string.Format("{0}: {1}", name, theValue)))
             {
                 source.Insert(index, str);
                 index++;
             }
         }
     }
 }
Example #13
0
        public void Agregar(bool A)
        {
            // Button b = sender as Button;
            int index = _randomizer.Next(_dataSource.Count);

            if (A)
            {
                _dataSource.Insert(index, "Images/01.jpg");
            }
            else
            {
                _dataSource.Insert(index, string.Format("Images/{0:00}", _randomizer.Next(1, 13)) + ".jpg");
            }
            // Update selectedindex slider
            //   _selectedIndexSlider.Maximum = _elementFlow.Items.Count - 1;
        }
Example #14
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (!dbList.Contains(this.comboBox1.Text))
     {
         dbList.Insert(0, this.comboBox1.Text);
         Properties.Settings.Default.Save();
     }
 }
Example #15
0
        /// <summary>
        ///     Adds a string to the list and positions it in the recent list
        /// </summary>
        /// <param name="text">The string that should be added</param>
        public void AddString(string text)
        {
            if (m_List.Contains(text))
            {
                m_List.Remove(text);
                m_List.Insert(0, text);
            }
            else
            {
                if (m_List.Count == m_Capacity)
                {
                    m_List.RemoveAt(m_List.Count - 1);
                }

                m_List.Insert(0, text);
            }
        }
Example #16
0
        internal static void RenameLastOpened(string filePath)
        {
            StringCollection files = GetRecentFiles();

            files.RemoveAt(0);
            files.Insert(0, filePath);
            Properties.Settings.Default.Save();
        }
        public static void AddRecentFile(StringCollection collection, string fileName)
        {
            if (collection.Contains(fileName))
            {
                collection.Remove(fileName);
            }

            collection.Insert(0, fileName);
        }
Example #18
0
        static void Main(string[] args)
        {
            StringCollection name = new StringCollection();

            string[] text = new string[] { "hello", "and", "welcome", "to", "epam" };
            name.Add("Name-Pranshika");
            name.Add("College-Chitkara");
            name.Add("State-Punjab");
            name.Add("Degree-B.Tech");
            name.AddRange(text);
            name.Insert(3, "*text Inserted*");
            Console.WriteLine("****This is System.Collections.Specialized StringCollection ****");
            foreach (string i in name)
            {
                Console.WriteLine(i);
            }

            HybridDictionary hyb = new HybridDictionary();

            hyb.Add("name", "Pranshika");
            hyb.Add("degree", "btech");
            hyb.Add("company", "epam");
            ICollection key1 = hyb.Keys;

            Console.WriteLine("****This is System.Collections.Specialized  HybridDictionary ****");
            foreach (string i in key1)
            {
                Console.WriteLine(i);
            }

            OrderedDictionary myOrdered = new OrderedDictionary();

            myOrdered.Add("name", "Pranshika");
            myOrdered.Add("degree", "btech");
            myOrdered.Add("company", "epam");
            ICollection keyCollection   = myOrdered.Keys;
            ICollection valueCollection = myOrdered.Values;

            Console.WriteLine("****This is System.Collections.Specialized  OrderedDictionary ****");
            foreach (string i in keyCollection)
            {
                Console.WriteLine(i);
            }

            NameValueCollection namevalue = new NameValueCollection();

            namevalue.Add("name", "Pranshika");
            namevalue.Add("degree", "btech");
            namevalue.Add("company", "epam");
            Console.WriteLine("****This is System.Collections.Specialized  NameValueCollection ****");
            foreach (string i in namevalue.AllKeys)
            {
                Console.WriteLine(i + "   " + namevalue[i]);
            }
        }
Example #19
0
        public void FixHangingBrace(String str)
        {
            int strloc = filebuffer.IndexOf(str);
            int brcloc = FindHangingBrace(strloc);
            int diff   = brcloc - strloc;

            if (brcloc > 0)
            {
                for (int i = 0; i < diff + 1; i++)
                {
                    filebuffer.RemoveAt(strloc);
                }
                filebuffer.Insert(strloc, str + " {");
                if (linespace)
                {
                    filebuffer.Insert(strloc + 1, "");
                }
            }
            else
            {
            }
        }
        private void buttonSaveToList_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxAccountName.Text))
            {
                MessageBox.Show("The account name cannot be empty.");
                return;
            }
            CredentialsEntry myCredentials = new CredentialsEntry(textBoxAccountName.Text, textBoxAccountKey.Text, textBoxBlobKey.Text, textBoxDescription.Text, radioButtonPartner.Checked.ToString(), radioButtonOther.Checked.ToString(), textBoxAPIServer.Text, textBoxScope.Text, textBoxACSBaseAddress.Text, textBoxAzureEndpoint.Text, textBoxManagementPortal.Text);

            if (CredentialsList == null)
            {
                CredentialsList = new StringCollection();
            }

            //let's find if the account name is already in the list
            int foundindex = -1;

            for (int i = 0; i < CredentialsList.Count; i += CredentialsEntry.StringsCount)
            {
                if (CredentialsList[i] == textBoxAccountName.Text)
                {
                    foundindex = i;
                    break;
                }
            }

            if (foundindex == -1) // not found
            {
                CredentialsList.AddRange(myCredentials.ToArray());
                Properties.Settings.Default.LoginList = CredentialsList;

                Program.SaveAndProtectUserConfig();

                listBoxAcounts.Items.Add(myCredentials.AccountName);
            }
            else
            {
                //found, let's update the entry et insert the new data
                for (int i = 0; i < CredentialsEntry.StringsCount; i++)
                {
                    CredentialsList.RemoveAt(foundindex);
                }
                for (int i = 0; i < CredentialsEntry.StringsCount; i++)
                {
                    CredentialsList.Insert(foundindex + i, myCredentials.ToArray().Skip(i).Take(1).FirstOrDefault());
                }
                Properties.Settings.Default.LoginList = CredentialsList;
                Program.SaveAndProtectUserConfig();
            }
        }
Example #21
0
        private void SetStatusToolTip(string text)
        {
            if (!DesignMode)
            {
                _toolTipList.Insert(0, "(" + DateTime.Now.ToLongTimeString() + ") " + text);
                if (_toolTipList.Count > _maximumToolTipLines)
                {
                    _toolTipList.RemoveAt(_maximumToolTipLines);
                }

                string[] toolTipArray = new string[_maximumToolTipLines];
                _toolTipList.CopyTo(toolTipArray, 0);
                _status.ToolTipText = string.Join("\n", toolTipArray).TrimEnd();
            }
        }
Example #22
0
        /// <summary>
        /// add new value of combobox to the user defaults, or move existing value to the front;
        /// limits the number of values to MAX_COMBOBOX_HISTORY
        /// </summary>
        /// <param name="Sender"></param>
        /// <param name="e"></param>
        public void AddComboBoxHistory(System.Object Sender, TAcceptNewEntryEventArgs e)
        {
            string           keyName = "CmbHistory" + ((Control)Sender).Name;
            StringCollection values  = StringHelper.StrSplit(TUserDefaults.GetStringDefault(keyName, ""), ",");

            values.Remove(e.ItemString);
            values.Insert(0, e.ItemString);

            while (values.Count > MAX_COMBOBOX_HISTORY)
            {
                values.RemoveAt(values.Count - 1);
            }

            TUserDefaults.SetDefault(keyName, StringHelper.StrMerge(values, ','));
        }
Example #23
0
        /// <summary>
        /// store information about the  recent  opened file
        /// </summary>
        /// <param name="fileDirector">file Directory</param>
        public static void AddRecentFile(string fileDirector)
        {
            StringCollection files = GetRecentFiles();

            if (files.Contains(fileDirector))
            {
                files.Remove(fileDirector);
            }
            files.Insert(0, fileDirector);
            if (files.Count > MAX_FILE)
            {
                files.RemoveAt(files.Count - 1);
            }
            Properties.Settings.Default.Save();
        }
Example #24
0
        private void save_Click(object sender, EventArgs e)
        {
            if (!dbList.Contains(this.comboBox1.Text))
            {
                string val = comboBox1.Text;
                if (this.comboBox1.SelectedItem != null)
                {
                    val = comboBox1.Text;
                }
                dbList.Insert(0, val);
                Properties.Settings.Default.Save();
            }

            credentials.Save(comboBox1.Text.Trim(), textBoxPassword.Text);
        }
        public static void StoreFilename(string filename)
        {
            RemoveFilename(filename);

            StringCollection filenames = Filenames;

            filenames.Insert(0, filename);

            while (filenames.Count > MaxFilenameCount)
            {
                filenames.RemoveAt(filenames.Count - 1);
            }

            Properties.Settings.Default.Save();
        }
Example #26
0
        /// <summary>
        /// This method is used to replace friends in friends list.
        /// </summary>
        public void ReplaceFriend()
        {
            Console.WriteLine("\nEnter name of the friend to be replaced:");

            string nameOfFriend = Console.ReadLine();
            int    position     = friend.IndexOf(nameOfFriend);

            friend.Remove(nameOfFriend);

            Console.WriteLine("\nEnter name of the new friend to be added:");
            string newFriend = Console.ReadLine();

            friend.Insert(position, newFriend);

            AccountSettings();
        }
Example #27
0
        private void AddItem(string item, string displayName)
        {
            Debug.Assert(item != null && displayName != null, "item != null && displayName != null");
            Debug.Assert(m_items.Count == m_displayNames.Count, "m_items.Count == m_displayNames.Count");

            if (m_items.Count == 0)
            {
                m_menu.MenuItems.Add(m_firstItemIndex, new MenuItem("-"));                 // Add a separator
            }

            MenuItem newItem = new MenuItem("&1 " + displayName, new EventHandler(item_Click));

            m_menu.MenuItems.Add(m_firstItemIndex + 1, newItem);

            m_items.Insert(0, item);
            m_displayNames.Insert(0, displayName);
        }
Example #28
0
        public void SimpleInsert()
        {
            int    index    = 3;
            int    oldCount = sc.Count;
            string before   = sc[index - 1];
            string current  = sc[index];
            string after    = sc[index + 1];
            string newStr   = "paco";

            sc.Insert(index, newStr);

            Assertion.Assert(sc.Count == oldCount + 1);
            Assertion.Assert(sc[index].Equals(newStr));
            Assertion.Assert(sc[index - 1].Equals(before));
            Assertion.Assert(sc[index + 1].Equals(current));
            Assertion.Assert(sc[index + 2].Equals(after));
        }
Example #29
0
        /// <summary>
        /// Gets the last used search <see cref="String"/>s as an <see cref="Array"/>.
        /// </summary>
        /// <returns>An <see cref="Array"/> of <see cref="String"/>s that contains the last used search values.</returns>
        private static string[] GetLastUsedSearchValues()
        {
            StringCollection strValues =
                Settings.Default.FrmFindSearchValue
                ?? new StringCollection();

            if (strValues.Count == 0 || !strValues.Contains(string.Empty))
            {
                // Ensure the very first entry is an empty string.
                strValues.Insert(0, string.Empty);
            }

            string[] lastSearchValues = new string[strValues.Count];
            strValues.CopyTo(lastSearchValues, 0);

            return(lastSearchValues);
        }
        public bool IsElementExist(string name)
        {
            bool             IsElementExist = false;
            StringCollection sc             = new StringCollection();

            sc.Add("sara");
            sc.Add("Sindhu");
            sc.Add("Ruthran");
            sc.Insert(4, "maya");// adding an item by Insert method.
            int result = sc.IndexOf(name);

            if (result > 0)
            {
                IsElementExist = true;
            }
            return(IsElementExist);
        }
Example #31
0
 public static void InsertTest(StringCollection collection, string[] data, string element, int location)
 {
     collection.Insert(location, element);
     Assert.Equal(data.Length + 1, collection.Count);
     if (element == ElementNotPresent)
     {
         Assert.Equal(location, collection.IndexOf(ElementNotPresent));
     }
     for (int i = 0; i < data.Length + 1; i++)
     {
         if (i < location)
         {
             Assert.Equal(data[i], collection[i]);
         }
         else if (i == location)
         {
             Assert.Equal(element, collection[i]);
         }
         else
         {
             Assert.Equal(data[i - 1], collection[i]);
         }
     }
 }
 public virtual bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     IntlStrings intl;
     String strLoc = "Loc_000oo";
     StringCollection sc; 
     string [] values = 
     {
         "",
         " ",
         "a",
         "aa",
         "text",
         "     spaces",
         "1",
         "$%^#",
         "2222222222222222222222222",
         System.DateTime.Today.ToString(),
         Int32.MaxValue.ToString()
     };
     try
     {
         intl = new IntlStrings(); 
         Console.WriteLine("--- create collection ---");
         strLoc = "Loc_001oo"; 
         iCountTestcases++;
         sc = new StringCollection();
         Console.WriteLine("1. Insert into empty collection");
         for (int i = 0; i < values.Length; i++) 
         {
             iCountTestcases++;
             if (sc.Count > 0)
                 sc.Clear();
             sc.Insert(0, values[i]);
             if (sc.Count != 1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0001_{0}a, Count {1} instead of 1", i, sc.Count);
             }
             if (! sc.Contains(values[i])) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0001_{0}b, doesn't contain just inserted item", i);
             }
         } 
         Console.WriteLine("2. Insert into filled collection");
         strLoc = "Loc_002oo"; 
         Console.WriteLine(" - at the beginning");
         iCountTestcases++;
         sc.Clear();
         sc.AddRange(values);
         if (sc.Count != values.Length) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002a, count is {0} instead of {1}", sc.Count, values.Length);
         } 
         string val = intl.GetString(MAX_LEN, true, true, true);
         iCountTestcases++;
         sc.Insert(0, val);
         if (sc.Count != values.Length + 1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002b, Count returned {0} instead of {1}", sc.Count, values.Length + 1);
         } 
         iCountTestcases++;
         if (sc.IndexOf(val) != 0) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002c, IndexOf returned {0} instead of {1}", sc.IndexOf(val), 0);
         } 
         for (int i = 0; i < values.Length; i++) 
         { 
             iCountTestcases++;
             if (sc.IndexOf(values[i]) != i+1) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}d, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), i+1);
             } 
         }
         Console.WriteLine(" - at the end");
         iCountTestcases++;
         sc.Clear();
         sc.AddRange(values);
         if (sc.Count != values.Length) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002e, count is {0} instead of {1}", sc.Count, values.Length);
         } 
         iCountTestcases++;
         sc.Insert(values.Length, val);
         if (sc.Count != values.Length + 1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002f, Count returned {0} instead of {1}", sc.Count, values.Length + 1);
         } 
         iCountTestcases++;
         if (sc.IndexOf(val) != values.Length) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002g, IndexOf returned {0} instead of {1}", sc.IndexOf(val), values.Length);
         } 
         for (int i = 0; i < values.Length; i++) 
         { 
             iCountTestcases++;
             if (sc.IndexOf(values[i]) != i) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}h, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), i);
             } 
         }
         Console.WriteLine(" - into the middle");
         iCountTestcases++;
         sc.Clear();
         sc.AddRange(values);
         if (sc.Count != values.Length) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002i, count is {0} instead of {1}", sc.Count, values.Length);
         } 
         iCountTestcases++;
         sc.Insert(values.Length/2, val);
         if (sc.Count != values.Length + 1) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002j, Count returned {0} instead of {1}", sc.Count, values.Length + 1);
         } 
         iCountTestcases++;
         if (sc.IndexOf(val) != values.Length/2) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0002g, IndexOf returned {0} instead of {1}", sc.IndexOf(val), values.Length/2);
         } 
         for (int i = 0; i < values.Length; i++) 
         { 
             iCountTestcases++;
             int expected = i;
             if (i >= values.Length / 2)
                 expected = i+1;
             if (sc.IndexOf(values[i]) != expected) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0002_{0}k, IndexOf returned {1} instead of {2}", i, sc.IndexOf(values[i]), expected);
             } 
         }
         Console.WriteLine("3. Insert(-1, string)");
         strLoc = "Loc_003oo"; 
         iCountTestcases++;
         try 
         {
             sc.Insert(-1, val);
             iCountErrors++;
             Console.WriteLine("Err_0003a, no exception");
         }
         catch (ArgumentOutOfRangeException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0003b, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("4. Insert(Count + 1, string)");
         strLoc = "Loc_004oo"; 
         iCountTestcases++;
         try 
         {
             sc.Insert(sc.Count + 1, val);
             iCountErrors++;
             Console.WriteLine("Err_0004a, no exception");
         }
         catch (ArgumentOutOfRangeException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0004b, unexpected exception: {0}", e.ToString());
         }
         Console.WriteLine("5. Insert(Count + 2, string)");
         strLoc = "Loc_005oo"; 
         iCountTestcases++;
         try 
         {
             sc.Insert(sc.Count + 2, val);
             iCountErrors++;
             Console.WriteLine("Err_0005a, no exception");
         }
         catch (ArgumentOutOfRangeException ex) 
         {
             Console.WriteLine("  expected exception: " + ex.Message);
         }
         catch (Exception e) 
         {
             iCountErrors++;
             Console.WriteLine("Err_0005b, unexpected exception: {0}", e.ToString());
         }
     } 
     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;
     }
 }
Example #33
0
        public static void Insert_ArgumentInvalidTest(StringCollection collection, string[] data)
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => collection.Insert(-1, ElementNotPresent));
            Assert.Throws<ArgumentOutOfRangeException>(() => collection.Insert(data.Length + 1, ElementNotPresent));

            // And as explicit interface implementation
            Assert.Throws<ArgumentOutOfRangeException>(() => ((IList)collection).Insert(-1, ElementNotPresent));
            Assert.Throws<ArgumentOutOfRangeException>(() => ((IList)collection).Insert(data.Length + 1, ElementNotPresent));
        }