Exemplo n.º 1
0
        public void TestAddRemove()
        {
            using (IDataStreamer <int, int> ldr = _grid.GetDataStreamer <int, int>(CacheName))
            {
                ldr.AllowOverwrite = true;

                // Additions.
                ldr.AddData(1, 1);
                ldr.Flush();
                Assert.AreEqual(1, _cache.Get(1));

                ldr.AddData(new KeyValuePair <int, int>(2, 2));
                ldr.Flush();
                Assert.AreEqual(2, _cache.Get(2));

                ldr.AddData(new List <KeyValuePair <int, int> > {
                    new KeyValuePair <int, int>(3, 3), new KeyValuePair <int, int>(4, 4)
                });
                ldr.Flush();
                Assert.AreEqual(3, _cache.Get(3));
                Assert.AreEqual(4, _cache.Get(4));

                // Removal.
                ldr.RemoveData(1);
                ldr.Flush();
                Assert.IsFalse(_cache.ContainsKey(1));

                // Mixed.
                ldr.AddData(5, 5);
                ldr.RemoveData(2);
                ldr.AddData(new KeyValuePair <int, int>(7, 7));
                ldr.AddData(6, 6);
                ldr.RemoveData(4);
                ldr.AddData(new List <KeyValuePair <int, int> > {
                    new KeyValuePair <int, int>(9, 9), new KeyValuePair <int, int>(10, 10)
                });
                ldr.AddData(new KeyValuePair <int, int>(8, 8));
                ldr.RemoveData(3);
                ldr.AddData(new List <KeyValuePair <int, int> > {
                    new KeyValuePair <int, int>(11, 11), new KeyValuePair <int, int>(12, 12)
                });

                ldr.Flush();

                for (int i = 2; i < 5; i++)
                {
                    Assert.IsFalse(_cache.ContainsKey(i));
                }

                for (int i = 5; i < 13; i++)
                {
                    Assert.AreEqual(i, _cache.Get(i));
                }
            }
        }