public void TestGetPrivateDataQueryResultWithException()
        {
            string        txId = "txId", query = "QUERY", channelId = "myc";
            ChaincodeStub stub  = new ChaincodeStub("myc", "txId", handler.Object, new List <ByteString>(), null);
            QueryResponse value = new QueryResponse {
                HasMore = false
            };

            value.Results.Add(new QueryResultBytes {
                ResultBytes = ByteString.CopyFromUtf8("exception")
            });
            handler.Setup(a => a.GetQueryResultAsync(channelId, txId, "testcoll", query, null, token)).ReturnsAsync(value);
            try
            {
                stub.GetPrivateDataQueryResult("testcoll", query).First();
            }
            catch (Exception e)
            {
                if (e is InvalidProtocolBufferException)
                {
                    throw;
                }
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
                throw;
            }
        }
        public void TestGetPrivateDataQueryResult()
        {
            ChaincodeStub stub = new ChaincodeStub("myc", "txId", handler.Object, new List <ByteString>(), null);

            KV[] keyValues = new KV[] { new KV {
                                            Key = "A", Value = ByteString.CopyFromUtf8("Value of A")
                                        }, new KV {
                                            Key = "B", Value = ByteString.CopyFromUtf8("Value of B")
                                        } };
            QueryResponse value = new QueryResponse {
                HasMore = false
            };

            value.Results.Add(new QueryResultBytes {
                ResultBytes = keyValues[0].ToByteString()
            });
            value.Results.Add(new QueryResultBytes {
                ResultBytes = keyValues[1].ToByteString()
            });
            handler.Setup(a => a.GetQueryResultAsync("myc", "txId", "testcoll", "QUERY", null, token)).ReturnsAsync(value);

            Assert.That.Contains(stub.GetPrivateDataQueryResult("testcoll", "QUERY"), keyValues.Select(a => new KeyValue(a)));

            try
            {
                stub.GetPrivateDataQueryResult(null, "QUERY");
                Assert.Fail("Null collection check fails");
            }
            catch (ArgumentException)
            {
                //ignored
            }

            try
            {
                stub.GetPrivateDataQueryResult("", "QUERY");
                Assert.Fail("Empty collection check fails");
            }
            catch (ArgumentException)
            {
                //ignored
            }
        }