public void Contains_Invoke_ReturnsExpected(IEqualityComparer <string> comparer, string key, bool expected) { var collection = new StringKeyedCollection <string>(comparer, 3); collection.GetKeyForItemHandler = item => item + "_key"; // Without dictionary. collection.InsertItem(0, "first"); Assert.Equal(expected, collection.Contains(key)); // With dictionary. collection.InsertItem(0, "second"); collection.InsertItem(0, "third"); collection.InsertItem(0, "fourth"); Assert.Equal(expected, collection.Contains(key)); }
public void Contains_NullKeyForItemResult_Success(int dictionaryCreationThreshold, bool expected) { var collection = new StringKeyedCollection <int>(null, dictionaryCreationThreshold); collection.GetKeyForItemHandler = i => i.ToString(); collection.Add(1); collection.Add(2); collection.Add(3); collection.Add(4); // Don't get even numbers. collection.GetKeyForItemHandler = i => i % 2 == 0 ? null : i.ToString(); // Get null key. Assert.Equal(expected, collection.Contains("2")); // Get non null key. Assert.True(collection.Contains("1")); }
public void Contains_DifferentKeyForItemResult_Success(int dictionaryCreationThreshold, bool expected) { var collection = new StringKeyedCollection <int>(null, dictionaryCreationThreshold); collection.GetKeyForItemHandler = i => i.ToString(); collection.Add(1); collection.Add(2); collection.Add(3); collection.Add(4); collection.GetKeyForItemHandler = i => (i * 2).ToString(); Assert.Equal(expected, collection.Contains("6")); }
public void Contains_NullKey_ThrowsArgumentNullException() { var collection = new StringKeyedCollection <string>(); AssertExtensions.Throws <ArgumentNullException>("key", () => collection.Contains(null)); }