Beispiel #1
0
        public void DomainDescription()
        {
            var evalResult = _client.IsComplete <CacheableTypeOk>(i => i.IndexKeyFolder == "aaa");

            Assert.IsFalse(evalResult);


            var item1 = new CacheableTypeOk(1, 1001, "aaa", new DateTime(2010, 10, 10), 1500);

            _client.PutOne(item1);

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

            _client.PutOne(item2);

            evalResult = _client.IsComplete <CacheableTypeOk>(i => i.IndexKeyFolder == "aaa");
            Assert.IsFalse(evalResult);

            var description = new DomainDescription(OrQuery.Empty <CacheableTypeOk>());

            //describe the domain as complete
            _client.DeclareDomain(description);

            evalResult = _client.IsComplete <CacheableTypeOk>(i => i.IndexKeyFolder == "aaa");
            Assert.IsTrue(evalResult);
        }
Beispiel #2
0
        public void DataAccess()
        {
            //add two new items
            var item1 = new CacheableTypeOk(1, 1001, "aaa", new DateTime(2010, 10, 10), 1500);

            _client.PutOne(item1);

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

            _client.PutOne(item2);

            _client.DeclareDomain <CacheableTypeOk>(x => x.IndexKeyFolder == "aaa");

            var eval = _client.IsComplete <CacheableTypeOk>(x => x.IndexKeyFolder == "aaa");

            Assert.IsTrue(eval); //domain is complete


            eval = _client.IsComplete <CacheableTypeOk>(x => x.IndexKeyFolder == "bbb");
            Assert.IsFalse(eval); //domain is incomplete


            //reload the first one by primary key
            var item1Reloaded = _client.GetOne <CacheableTypeOk>(i => i.PrimaryKey == 1);

            Assert.AreEqual(item1, item1Reloaded);

            //reload both items by folder name
            var itemsInAaa = _client.GetMany <CacheableTypeOk>(x => x.IndexKeyFolder == "aaa").ToList();

            Assert.AreEqual(2, itemsInAaa.Count);

            //change the folder of the first item and put it back into the cache
            item1.IndexKeyFolder = "bbb";
            _client.PutOne(item1);

            //now it should be only one item left in aaa
            itemsInAaa = _client.GetMany <CacheableTypeOk>(x => x.IndexKeyFolder == "aaa").ToList();
            Assert.AreEqual(1, itemsInAaa.Count);

            //get both of them again by date
            var allItems = _client.GetMany <CacheableTypeOk>(x => x.IndexKeyDate == new DateTime(2010, 10, 10)).ToList();

            Assert.AreEqual(allItems.Count, 2);

            //get both of them using an In query

            var folders = new[] { "aaa", "bbb" };

            allItems = _client.GetMany <CacheableTypeOk>(x => folders.Contains(x.IndexKeyFolder)).ToList();
            Assert.AreEqual(allItems.Count, 2);

            //remove the first one
            _client.RemoveMany <CacheableTypeOk>(x => x.PrimaryKey == 1);

            //the previous query should now return only one item
            allItems = _client.GetMany <CacheableTypeOk>(x => folders.Contains(x.IndexKeyFolder)).ToList();
            Assert.AreEqual(allItems.Count, 1);
        }