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();
        }
Example #2
0
        public void GetPeerCountResponse_Can_Get_Output()
        {
            //Arrange
            var getPeerCountResponse = new GetPeerCountResponse {
                PeerCount = 50
            };
            var commandContext      = TestCommandHelpers.GenerateCliResponseCommandContext(_testScheduler);
            var getPeerCountCommand = new PeerCountCommand(commandContext, Substitute.For <ILogger>());

            //Act
            TestCommandHelpers.GenerateResponse(commandContext, getPeerCountResponse);

            _testScheduler.Start();

            //Assert
            commandContext.UserOutput.Received(1).WriteLine(getPeerCountResponse.ToJsonString());
        }