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

Commit

Permalink
Add TryAdd and Clear regression tests (#32407)
Browse files Browse the repository at this point in the history
* Add TryAdd and Clear regression tests

* Add Run Condition on Clear()

* Address PR Feedback

* Address PR Feedback #2

*  Address PR Feedback #3

* Remove Extra Line

* Add MoveNext Result Asserts
  • Loading branch information
A-And committed Sep 25, 2018
1 parent 61c90ce commit d8a0778
Showing 1 changed file with 26 additions and 0 deletions.
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

0 comments on commit d8a0778

Please sign in to comment.