public void DataAccess() { var builder = new QueryBuilder(typeof(CacheableTypeOk)); //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); var domainDeclaration = new DomainDescription(typeof(CacheableTypeOk)); domainDeclaration.AddOrReplace(builder.MakeAtomicQuery("IndexKeyFolder", "aaa")); _client.DeclareDomain(domainDeclaration, DomainDeclarationAction.Set); var eval = _client.EvalQuery(builder.GetManyWhere("IndexKeyFolder == aaa")); Assert.IsTrue(eval.Key); //domain is complete Assert.AreEqual(eval.Value, 2); eval = _client.EvalQuery(builder.GetManyWhere("IndexKeyFolder == bbb")); Assert.IsFalse(eval.Key); //domain is incomplete Assert.AreEqual(eval.Value, 0); //reload the first one by primary key var item1Reloaded = _client.GetOne <CacheableTypeOk>(1); Assert.AreEqual(item1, item1Reloaded); //reload both items by folder name IList <CacheableTypeOk> itemsInAaa = new List <CacheableTypeOk>(_client.GetMany <CacheableTypeOk>("IndexKeyFolder == aaa")); Assert.AreEqual(itemsInAaa.Count, 2); //change the folder of the first item and put it back into the cache item1.IndexKeyFolder = "bbb"; _client.Put(item1); //now it should be only one item left in aaa itemsInAaa = new List <CacheableTypeOk>(_client.GetMany <CacheableTypeOk>("IndexKeyFolder == aaa")); Assert.AreEqual(itemsInAaa.Count, 1); //get both of them again by date IList <CacheableTypeOk> allItems = new List <CacheableTypeOk>(_client.GetMany <CacheableTypeOk>($"IndexKeyDate == {new DateTime(2010, 10, 10).Ticks}")); Assert.AreEqual(allItems.Count, 2); //get both of them using an In query var q = builder.In("indexkeyfolder", "aaa", "bbb"); allItems = _client.GetMany <CacheableTypeOk>(q).ToList(); Assert.AreEqual(allItems.Count, 2); //remove the first one _client.Remove <CacheableTypeOk>(1); //the previous query should now return only one item allItems = _client.GetMany <CacheableTypeOk>(q).ToList(); Assert.AreEqual(allItems.Count, 1); }
public void DataAccess() { //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); //reload the first one by primary key var item1Reloaded = _client.GetOne <CacheableTypeOk>(1); Assert.AreEqual(item1, item1Reloaded); //try to load nonexistent object by primary key var itemNull = _client.GetOne <CacheableTypeOk>("UniqueKey", 2055); Assert.IsNull(itemNull); //try to load nonexistent object by unique key itemNull = _client.GetOne <CacheableTypeOk>(55); Assert.IsNull(itemNull); //reload both items by folder name IList <CacheableTypeOk> itemsInAaa = _client.GetMany <CacheableTypeOk>("IndexKeyFolder == aaa").ToList(); Assert.AreEqual(itemsInAaa.Count, 2); //change the folder of the first item and put it back into the cache item1.IndexKeyFolder = "bbb"; _client.Put(item1); //now it should be only one item left in aaa itemsInAaa = _client.GetMany <CacheableTypeOk>("IndexKeyFolder == aaa").ToList(); Assert.AreEqual(itemsInAaa.Count, 1); //get both of them again by date IList <CacheableTypeOk> allItems = _client.GetMany <CacheableTypeOk>($"IndexKeyDate == {new DateTime(2010, 10, 10).Ticks}").ToList(); Assert.AreEqual(allItems.Count, 2); var desc = ClientSideTypeDescription.RegisterType <CacheableTypeOk>().AsTypeDescription; //get object descriptions var qb = new QueryBuilder(typeof(CacheableTypeOk)); var itemDescriptions = _client.GetObjectDescriptions(qb.GetManyWhere($"IndexKeyDate == {new DateTime(2010, 10, 10).Ticks}")); Assert.AreEqual(itemDescriptions.Count, 2); Assert.AreEqual(itemDescriptions[0].PrimaryKey, desc.MakePrimaryKeyValue(1)); Assert.AreEqual(itemDescriptions[1].PrimaryKey, desc.MakePrimaryKeyValue(2)); //get both of them using an In query var builder = new QueryBuilder(typeof(CacheableTypeOk)); var q = builder.In("indexkeyfolder", "aaa", "bbb"); allItems = _client.GetMany <CacheableTypeOk>(q).ToList(); Assert.AreEqual(allItems.Count, 2); //remove the first one _client.Remove <CacheableTypeOk>(1); //removing non existent item should throw exception Assert.Throws <CacheException>(() => _client.Remove <CacheableTypeOk>(46546)); //the previous query should now return only one item allItems = _client.GetMany <CacheableTypeOk>(q).ToList(); Assert.AreEqual(allItems.Count, 1); //COUNT should also return 1 int count = _client.EvalQuery(q).Value; Assert.AreEqual(count, 1); }