GetEnumerator() public method

public GetEnumerator ( ) : IDictionaryEnumerator
return IDictionaryEnumerator
Beispiel #1
0
		private void Common (OrderedDictionary od)
		{
			Assert.IsNotNull (od.GetEnumerator (), "GetEnumerator");
			Assert.AreEqual (0, od.Count, "Count-0");
			Assert.IsFalse (od.IsReadOnly, "IsReadOnly");
			od.Add ("a", "1");
			Assert.AreEqual (1, od.Count, "Count-1");
			od["a"] = "11";
			Assert.AreEqual ("11", od["a"], "this[string]");
			od[0] = "111";
			Assert.AreEqual ("111", od[0], "this[int]");

			DictionaryEntry[] array = new DictionaryEntry[2];
			od.CopyTo (array, 1);

			Assert.AreEqual ("111", ((DictionaryEntry)array[1]).Value, "CopyTo");
			Assert.AreEqual (1, od.Keys.Count, "Keys");
			Assert.AreEqual (1, od.Values.Count, "Values");
			Assert.IsTrue (od.Contains ("a"), "Contains(a)");
			Assert.IsFalse (od.Contains ("111"), "Contains(111)");

			od.Insert (0, "b", "2");
			Assert.AreEqual (2, od.Count, "Count-2");
			od.Add ("c", "3");
			Assert.AreEqual (3, od.Count, "Count-3");

			OrderedDictionary ro = od.AsReadOnly ();

			od.RemoveAt (2);
			Assert.AreEqual (2, od.Count, "Count-4");
			Assert.IsFalse (od.Contains ("c"), "Contains(c)");

			od.Remove ("b");
			Assert.AreEqual (1, od.Count, "Count-5");
			Assert.IsFalse (od.Contains ("b"), "Contains(b)");

			od.Clear ();
			Assert.AreEqual (0, od.Count, "Count-6");

			Assert.IsTrue (ro.IsReadOnly, "IsReadOnly-2");
			// it's a read-only reference
			Assert.AreEqual (0, od.Count, "Count-7");
		}
		public void DetailsView_ExtractRowValues ()
		{
			PokerDetailsView dv = new PokerDetailsView ();
			DataTable ds = TableObject.CreateDataTable ();
			dv.DataSource = ds;
			dv.DataBind ();
			OrderedDictionary fieldsValues = new OrderedDictionary ();
			dv.DoExtractRowValues (fieldsValues, true, true);
			Assert.AreEqual (3, fieldsValues.Count, "ExtractRowValues1");
			Assert.AreEqual (3, fieldsValues.Keys.Count, "ExtractRowValues2");
			Assert.AreEqual (3, fieldsValues.Values.Count, "ExtractRowValues3");
			Assert.AreEqual (true, fieldsValues.Contains ("ID"), "ExtractRowValues4");
			IDictionaryEnumerator enumerator=fieldsValues.GetEnumerator ();
			enumerator.MoveNext ();
			Assert.AreEqual ("ID",enumerator.Key,"FieldValue1");
			Assert.AreEqual ("1001", enumerator.Value , "FieldValue2");
			enumerator.MoveNext ();
			Assert.AreEqual ("FName", enumerator.Key, "FieldValue3");
			Assert.AreEqual ("Mahesh", enumerator.Value, "FieldValue4");
			enumerator.MoveNext ();
			Assert.AreEqual ("LName", enumerator.Key, "FieldValue5");
			Assert.AreEqual ("Chand", enumerator.Value, "FieldValue6");
			fieldsValues = new OrderedDictionary ();
			dv.DoExtractRowValues (fieldsValues, false, false);
			Assert.AreEqual (0, fieldsValues.Count, "ExtractRowValues-NotReadOnly1");
			fieldsValues = new OrderedDictionary ();
			dv.DoExtractRowValues (fieldsValues, true, false);
			Assert.AreEqual (3, fieldsValues.Count, "ExtractRowValues-NoPrimaryKeys1");
			Assert.AreEqual (3, fieldsValues.Keys.Count, "ExtractRowValues-NoPrimaryKeys2");
			fieldsValues = new OrderedDictionary ();
			dv.DoExtractRowValues (fieldsValues, false, true);
			Assert.AreEqual (0, fieldsValues.Count, "ExtractRowValues-NotReadOnly2");
			Assert.AreEqual (0, fieldsValues.Keys.Count, "ExtractRowValues-NotReadOnly3");
		}
 public void GetEnumeratorTests()
 {
     var d = new OrderedDictionary();
     IEnumerator e = d.GetEnumerator();
     d["foo"] = "bar";
     Assert.Throws<InvalidOperationException>(() => e.MoveNext());
     e = d.GetEnumerator();
     Assert.True(e.MoveNext());
     var c = (DictionaryEntry)e.Current;
     Assert.Equal("foo", c.Key);
     Assert.Equal("bar", c.Value);
     Assert.False(e.MoveNext());
 }
        public void GetDictionaryEnumeratorTests()
        {
            var d = new OrderedDictionary();
            for (int i = 0; i < 10; i++)
            {
                d.Add("Key_" + i, "Value_" + i);
            }

            IDictionaryEnumerator e = d.GetEnumerator();
            for (int i = 0; i < 2; i++)
            {
                int count = 0;
                while (e.MoveNext())
                {
                    DictionaryEntry entry1 = (DictionaryEntry)e.Current;
                    DictionaryEntry entry2 = e.Entry;

                    Assert.Equal(entry1.Key, entry2.Key);
                    Assert.Equal(entry1.Value, entry1.Value);

                    Assert.Equal(e.Key, entry1.Key);
                    Assert.Equal(e.Value, entry1.Value);

                    Assert.Equal(e.Value, d[e.Key]);
                    count++;
                }
                Assert.Equal(count, d.Count);
                Assert.False(e.MoveNext());
                e.Reset();
            }

            e = d.GetEnumerator();
            d["foo"] = "bar";
            Assert.Throws<InvalidOperationException>(() => e.MoveNext());
        }