public void TestGetStateByPartialCompositeKeyWithPagination()
        {
            QueryMetadata queryMetadata = new QueryMetadata {
                Bookmark = "aaaa", PageSize = 1
            };

            ChaincodeStub stub = PrepareStubAndMockHandler(true, queryMetadata.ToByteString());

            CompositeKey key = new CompositeKey("KEY");
            IQueryResultsEnumerable <IKeyValue> queryResultsIterator = stub.GetStateByPartialCompositeKeyWithPagination(key, 1, "aaaa");

            queryResultsIterator.First(); //Otherwise GetStateByRangeAsync will not be executed, that Or GetMetadata()
            handler.Verify(a => a.GetStateByRangeAsync("myc", "txId", "", key.ToString(), key.ToString() + "\udbff\udfff", queryMetadata.ToByteString(), It.IsAny <CancellationToken>()));
            Assert.AreEqual(queryResultsIterator.GetMetadata().FetchedRecordsCount, 2);
            Assert.AreEqual(queryResultsIterator.GetMetadata().Bookmark, "bbbb");


            key = new CompositeKey("");
            queryResultsIterator = stub.GetStateByPartialCompositeKeyWithPagination(key, 1, "aaaa");
            queryResultsIterator.First(); //Otherwise GetStateByRangeAsync will not be executed, that Or GetMetadata()

            handler.Verify(a => a.GetStateByRangeAsync("myc", "txId", "", key.ToString(), key.ToString() + "\udbff\udfff", queryMetadata.ToByteString(), It.IsAny <CancellationToken>()));
            Assert.AreEqual(queryResultsIterator.GetMetadata().FetchedRecordsCount, 2);
            Assert.AreEqual(queryResultsIterator.GetMetadata().Bookmark, "bbbb");
        }
Ejemplo n.º 2
0
        public IAsyncQueryResultsEnumerable <IKeyValue> GetStateByRangeWithPaginationAsync(string startKey, string endKey, int pageSize, string bookmark)
        {
            if (string.IsNullOrEmpty(startKey))
            {
                startKey = UNSPECIFIED_KEY;
            }
            if (string.IsNullOrEmpty(endKey))
            {
                endKey = UNSPECIFIED_KEY;
            }

            CompositeKey.ValidateSimpleKeys(startKey, endKey);

            QueryMetadata queryMetadata = new QueryMetadata {
                Bookmark = bookmark, PageSize = pageSize
            };

            return(ExecuteGetStateByRangeWithMetadata("", startKey, endKey, queryMetadata.ToByteString()));
        }
Ejemplo n.º 3
0
        public IAsyncQueryResultsEnumerable <IKeyValue> GetQueryResultWithPaginationAsync(string query, int pageSize, string bookmark)
        {
            QueryMetadata queryMetadata = new QueryMetadata {
                Bookmark = bookmark, PageSize = pageSize
            };

            return(new AsyncQueryResultsEnumerable <IKeyValue>(handler, ChannelId, TxId,
                                                               (token) => handler.GetQueryResultAsync(ChannelId, TxId, "", query, queryMetadata.ToByteString(), token),
                                                               qv => new KeyValue(KV.Parser.ParseFrom(qv.ResultBytes))));
        }
Ejemplo n.º 4
0
        public IAsyncQueryResultsEnumerable <IKeyValue> GetStateByPartialCompositeKeyWithPaginationAsync(CompositeKey compositeKey, int pageSize, string bookmark)
        {
            if (compositeKey == null)
            {
                compositeKey = new CompositeKey(UNSPECIFIED_KEY);
            }

            string cKeyAsString = compositeKey.ToString();

            QueryMetadata queryMetadata = new QueryMetadata {
                Bookmark = bookmark, PageSize = pageSize
            };

            return(ExecuteGetStateByRangeWithMetadata("", cKeyAsString, cKeyAsString + MAX_UNICODE_RUNE, queryMetadata.ToByteString()));
        }
        public void TestGetStateByRangeWithPagination()
        {
            ChaincodeStub stub     = new ChaincodeStub("myc", "txId", handler.Object, new List <ByteString>(), null);
            string        startKey = "START";
            string        endKey   = "END";

            KV[]          keyValues = PrepareKeyValuePairs(2);
            QueryResponse value     = PrepareQueryResponseForRange(keyValues, true);


            QueryMetadata queryMetadata = new QueryMetadata {
                Bookmark = "aaaa", PageSize = 1
            };

            handler.Setup((a) => a.GetStateByRangeAsync("myc", "txId", "", startKey, endKey, queryMetadata.ToByteString(), token)).ReturnsAsync(value);
            IQueryResultsEnumerable <IKeyValue> queryResultsIterator = stub.GetStateByRangeWithPagination(startKey, endKey, 1, "aaaa");

            Assert.That.Contains(queryResultsIterator, keyValues.Select(a => new KeyValue(a)));
            Assert.AreEqual(queryResultsIterator.GetMetadata().FetchedRecordsCount, 2);
            Assert.AreEqual(queryResultsIterator.GetMetadata().Bookmark, "bbbb");
        }