Skip to content

Commit

Permalink
Add TryAdd and Clear regression tests (dotnet/corefx#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 dotnet/corefx#2

*  Address PR Feedback dotnet/corefx#3

* Remove Extra Line

* Add MoveNext Result Asserts


Commit migrated from dotnet/corefx@d8a0778
  • Loading branch information
A-And committed Sep 25, 2018
1 parent 3b61100 commit 8fd7b0d
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 8fd7b0d

Please sign in to comment.