public void Remove_WrongValueForKey_ReturnsFalse() { List <KeyValuePair <Guid, string> > collection = Enumerable.Range(1, Random.Next(10, 100)).Select( n => new KeyValuePair <Guid, string>(Guid.NewGuid(), Random.RandomString(10))).ToList(); Guid existingKey = collection[Random.Next(0, collection.Count)].Key; ConcurrentLookup <Guid, String> concurrentLookup = new ConcurrentLookup <Guid, string>(collection); Assert.IsFalse(concurrentLookup.Remove(existingKey, Random.RandomString(50))); }
public void Remove_ExistingKeyAndValue_ReturnsTrue() { List <KeyValuePair <Guid, string> > collection = Enumerable.Range(1, Random.Next(10, 100)).Select( n => new KeyValuePair <Guid, string>(Guid.NewGuid(), Random.RandomString(10))).ToList(); KeyValuePair <Guid, string> existing = collection[Random.Next(0, collection.Count)]; ConcurrentLookup <Guid, String> concurrentLookup = new ConcurrentLookup <Guid, string>(collection); Assert.IsTrue(concurrentLookup.Remove(existing.Key, existing.Value)); }
public void Remove_AbsentKeyAndValue_ReturnsFalse() { Guid absentKey = Guid.NewGuid(); IEnumerable <KeyValuePair <Guid, string> > collection = Enumerable.Range(1, Random.Next(10, 100)).Select( n => new KeyValuePair <Guid, string>(Guid.NewGuid(), Random.RandomString(10))); ConcurrentLookup <Guid, String> concurrentLookup = new ConcurrentLookup <Guid, string>(collection); Assert.IsFalse(concurrentLookup.Remove(absentKey, Random.RandomString(15))); }
public void Contains_AfterRemovingLastValueInKey_ReturnsFalse() { List <KeyValuePair <Guid, string> > collection = Enumerable.Range(1, Random.Next(10, 100)).Select( n => new KeyValuePair <Guid, string>(Guid.NewGuid(), Random.RandomString(10))).ToList(); KeyValuePair <Guid, string> existing = collection[Random.Next(0, collection.Count)]; ConcurrentLookup <Guid, String> concurrentLookup = new ConcurrentLookup <Guid, string>(collection); concurrentLookup.Remove(existing.Key, existing.Value); Assert.IsFalse(concurrentLookup.Contains(existing.Key)); }
public void Contains_AfterRemovingButValuesStillExistForKey_ReturnsTrue() { Guid existingKeyWithDuplicates = Guid.NewGuid(); List <KeyValuePair <Guid, string> > existingValues = Enumerable.Range(1, Random.Next(2, 10)).Select( n => new KeyValuePair <Guid, string>(existingKeyWithDuplicates, Random.RandomString(20))).ToList(); IEnumerable <KeyValuePair <Guid, string> > collection = Enumerable.Range(1, Random.Next(10, 100)).Select( n => new KeyValuePair <Guid, string>(Guid.NewGuid(), Random.RandomString(10))) .Concat(existingValues); ConcurrentLookup <Guid, String> concurrentLookup = new ConcurrentLookup <Guid, string>(collection); concurrentLookup.Remove(existingKeyWithDuplicates, existingValues.First().Value); Assert.IsTrue(concurrentLookup.Contains(existingKeyWithDuplicates)); }
public void Remove() { var lookup = new ConcurrentLookup <int, string>(); lookup.Add(1, "one"); Assert.IsTrue(lookup.TryGetValues(1, out IReadOnlyList <string> ones)); Assert.AreEqual(1, ones.Count); Assert.AreEqual("one", ones[0]); lookup.Add(2, "two"); lookup.Add(2, "zwei"); Assert.IsTrue(lookup.TryGetValues(2, out IReadOnlyList <string> twos)); Assert.AreEqual(2, twos.Count); Assert.AreEqual("two", twos[0]); Assert.AreEqual("zwei", twos[1]); Assert.IsFalse(lookup.TryGetValues(0, out IReadOnlyList <string> zeros)); Assert.IsNull(zeros); lookup.Remove(2, "zwei"); Assert.IsTrue(lookup.TryGetValues(2, out IReadOnlyList <string> oneTwo)); Assert.AreEqual(1, oneTwo.Count); Assert.AreEqual("two", oneTwo[0]); lookup.Remove(2, "duo"); Assert.IsTrue(lookup.TryGetValues(2, out IReadOnlyList <string> stillTwo)); Assert.AreEqual(1, stillTwo.Count); Assert.AreEqual("two", stillTwo[0]); lookup.Remove(2, "two"); Assert.IsFalse(lookup.TryGetValues(2, out IReadOnlyList <string> noTwos)); Assert.IsNull(noTwos); }
public void This_AfterRemovingDuplicateValue_StillContainsOneAddedValues() { List <KeyValuePair <Guid, string> > collection = Enumerable.Range(1, Random.Next(10, 100)).Select( n => new KeyValuePair <Guid, string>(Guid.NewGuid(), Random.RandomString(10))).ToList(); Guid newKey = Guid.NewGuid(); String newValue = Random.RandomString(20); ConcurrentLookup <Guid, String> concurrentLookup = new ConcurrentLookup <Guid, string>(collection); concurrentLookup.Add(newKey, newValue); concurrentLookup.Add(newKey, newValue); concurrentLookup.Remove(newKey, newValue); CollectionAssert.AreEqual(new List <String> { newValue }, concurrentLookup[newKey].ToList()); }
public void This_AfterRemovingDuplicateValue_StillContainsOneAddedValues() { List<KeyValuePair<Guid, string>> collection = Enumerable.Range(1, Random.Next(10, 100)).Select( n => new KeyValuePair<Guid, string>(Guid.NewGuid(), Random.RandomString(10))).ToList(); Guid newKey = Guid.NewGuid(); String newValue = Random.RandomString(20); ConcurrentLookup<Guid, String> concurrentLookup = new ConcurrentLookup<Guid, string>(collection); concurrentLookup.Add(newKey, newValue); concurrentLookup.Add(newKey, newValue); concurrentLookup.Remove(newKey, newValue); CollectionAssert.AreEqual(new List<String> {newValue}, concurrentLookup[newKey].ToList()); }
public void Contains_AfterRemovingButValuesStillExistForKey_ReturnsTrue() { Guid existingKeyWithDuplicates = Guid.NewGuid(); List<KeyValuePair<Guid, string>> existingValues = Enumerable.Range(1, Random.Next(2, 10)).Select( n => new KeyValuePair<Guid, string>(existingKeyWithDuplicates, Random.RandomString(20))).ToList(); IEnumerable<KeyValuePair<Guid, string>> collection = Enumerable.Range(1, Random.Next(10, 100)).Select( n => new KeyValuePair<Guid, string>(Guid.NewGuid(), Random.RandomString(10))) .Concat(existingValues); ConcurrentLookup<Guid, String> concurrentLookup = new ConcurrentLookup<Guid, string>(collection); concurrentLookup.Remove(existingKeyWithDuplicates, existingValues.First().Value); Assert.IsTrue(concurrentLookup.Contains(existingKeyWithDuplicates)); }
public void Contains_AfterRemovingLastValueInKey_ReturnsFalse() { List<KeyValuePair<Guid, string>> collection = Enumerable.Range(1, Random.Next(10, 100)).Select( n => new KeyValuePair<Guid, string>(Guid.NewGuid(), Random.RandomString(10))).ToList(); KeyValuePair<Guid, string> existing = collection[Random.Next(0, collection.Count)]; ConcurrentLookup<Guid, String> concurrentLookup = new ConcurrentLookup<Guid, string>(collection); concurrentLookup.Remove(existing.Key, existing.Value); Assert.IsFalse(concurrentLookup.Contains(existing.Key)); }
public void Remove_WrongValueForKey_ReturnsFalse() { List<KeyValuePair<Guid, string>> collection = Enumerable.Range(1, Random.Next(10, 100)).Select( n => new KeyValuePair<Guid, string>(Guid.NewGuid(), Random.RandomString(10))).ToList(); Guid existingKey = collection[Random.Next(0, collection.Count)].Key; ConcurrentLookup<Guid, String> concurrentLookup = new ConcurrentLookup<Guid, string>(collection); Assert.IsFalse(concurrentLookup.Remove(existingKey, Random.RandomString(50))); }
public void Remove_AbsentKeyAndValue_ReturnsFalse() { Guid absentKey = Guid.NewGuid(); IEnumerable<KeyValuePair<Guid, string>> collection = Enumerable.Range(1, Random.Next(10, 100)).Select( n => new KeyValuePair<Guid, string>(Guid.NewGuid(), Random.RandomString(10))); ConcurrentLookup<Guid, String> concurrentLookup = new ConcurrentLookup<Guid, string>(collection); Assert.IsFalse(concurrentLookup.Remove(absentKey, Random.RandomString(15))); }
public void Remove_ExistingKeyAndValue_ReturnsTrue() { List<KeyValuePair<Guid, string>> collection = Enumerable.Range(1, Random.Next(10, 100)).Select( n => new KeyValuePair<Guid, string>(Guid.NewGuid(), Random.RandomString(10))).ToList(); KeyValuePair<Guid, string> existing = collection[Random.Next(0, collection.Count)]; ConcurrentLookup<Guid, String> concurrentLookup = new ConcurrentLookup<Guid, string>(collection); Assert.IsTrue(concurrentLookup.Remove(existing.Key, existing.Value)); }