public void This_Empty () { StringDictionary sd = new StringDictionary (); sd[String.Empty] = null; Assert.IsNull (sd[String.Empty], "this[String.Empty]"); Assert.AreEqual (1, sd.Count, "Count-1"); Assert.IsTrue (sd.ContainsKey (String.Empty), "ContainsKey"); Assert.IsTrue (sd.ContainsValue (null), "ContainsValue"); }
public bool Contains(string item) { // The underlying backing store for the StringDictionary is a HashTable so we // want to delegate Contains to respective ContainsKey/ContainsValue functionality // depending upon whether we are using Keys or Value collections. if (_keyOrValue == KeyOrValue.Key) { return(_internal.ContainsKey(item)); } return(_internal.ContainsValue(item)); }
public static void Main() { // Creates and initializes a new StringDictionary. StringDictionary myCol = new StringDictionary(); myCol.Add("red", "rojo"); myCol.Add("green", "verde"); myCol.Add("blue", "azul"); Console.WriteLine("Count: {0}", myCol.Count); // Display the contents of the collection using foreach. This is the preferred method. Console.WriteLine("Displays the elements using foreach:"); PrintKeysAndValues1(myCol); // Display the contents of the collection using the enumerator. Console.WriteLine("Displays the elements using the IEnumerator:"); PrintKeysAndValues2(myCol); // Display the contents of the collection using the Keys, Values, Count, and Item properties. Console.WriteLine("Displays the elements using the Keys, Values, Count, and Item properties:"); PrintKeysAndValues3(myCol); // Copies the StringDictionary to an array with DictionaryEntry elements. DictionaryEntry[] myArr = new DictionaryEntry[myCol.Count]; myCol.CopyTo(myArr, 0); // Displays the values in the array. Console.WriteLine("Displays the elements in the array:"); Console.WriteLine(" KEY VALUE"); for (int i = 0; i < myArr.Length; i++) Console.WriteLine(" {0,-10} {1}", myArr[i].Key, myArr[i].Value); Console.WriteLine(); // Searches for a value. if (myCol.ContainsValue("amarillo")) Console.WriteLine("The collection contains the value \"amarillo\"."); else Console.WriteLine("The collection does not contain the value \"amarillo\"."); Console.WriteLine(); // Searches for a key and deletes it. if (myCol.ContainsKey("green")) myCol.Remove("green"); Console.WriteLine("The collection contains the following elements after removing \"green\":"); PrintKeysAndValues1(myCol); // Clears the entire collection. myCol.Clear(); Console.WriteLine("The collection contains the following elements after it is cleared:"); PrintKeysAndValues1(myCol); }
public void Empty () { StringDictionary sd = new StringDictionary (); Assert.AreEqual (0, sd.Count, "Count"); Assert.IsFalse (sd.IsSynchronized, "IsSynchronized"); Assert.AreEqual (0, sd.Keys.Count, "Keys"); Assert.AreEqual (0, sd.Values.Count, "Values"); Assert.IsNotNull (sd.SyncRoot, "SyncRoot"); Assert.IsFalse (sd.ContainsKey ("a"), "ContainsKey"); Assert.IsFalse (sd.ContainsValue ("1"), "ContainsValue"); sd.CopyTo (new DictionaryEntry[0], 0); Assert.IsNotNull (sd.GetEnumerator (), "GetEnumerator"); sd.Remove ("a"); // doesn't exists sd.Clear (); }
public void Test01() { StringDictionary sd; // [] StringDictionary is constructed as expected //----------------------------------------------------------------- sd = new StringDictionary(); // [] Compare to null // if (sd == null) { Assert.False(true, string.Format("Error, collection is null after default ctor")); } // [] check Count // if (sd.Count != 0) { Assert.False(true, string.Format("Error, Count = {0} after default ctor", sd.Count)); } // [] check other properties // if (sd.ContainsValue("string")) { Assert.False(true, string.Format("Error, ContainsValue() returned true after default ctor")); } if (sd.ContainsKey("string")) { Assert.False(true, string.Format("Error, ContainsKey() returned true after default ctor")); } // // IsSynchronized = false by default // if (sd.IsSynchronized) { Assert.False(true, string.Format("Error, IsSynchronized returned {0}", sd.IsSynchronized)); } // // [] Add item and verify // sd.Add("key", "value"); if (sd.Count != 1) { Assert.False(true, string.Format("Error, Count returned {0}", sd.Count)); } if (!sd.ContainsKey("key")) { Assert.False(true, string.Format("Error, ContainsKey() returned false")); } if (!sd.ContainsValue("value")) { Assert.False(true, string.Format("Error, ContainsValue() returned false")); } }
public void Test01() { StringDictionary sd; IEnumerator en; DictionaryEntry curr; // Enumerator.Current value // simple string values string[] values = { "a", "aa", "", " ", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keys = { "zero", "one", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; // [] StringDictionary GetEnumerator() //----------------------------------------------------------------- sd = new StringDictionary(); // [] Enumerator for empty dictionary // en = sd.GetEnumerator(); string type = en.GetType().ToString(); if (type.IndexOf("Enumerator", 0) == 0) { Assert.False(true, string.Format("Error, type is not Enumerator")); } // // MoveNext should return false // bool res = en.MoveNext(); if (res) { Assert.False(true, string.Format("Error, MoveNext returned true")); } // // Attempt to get Current should result in exception // Assert.Throws<InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; }); // // Filled collection // [] Enumerator for filled dictionary // for (int i = 0; i < values.Length; i++) { sd.Add(keys[i], values[i]); } en = sd.GetEnumerator(); type = en.GetType().ToString(); if (type.IndexOf("Enumerator", 0) == 0) { Assert.False(true, string.Format("Error, type is not Enumerator")); } // // MoveNext should return true // for (int i = 0; i < sd.Count; i++) { res = en.MoveNext(); if (!res) { Assert.False(true, string.Format("Error, MoveNext returned false", i)); } curr = (DictionaryEntry)en.Current; // //enumerator enumerates in different than added order // so we'll check Contains // if (!sd.ContainsValue(curr.Value.ToString())) { Assert.False(true, string.Format("Error, Current dictionary doesn't contain value from enumerator", i)); } if (!sd.ContainsKey(curr.Key.ToString())) { Assert.False(true, string.Format("Error, Current dictionary doesn't contain key from enumerator", i)); } if (String.Compare(sd[curr.Key.ToString()], curr.Value.ToString()) != 0) { Assert.False(true, string.Format("Error, Value for current Key is different in dictionary", i)); } // while we didn't MoveNext, Current should return the same value DictionaryEntry curr1 = (DictionaryEntry)en.Current; if (!curr.Equals(curr1)) { Assert.False(true, string.Format("Error, second call of Current returned different result", i)); } } // next MoveNext should bring us outside of the collection // res = en.MoveNext(); res = en.MoveNext(); if (res) { Assert.False(true, string.Format("Error, MoveNext returned true")); } // // Attempt to get Current should result in exception // Assert.Throws<InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; }); en.Reset(); // // Attempt to get Current should result in exception // Assert.Throws<InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; }); // // [] Modify dictionary when enumerating // if (sd.Count < 1) { for (int i = 0; i < values.Length; i++) { sd.Add(keys[i], values[i]); } } en = sd.GetEnumerator(); res = en.MoveNext(); if (!res) { Assert.False(true, string.Format("Error, MoveNext returned false")); } curr = (DictionaryEntry)en.Current; int cnt = sd.Count; sd.Remove(keys[0]); if (sd.Count != cnt - 1) { Assert.False(true, string.Format("Error, didn't remove item with 0th key")); } // will return just removed item DictionaryEntry curr2 = (DictionaryEntry)en.Current; if (!curr.Equals(curr2)) { Assert.False(true, string.Format("Error, current returned different value after modification")); } // exception expected Assert.Throws<InvalidOperationException>(() => { res = en.MoveNext(); }); // // [] Modify dictionary when enumerated beyond the end // sd.Clear(); for (int i = 0; i < values.Length; i++) { sd.Add(keys[i], values[i]); } en = sd.GetEnumerator(); for (int i = 0; i < sd.Count; i++) { en.MoveNext(); } curr = (DictionaryEntry)en.Current; curr = (DictionaryEntry)en.Current; cnt = sd.Count; sd.Remove(keys[0]); if (sd.Count != cnt - 1) { Assert.False(true, string.Format("Error, didn't remove item with 0th key")); } // will return just removed item curr2 = (DictionaryEntry)en.Current; if (!curr.Equals(curr2)) { Assert.False(true, string.Format("Error, current returned different value after modification")); } // exception expected Assert.Throws<InvalidOperationException>(() => { res = en.MoveNext(); }); }
public void Test01() { IntlStrings intl; StringDictionary sd; // simple string values string[] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keys = { "zero", "one", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; // initialize IntStrings intl = new IntlStrings(); // [] StringDictionary is constructed as expected //----------------------------------------------------------------- sd = new StringDictionary(); // [] Remove() from empty dictionary // if (sd.Count > 0) sd.Clear(); for (int i = 0; i < keys.Length; i++) { sd.Remove(keys[0]); } // [] Remove() from filled dictionary // int len = values.Length; sd.Clear(); for (int i = 0; i < len; i++) { sd.Add(keys[i], values[i]); } if (sd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len)); } for (int i = 0; i < len; i++) { cnt = sd.Count; sd.Remove(keys[i]); if (sd.Count != cnt - 1) { Assert.False(true, string.Format("Error, didn't remove element with {0} key", i)); } // verify that indeed element with given key was removed if (sd.ContainsValue(values[i])) { Assert.False(true, string.Format("Error, removed wrong value", i)); } if (sd.ContainsKey(keys[i])) { Assert.False(true, string.Format("Error, removed wrong value", i)); } } // // [] Remove() on dictionary with identical values // sd.Clear(); string intlStr = intl.GetRandomString(MAX_LEN); sd.Add("keykey1", intlStr); // 1st duplicate for (int i = 0; i < len; i++) { sd.Add(keys[i], values[i]); } sd.Add("keykey2", intlStr); // 2nd duplicate if (sd.Count != len + 2) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len + 2)); } // remove // sd.Remove("keykey2"); if (!sd.ContainsValue(intlStr)) { Assert.False(true, string.Format("Error, removed both duplicates")); } // second string should still be present if (sd.ContainsKey("keykey2")) { Assert.False(true, string.Format("Error, removed not given instance")); } if (!sd.ContainsKey("keykey1")) { Assert.False(true, string.Format("Error, removed wrong instance")); } // // Intl strings // [] Remove() from dictionary filled with Intl strings // string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) val = intl.GetRandomString(MAX_LEN); intlValues[i] = val; } // // will use first half of array as values and second half as keys // sd.Clear(); for (int i = 0; i < len; i++) { sd.Add(intlValues[i + len], intlValues[i]); } if (sd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len)); } // remove for (int i = 0; i < len; i++) { cnt = sd.Count; sd.Remove(intlValues[i + len]); if (sd.Count != cnt - 1) { Assert.False(true, string.Format("Error, didn't remove element with {0} key", i + len)); } // verify that indeed element with given key was removed if (sd.ContainsValue(intlValues[i])) { Assert.False(true, string.Format("Error, removed wrong value", i)); } if (sd.ContainsKey(intlValues[i + len])) { Assert.False(true, string.Format("Error, removed wrong key", i)); } } // // [] Case sensitivity: keys are always lowercased // sd.Clear(); string[] intlValuesUpper = new string[len]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToLowerInvariant(); } // array of uppercase keys for (int i = 0; i < len; i++) { intlValuesUpper[i] = intlValues[i + len].ToUpperInvariant(); } sd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { sd.Add(intlValues[i + len], intlValues[i]); // adding lowercase strings } if (sd.Count != len) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, len)); } // remove for (int i = 0; i < len; i++) { cnt = sd.Count; sd.Remove(intlValuesUpper[i]); if (sd.Count != cnt - 1) { Assert.False(true, string.Format("Error, didn't remove element with {0} lower key", i + len)); } // verify that indeed element with given key was removed if (sd.ContainsValue(intlValues[i])) { Assert.False(true, string.Format("Error, removed wrong value", i)); } if (sd.ContainsKey(intlValuesUpper[i])) { Assert.False(true, string.Format("Error, removed wrong key", i)); } } // // [] Invalid parameter // Assert.Throws<ArgumentNullException>(() => { sd.Remove(null); }); }
public void SomeElements () { StringDictionary sd = new StringDictionary (); for (int i = 0; i < 10; i++) sd.Add (i.ToString (), (i * 10).ToString ()); Assert.AreEqual ("10", sd["1"], "this[1]"); Assert.AreEqual (10, sd.Count, "Count-10"); Assert.AreEqual (10, sd.Keys.Count, "Keys"); Assert.AreEqual (10, sd.Values.Count, "Values"); Assert.IsTrue (sd.ContainsKey ("2"), "ContainsKey"); Assert.IsTrue (sd.ContainsValue ("20"), "ContainsValue"); DictionaryEntry[] array = new DictionaryEntry[10]; sd.CopyTo (array, 0); sd.Remove ("1"); Assert.AreEqual (9, sd.Count, "Count-9"); sd.Clear (); Assert.AreEqual (0, sd.Count, "Count-0"); }
public void Test01() { IntlStrings intl; StringDictionary sd; string ind; // simple string values string[] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keys = { "zero", "one", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; // Count // initialize IntStrings intl = new IntlStrings(); // [] StringDictionary is constructed as expected //----------------------------------------------------------------- sd = new StringDictionary(); // [] check for empty dictionary // for (int i = 0; i < values.Length; i++) { if (sd.ContainsKey(keys[i])) { Assert.False(true, string.Format("Error, returned true for empty dictionary", i)); } } // [] add simple strings and verify ContainsKey() // cnt = values.Length; for (int i = 0; i < cnt; i++) { sd.Add(keys[i], values[i]); } if (sd.Count != cnt) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, cnt)); } for (int i = 0; i < cnt; i++) { // verify that collection contains all added items // if (!sd.ContainsValue(values[i])) { Assert.False(true, string.Format("Error, collection doesn't contain value \"{1}\"", i, values[i])); } if (!sd.ContainsKey(keys[i])) { Assert.False(true, string.Format("Error, collection doesn't contain key \"{1}\"", i, keys[i])); } } // // Intl strings // [] add Intl strings and verify ContainsKey() // int len = values.Length; string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) val = intl.GetRandomString(MAX_LEN); intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLowerInvariant() == intlValues[i].ToUpperInvariant()) caseInsensitive = true; } // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { cnt = sd.Count; sd.Add(intlValues[i + len], intlValues[i]); if (sd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, sd.Count, cnt + 1)); } // verify that collection contains newly added item // if (!sd.ContainsValue(intlValues[i])) { Assert.False(true, string.Format("Error, collection doesn't contain value of new item", i)); } if (!sd.ContainsKey(intlValues[i + len])) { Assert.False(true, string.Format("Error, collection doesn't contain key of new item", i)); } // access the item // ind = intlValues[i + len]; if (String.Compare(sd[ind], intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, sd[ind], intlValues[i])); } } // // add null string with non-null key // [] add null string with non-null key and verify ContainsKey() // cnt = sd.Count; string k = "keykey"; sd.Add(k, null); if (sd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", sd.Count, cnt + 1)); } // verify that collection contains newly added item // if (!sd.ContainsKey(k)) { Assert.False(true, string.Format("Error, dictionary doesn't contain new key")); } // // [] Case sensitivity: search should be case-sensitive // sd.Clear(); if (sd.Count != 0) { Assert.False(true, string.Format("Error, count is {1} instead of {2} after Clear()", sd.Count, 0)); } string[] intlValuesLower = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpperInvariant(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLowerInvariant(); } sd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { cnt = sd.Count; sd.Add(intlValues[i + len], intlValues[i]); // adding uppercase strings if (sd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, sd.Count, cnt + 1)); } // verify that collection contains newly added uppercase item // if (!sd.ContainsValue(intlValues[i])) { Assert.False(true, string.Format("Error, collection doesn't contain value of new item", i)); } if (!sd.ContainsKey(intlValues[i + len])) { Assert.False(true, string.Format("Error, collection doesn't contain key of new item", i)); } // verify that collection doesn't contains lowercase item // if (!caseInsensitive && sd.ContainsValue(intlValuesLower[i])) { Assert.False(true, string.Format("Error, collection contains lowercase value of new item", i)); } // key is case insensitive if (!sd.ContainsKey(intlValuesLower[i + len])) { Assert.False(true, string.Format("Error, collection doesn't contain lowercase key of new item", i)); } } // // call ContainsKey with null - ArgumentNullException expected // [] ContainsKey (null) // Assert.Throws<ArgumentNullException>(() => { sd.ContainsKey(null); }); }
/// <summary> /// Binds the country dropdown list with countries retrieved /// from the .NET Framework. /// </summary> public void BindCountries() { var dic = new StringDictionary(); var col = new List<string>(); foreach ( var ri in CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(ci => new RegionInfo(ci.Name))) { if (!dic.ContainsKey(ri.EnglishName)) { dic.Add(ri.EnglishName, ri.TwoLetterISORegionName.ToLowerInvariant()); } if (!col.Contains(ri.EnglishName)) { col.Add(ri.EnglishName); } } // Add custom cultures if (!dic.ContainsValue("bd")) { dic.Add("Bangladesh", "bd"); col.Add("Bangladesh"); } col.Sort(); this.ddlCountry.Items.Add(new ListItem("[Not specified]", string.Empty)); foreach (var key in col) { this.ddlCountry.Items.Add(new ListItem(key, dic[key])); } if (this.ddlCountry.SelectedIndex == 0) { this.ddlCountry.SelectedValue = ResolveRegion().TwoLetterISORegionName.ToLowerInvariant(); this.SetFlagImageUrl(); } }
public void Test01() { IntlStrings intl; StringDictionary sd; // simple string values string[] values = { "", " ", "a", "aa", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keys = { "zero", "one", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; int cnt = 0; // Count string ind; // key // initialize IntStrings intl = new IntlStrings(); // [] StringDictionary is constructed as expected //----------------------------------------------------------------- sd = new StringDictionary(); // [] Add() simple strings // for (int i = 0; i < values.Length; i++) { cnt = sd.Count; sd.Add(keys[i], values[i]); if (sd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, sd.Count, cnt + 1)); } // verify that collection contains newly added item // if (!sd.ContainsValue(values[i])) { Assert.False(true, string.Format("Error, collection doesn't contain value of new item", i)); } if (!sd.ContainsKey(keys[i])) { Assert.False(true, string.Format("Error, collection doesn't contain key of new item", i)); } // access the item // if (String.Compare(sd[keys[i]], values[i]) != 0) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, sd[keys[i]], values[i])); } } // // Intl strings // [] Add() Intl strings // int len = values.Length; string[] intlValues = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { string val = intl.GetRandomString(MAX_LEN); while (Array.IndexOf(intlValues, val) != -1) val = intl.GetRandomString(MAX_LEN); intlValues[i] = val; } Boolean caseInsensitive = false; for (int i = 0; i < len * 2; i++) { if (intlValues[i].Length != 0 && intlValues[i].ToLowerInvariant() == intlValues[i].ToUpperInvariant()) caseInsensitive = true; } // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { cnt = sd.Count; sd.Add(intlValues[i + len], intlValues[i]); if (sd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, sd.Count, cnt + 1)); } // verify that collection contains newly added item // if (!sd.ContainsValue(intlValues[i])) { Assert.False(true, string.Format("Error, collection doesn't contain value of new item", i)); } if (!sd.ContainsKey(intlValues[i + len])) { Assert.False(true, string.Format("Error, collection doesn't contain key of new item", i)); } // access the item // ind = intlValues[i + len]; if (String.Compare(sd[ind], intlValues[i]) != 0) { Assert.False(true, string.Format("Error, returned item \"{1}\" instead of \"{2}\"", i, sd[ind], intlValues[i])); } } // // [] Case sensitivity // string[] intlValuesLower = new string[len * 2]; // fill array with unique strings // for (int i = 0; i < len * 2; i++) { intlValues[i] = intlValues[i].ToUpperInvariant(); } for (int i = 0; i < len * 2; i++) { intlValuesLower[i] = intlValues[i].ToLowerInvariant(); } sd.Clear(); // // will use first half of array as values and second half as keys // for (int i = 0; i < len; i++) { cnt = sd.Count; sd.Add(intlValues[i + len], intlValues[i]); if (sd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {1} instead of {2}", i, sd.Count, cnt + 1)); } // verify that collection contains newly added uppercase item // if (!sd.ContainsValue(intlValues[i])) { Assert.False(true, string.Format("Error, collection doesn't contain value of new item", i)); } if (!sd.ContainsKey(intlValues[i + len])) { Assert.False(true, string.Format("Error, collection doesn't contain key of new item", i)); } // verify that collection doesn't contains lowercase item // if (!caseInsensitive && sd.ContainsValue(intlValuesLower[i])) { Assert.False(true, string.Format("Error, collection contains lowercase value of new item", i)); } // key is case insensitive if (!sd.ContainsKey(intlValuesLower[i + len])) { Assert.False(true, string.Format("Error, collection doesn't contain lowercase key of new item", i)); } } // // [] Add (string, null) // cnt = sd.Count; sd.Add("keykey", null); if (sd.Count != cnt + 1) { Assert.False(true, string.Format("Error, count is {0} instead of {1}", sd.Count, cnt + 1)); } // verify that collection contains null // if (!sd.ContainsValue(null)) { Assert.False(true, string.Format("Error, collection doesn't contain null")); } // access item-null // if (sd["keykey"] != null) { Assert.False(true, string.Format("Error, returned non-null on place of null")); } // // Add item with null key - ArgumentNullException expected // [] Add (null, string) // Assert.Throws<ArgumentNullException>(() => { sd.Add(null, "item"); }); // // Add duplicate key item - ArgumentException expected // [] Add duplicate key item // // generate key string k = intl.GetRandomString(MAX_LEN); if (!sd.ContainsKey(k)) { sd.Add(k, "newItem"); } if (!sd.ContainsKey(k)) { Assert.False(true, string.Format("Error,failed to add item")); } else { Assert.Throws<ArgumentException>(() => { sd.Add(k, "itemitemitem"); }); } }