private Task <QueryResponse> PrepareQueryResponseAsync(CancellationToken token)
        {
            QueryResponseMetadata qrm = new QueryResponseMetadata {
                Bookmark = "asdf", FetchedRecordsCount = 2
            };

            return(Task.FromResult(new QueryResponse {
                HasMore = false, Metadata = qrm.ToByteString()
            }));
        }
        private QueryResponse PrepareQueryResponseForRange(KV[] keyValues, bool createMetadata)
        {
            QueryResponse qr = new QueryResponse {
                HasMore = false
            };

            qr.Results.AddRange(keyValues.Select(a => new QueryResultBytes {
                ResultBytes = a.ToByteString()
            }));
            if (createMetadata)
            {
                QueryResponseMetadata qrm = new QueryResponseMetadata {
                    Bookmark = "bbbb", FetchedRecordsCount = 2
                };
                qr.Metadata = qrm.ToByteString();
            }

            return(qr);
        }
        private ChaincodeStub PrepareStubAndMockHandler(bool createMetadata, ByteString metadata)
        {
            ChaincodeStub stub = new ChaincodeStub("myc", "txId", handler.Object, new List <ByteString>(), null);

            KV[] keyValues = PrepareKeyValuePairs(2);

            QueryResponse value = new QueryResponse {
                HasMore = false
            };

            value.Results.AddRange(keyValues.Select(a => new QueryResultBytes {
                ResultBytes = a.ToByteString()
            }));
            if (createMetadata)
            {
                QueryResponseMetadata qrm = new QueryResponseMetadata {
                    Bookmark = "bbbb", FetchedRecordsCount = 2
                };
                value.Metadata = qrm.ToByteString();
            }

            handler.Setup((a) => a.GetStateByRangeAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.Is <ByteString>(b => (b == null && metadata == null) || (b.Equals(metadata))), token)).ReturnsAsync(value);
            return(stub);
        }