Ejemplo n.º 1
0
        public int RemoveAllValues(string key)
        {
            var count = data[key].Count();

            if (count > 0)
            {
                data.Remove(key);
            }

            return(count);
        }
Ejemplo n.º 2
0
        public void EditableLookupRemove()
        {
            var lookup = new EditableLookup <string, int>();

            lookup.Add("a", 1);
            lookup.Add("a", 2);
            lookup.Add("b", 3);
            lookup.Add("a", 4);
            Assert.IsTrue(lookup.Contains("a"));
            Assert.IsTrue(lookup.Contains("b"));
            Assert.IsTrue(lookup.Contains("b", 3));
            Assert.IsFalse(lookup.Contains("b", 17));

            Assert.IsTrue(lookup.Remove("b"));
            Assert.IsFalse(lookup.Remove("b")); // no longer there
            Assert.AreEqual(1, lookup.Count);
            Assert.AreEqual(3, lookup["a"].Count());
            Assert.IsTrue(lookup.Remove("a", 1));
            Assert.IsFalse(lookup.Remove("a", 1));    // no longer there
            Assert.IsFalse(lookup.Remove("foo", 99)); // never existed

            Assert.AreEqual(6, lookup["a"].Sum());    // 2 + 4
            lookup.Remove("a", 2);
            lookup.Remove("a", 4);
            Assert.IsFalse(lookup.Contains("a"));
            Assert.AreEqual(0, lookup.Count);
        }
Ejemplo n.º 3
0
 public Task <bool> Remove(string key, string value)
 {
     return(Task.FromResult(_data.Remove(key, value)));
 }
Ejemplo n.º 4
0
        public void EditableLookupRemove()
        {
            var lookup = new EditableLookup<string, int>();
            lookup.Add("a", 1);
            lookup.Add("a", 2);
            lookup.Add("b", 3);
            lookup.Add("a", 4);
            Assert.IsTrue(lookup.Contains("a"));
            Assert.IsTrue(lookup.Contains("b"));
            Assert.IsTrue(lookup.Contains("b", 3));
            Assert.IsFalse(lookup.Contains("b", 17));

            Assert.IsTrue(lookup.Remove("b"));
            Assert.IsFalse(lookup.Remove("b")); // no longer there
            Assert.AreEqual(1, lookup.Count);
            Assert.AreEqual(3, lookup["a"].Count());
            Assert.IsTrue(lookup.Remove("a", 1));
            Assert.IsFalse(lookup.Remove("a", 1)); // no longer there
            Assert.IsFalse(lookup.Remove("foo", 99)); // never existed

            Assert.AreEqual(6, lookup["a"].Sum()); // 2 + 4
            lookup.Remove("a", 2);
            lookup.Remove("a", 4);
            Assert.IsFalse(lookup.Contains("a"));
            Assert.AreEqual(0, lookup.Count);            
        }