public void HandleInvokeChaincode_throws_an_exception_when_response_is_of_type_error() { QueueMessage <ChaincodeMessage> queuedMessage = null; var messageQueueMock = new Mock <IMessageQueue>(); messageQueueMock.Setup(m => m.QueueMessage(It.IsAny <QueueMessage>())) .Callback <QueueMessage>(message => queuedMessage = message as QueueMessage <ChaincodeMessage>); var messageQueueFactoryMock = new Mock <IMessageQueueFactory>(); messageQueueFactoryMock.Setup(m => m.Create(It.IsAny <global::Thinktecture.HyperledgerFabric.Chaincode.NET.Handler.Handler>())) .Returns(messageQueueMock.Object); var handler = CreateHandlerWithChainsupportClientFactory(messageQueueFactoryMock.Object); var task = handler.HandleInvokeChaincode("ChaincodeName", new ByteString[0], "ChannelId", "TxId"); queuedMessage.Should().NotBeNull(); queuedMessage.Success(new ChaincodeMessage { Type = ChaincodeMessage.Types.Type.Error, Payload = "unittest".ToByteString() }); Func <Task> act = async() => await task; act.Should().Throw <Exception>() .WithMessage("unittest"); }
public async void HandleInvokeChaincode_returns_a_response() { QueueMessage <ChaincodeMessage> queuedMessage = null; var messageQueueMock = new Mock <IMessageQueue>(); messageQueueMock.Setup(m => m.QueueMessage(It.IsAny <QueueMessage>())) .Callback <QueueMessage>(message => queuedMessage = message as QueueMessage <ChaincodeMessage>); var messageQueueFactoryMock = new Mock <IMessageQueueFactory>(); messageQueueFactoryMock.Setup(m => m.Create(It.IsAny <global::Thinktecture.HyperledgerFabric.Chaincode.NET.Handler.Handler>())) .Returns(messageQueueMock.Object); var handler = CreateHandlerWithChainsupportClientFactory(messageQueueFactoryMock.Object); var task = handler.HandleInvokeChaincode("ChaincodeName", new ByteString[0], "ChannelId", "TxId"); queuedMessage.Should().NotBeNull(); queuedMessage.Success(new ChaincodeMessage { Type = ChaincodeMessage.Types.Type.Completed, Payload = new Response { Message = "unittest" }.ToByteString() }); var result = await task; result.Message.Should().Be("unittest"); }