public void RpcClientChannelFactory_should_put_the_correct_inbound_handlers_on_the_pipeline() { var testingChannel = new EmbeddedChannel("test".ToChannelId(), true, _factory.InheritedHandlers.ToArray()); var senderId = PeerIdHelper.GetPeerId("sender"); var correlationId = CorrelationId.GenerateCorrelationId(); var signatureBytes = ByteUtil.GenerateRandomByteArray(new FfiWrapper().SignatureLength); var protocolMessage = new PingResponse() .ToSignedProtocolMessage(senderId, signatureBytes, correlationId: correlationId); _keySigner.Verify(Arg.Any <ISignature>(), Arg.Any <byte[]>(), Arg.Any <SigningContext>()) .Returns(true); _correlationManager.TryMatchResponse(protocolMessage).Returns(true); var observer = new ProtocolMessageObserver(0, Substitute.For <ILogger>()); var messageStream = _factory.InheritedHandlers.OfType <ObservableServiceHandler>().Single().MessageStream; using (messageStream.Subscribe(observer)) { testingChannel.WriteInbound(protocolMessage); _correlationManager.Received(1).TryMatchResponse(protocolMessage); _keySigner.ReceivedWithAnyArgs(1).Verify(null, null, null); _testScheduler.Start(); observer.Received.Count.Should().Be(1); observer.Received.Single().Payload.CorrelationId.ToCorrelationId().Id.Should().Be(correlationId.Id); } }
RpcServerChannelFactory_Pipeline_Should_Produce_Response_Object_RpcClientChannelFactory_Can_Process() { var recipient = PeerIdHelper.GetPeerId("recipient"); var sender = PeerIdHelper.GetPeerId("sender"); var signature = Substitute.For <ISignature>(); _peerIdValidator.ValidatePeerIdFormat(Arg.Any <PeerId>()).Returns(true); _serverKeySigner.Sign(Arg.Any <byte[]>(), default).ReturnsForAnyArgs(signature); var correlationId = CorrelationId.GenerateCorrelationId(); var protocolMessage = new GetPeerCountResponse().ToProtocolMessage(sender, correlationId); var dto = new MessageDto( protocolMessage, recipient ); _clientCorrelationManager.TryMatchResponse(Arg.Any <ProtocolMessage>()).Returns(true); _serverChannel.WriteOutbound(dto); var sentBytes = _serverChannel.ReadOutbound <IByteBuffer>(); _serverCorrelationManager.DidNotReceiveWithAnyArgs().AddPendingRequest(Arg.Any <CorrelatableMessage <ProtocolMessage> >()); _serverKeySigner.ReceivedWithAnyArgs(1) .Sign(Arg.Any <byte[]>(), default); _clientKeySigner.Verify( Arg.Any <ISignature>(), Arg.Any <byte[]>(), default) .ReturnsForAnyArgs(true); _authenticationStrategy.Authenticate(Arg.Any <PeerId>()).Returns(true); var observer = new ProtocolMessageObserver(0, Substitute.For <ILogger>()); var messageStream = _clientFactory.InheritedHandlers.OfType <ObservableServiceHandler>().Single().MessageStream; using (messageStream.Subscribe(observer)) { _clientChannel.WriteInbound(sentBytes); _clientChannel.ReadInbound <ProtocolMessage>(); _clientCorrelationManager.ReceivedWithAnyArgs(1).TryMatchResponse(Arg.Any <ProtocolMessage>()); _clientKeySigner.ReceivedWithAnyArgs(1).Verify(null, null, null); _testScheduler.Start(); observer.Received.Count.Should().Be(1); observer.Received.Single().Payload.CorrelationId.ToCorrelationId().Id.Should().Be(correlationId.Id); } await _serverChannel.DisconnectAsync(); await _clientChannel.DisconnectAsync(); }