Beispiel #1
0
        /// <summary>
        ///     Get one by primary key
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public OrQuery GetOne(object value)
        {
            var keyValue = _typeDescription.MakePrimaryKeyValue(value);

            var query    = new OrQuery(_typeDescription.FullTypeName);
            var andQuery = new AndQuery();

            query.Elements.Add(andQuery);
            andQuery.Elements.Add(new AtomicQuery(keyValue));

            return(query);
        }
Beispiel #2
0
        public void StreamUnstreamMessagesOneByOne()
        {
            QueryBuilder qbuilder = new QueryBuilder(typeof(CacheableTypeOk));

            PutRequest      put  = new PutRequest(typeof(CacheableTypeOk));
            CacheableTypeOk item = new CacheableTypeOk(3, 1003, "AHA", new DateTime(2010, 10, 02), 8);

            TypeDescription typeDescription =
                ClientSideTypeDescription.RegisterType(typeof(CacheableTypeOk)).AsTypeDescription;

            put.Items.Add(CachedObject.Pack(item));

            RemoveRequest remove = new RemoveRequest(typeof(CacheableTypeOk), typeDescription.MakePrimaryKeyValue(1));

            RegisterTypeRequest register = new RegisterTypeRequest(typeDescription);

            using (MemoryStream stream = new MemoryStream())
            {
                //request
                Streamer.ToStream(stream, new GetRequest(qbuilder.GetManyWhere("IndexKeyValue > 1000")));
                Streamer.ToStream(stream, put);
                Streamer.ToStream(stream, remove);
                Streamer.ToStream(stream, register);

                //response
                Streamer.ToStream(stream, new NullResponse());
                Streamer.ToStream(stream, new ExceptionResponse(new Exception("fake exception")));
                Streamer.ToStream(stream, new ServerDescriptionResponse());

                stream.Seek(0, SeekOrigin.Begin);
                object reloaded = Streamer.FromStream <Request>(stream);
                Assert.IsTrue(reloaded is GetRequest);

                //request
                reloaded = Streamer.FromStream <Request>(stream);
                Assert.IsTrue(reloaded is PutRequest);

                reloaded = Streamer.FromStream <Request>(stream);
                Assert.IsTrue(reloaded is RemoveRequest);

                reloaded = Streamer.FromStream <Request>(stream);
                Assert.IsTrue(reloaded is RegisterTypeRequest);

                ////response
                reloaded = Streamer.FromStream <Response>(stream);
                Assert.IsTrue(reloaded is NullResponse);

                reloaded = Streamer.FromStream <Response>(stream);
                Assert.IsTrue(reloaded is ExceptionResponse);

                reloaded = Streamer.FromStream <Response>(stream);
                Assert.IsTrue(reloaded is ServerDescriptionResponse);
            }
        }
        public void GetManyOnOrderedIndexes()
        {
            var item = new CacheableTypeOk(1, 1001, "AHA", new DateTime(2010, 10, 01), 9);

            _dataStore.InternalAddNew(CachedObject.Pack(item), false);

            item = new CacheableTypeOk(2, 1002, "AHA", new DateTime(2010, 10, 01), 8);
            _dataStore.InternalAddNew(CachedObject.Pack(item), false);

            item = new CacheableTypeOk(3, 1003, "AHA", new DateTime(2010, 10, 02), 8);
            _dataStore.InternalAddNew(CachedObject.Pack(item), false);

            item = new CacheableTypeOk(4, 1004, "BBB", new DateTime(2010, 9, 01), 5);
            _dataStore.InternalAddNew(CachedObject.Pack(item), false);

            item = new CacheableTypeOk(5, 1005, "BBB", new DateTime(2010, 10, 01), 4);
            _dataStore.InternalAddNew(CachedObject.Pack(item), false);

            item = new CacheableTypeOk(6, 1006, "BBA", new DateTime(2010, 10, 01), 1);
            _dataStore.InternalAddNew(CachedObject.Pack(item), false);

            var result =
                _dataStore.InternalGetMany(
                    _typeDescription.MakeIndexKeyValue("IndexKeyDate", new DateTime(2010, 10, 01)),
                    QueryOperator.Le);

            Assert.AreEqual(result.Count, 5);

            result = _dataStore.InternalGetMany(_typeDescription.MakeIndexKeyValue("IndexKeyValue", 8),
                                                QueryOperator.Ge);
            Assert.AreEqual(result.Count, 3);

            _dataStore.RemoveByPrimaryKey(_typeDescription.MakePrimaryKeyValue(2));

            result = _dataStore.InternalGetMany(
                _typeDescription.MakeIndexKeyValue("IndexKeyDate", new DateTime(2010, 10, 01)),
                QueryOperator.Le);
            Assert.AreEqual(result.Count, 4);

            result = _dataStore.InternalGetMany(_typeDescription.MakeIndexKeyValue("IndexKeyValue", 8),
                                                QueryOperator.Ge);
            Assert.AreEqual(result.Count, 2);
        }