Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add TryAdd and Clear regression tests #32407

Merged
merged 7 commits into from
Sep 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ public void IDictionary_NonGeneric_Contains_KeyOfWrongType(int count)
}
}

[Fact]
public void Clear_OnEmptyCollection_DoesNotInvalidateEnumerator()
{
if (ModifyEnumeratorAllowed.HasFlag(ModifyOperation.Clear))
{
IDictionary dictionary = new Dictionary<string, string>();
IEnumerator valuesEnum = dictionary.GetEnumerator();

dictionary.Clear();
Assert.Empty(dictionary);
Assert.False(valuesEnum.MoveNext());
}
}

#endregion

#region ICollection tests
Expand Down Expand Up @@ -250,6 +264,18 @@ public void Remove_NonExistentEntries_DoesNotPreventEnumeration()
}
}

[Fact]
public void TryAdd_ItemAlreadyExists_DoesNotInvalidateEnumerator()
{
var dictionary = new Dictionary<string, string>();
dictionary.Add("a", "b");

IEnumerator valuesEnum = dictionary.GetEnumerator();
Assert.False(dictionary.TryAdd("a", "c"));

Assert.True(valuesEnum.MoveNext());
}

[Theory]
[MemberData(nameof(CopyConstructorInt32Data))]
public void CopyConstructorInt32(int size, Func<int, int> keyValueSelector, Func<IDictionary<int, int>, IDictionary<int, int>> dictionarySelector)
Expand Down