Ejemplo n.º 1
0
        public void StreamAvailableObjects()
        {
            //add two new items
            var item1 = new CacheableTypeOk(1, 1001, "aaa", new DateTime(2010, 10, 10), 1500);

            _client.Put(item1);

            var item2 = new CacheableTypeOk(2, 1002, "aaa", new DateTime(2010, 10, 10), 1600);

            _client.Put(item2);

            //ask for items 1 2 3 4 (1 2 should be returned and 3 4 not found)
            var items = new List <KeyValue>
            {
                new KeyValue(1,
                             new KeyInfo(KeyDataType.IntKey, KeyType.Primary,
                                         "PrimaryKey")),
                new KeyValue(2,
                             new KeyInfo(KeyDataType.IntKey, KeyType.Primary,
                                         "PrimaryKey")),
                new KeyValue(3,
                             new KeyInfo(KeyDataType.IntKey, KeyType.Primary,
                                         "PrimaryKey")),
                new KeyValue(4,
                             new KeyInfo(KeyDataType.IntKey, KeyType.Primary,
                                         "PrimaryKey"))
            };

            var wait     = new ManualResetEvent(false);
            var found    = new List <CacheableTypeOk>();
            var notFound = _client.GetAvailableItems(items,
                                                     delegate(CacheableTypeOk item, int currentItem, int totalItems)
            {
                found.Add(item);
                if (currentItem == totalItems)
                {
                    wait.Set();
                }
            }, delegate { });

            wait.WaitOne();
            Assert.AreEqual(notFound.Count, 2);
            Assert.AreEqual(notFound[0], 3);
            Assert.AreEqual(notFound[1], 4);
            Assert.AreEqual(found.Count, 2);
            Assert.AreEqual(found[0].PrimaryKey, 1);
            Assert.AreEqual(found[1].PrimaryKey, 2);
        }