From e373d993c1b3f61315dcc9280ee251c7a9b5e854 Mon Sep 17 00:00:00 2001 From: Andon Andonov Date: Fri, 21 Sep 2018 21:01:38 -0700 Subject: [PATCH] Add TryAdd and Clear regression tests --- .../Generic/Dictionary/Dictionary.Tests.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs b/src/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs index 640205b269e1..53e488a86d7c 100644 --- a/src/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs +++ b/src/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs @@ -250,6 +250,31 @@ public void Remove_NonExistentEntries_DoesNotPreventEnumeration() } } + [Fact] + [Trait("MyTrait", "MyTraitValue")] + public void Clear_OnEmptyCollection_DoesNotInvalidateEnumerator() + { + Dictionary dictionary = new Dictionary(); + var valuesEnum = dictionary.GetEnumerator(); + + dictionary.Clear(); + Assert.Empty(dictionary); + valuesEnum.MoveNext(); + } + + [Fact] + [Trait("MyTrait", "MyTraitValue")] + public void Unsuccessful_TryAdd_DoesNotInvalidateEnumerator() + { + Dictionary dictionary = new Dictionary(); + dictionary.Add("a", "b"); + + var valuesEnum = dictionary.GetEnumerator(); + Assert.False(dictionary.TryAdd("a", "c")); + + valuesEnum.MoveNext(); + } + [Theory] [MemberData(nameof(CopyConstructorInt32Data))] public void CopyConstructorInt32(int size, Func keyValueSelector, Func, IDictionary> dictionarySelector)