public void WeakKeyDictionaryWithData_EnumerateUsingIDictionaryEnumerator_ValidateContents() { IDictionary dictionary = new WeakKeyDictionary <string, int>(); var values = new[] { -1, 48, 62, 88, -32 }; for (int i = 0; i < values.Length; ++i) { dictionary.Add(values[i].ToString(), values[i]); } var dictionaryEnumerator = dictionary.GetEnumerator(); while (dictionaryEnumerator.MoveNext()) { var current = dictionaryEnumerator.Current; var entry = dictionaryEnumerator.Entry; Assert.Equal(current, entry); var key = dictionaryEnumerator.Key; var value = dictionaryEnumerator.Value; var entryKey = entry.Key as string; var entryValue = (int)entry.Value; Assert.Equal(key, entryKey); Assert.Equal(value, entryValue); } var disposable = dictionaryEnumerator as IDisposable; if (disposable != null) { disposable.Dispose(); dictionaryEnumerator = null; disposable = null; } }
public void WeakKeyDictionaryWithData_ResetIDictionaryEnumerator_ThrowsNotSupportedException() { IDictionary dictionary = new WeakKeyDictionary <DisposableTestObject, int>(); var values = new[] { -1, 48, 62, 88, -32 }; for (int i = 0; i < values.Length; ++i) { dictionary.Add(new DisposableTestObject(values[i].ToString()), values[i]); } var dictionaryEnumerator = dictionary.GetEnumerator(); Assert.Throws <NotSupportedException>(() => dictionaryEnumerator.Reset()); }