public void TestGetHistoryForKeyWithException() { string txId = "txId", key = "KEY", 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.GetHistoryForKeyAsync(channelId, txId, key, token)).ReturnsAsync(value); try { stub.GetHistoryForKey(key).First(); } catch (Exception e) { if (e is InvalidProtocolBufferException) { throw; } if (e.InnerException != null) { throw e.InnerException; } throw; } }
public void TestGetHistoryForKey() { ChaincodeStub stub = new ChaincodeStub("myc", "txId", handler.Object, new List <ByteString>(), null); KeyModification[] keyValues = new KeyModification[] { new KeyModification { TxId = "tx0", Value = ByteString.CopyFromUtf8("Value A"), Timestamp = new Timestamp() }, new KeyModification { TxId = "tx1", Value = ByteString.CopyFromUtf8("Value B"), Timestamp = new Timestamp() } }; 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.GetHistoryForKeyAsync("myc", "txId", "KEY", token)).ReturnsAsync(value); Assert.That.Contains(stub.GetHistoryForKey("KEY"), keyValues.Select(a => new Shim.Implementation.KeyModification(a))); }