Exemplo n.º 1
0
        public async Task Can_send_acknowledgement_on_version_receiving()
        {
            // Arrange
            var server = new NullServer();

            AutoMockContainer.Register <IServer>(server);

            var messageHandler = AutoMockContainer.Get <VersionMessageHandler>();
            var versionMessage = GetPeerVersionMessage(server);
            var peerMock       = AutoMockContainer.GetMock <IPeer>();

            peerMock.SetupProperty(x => x.Version);

            // Act
            await messageHandler.Handle(versionMessage, peerMock.Object);

            // Assert
            peerMock.Verify(x => x.Send <VerAckMessage>(), Times.Once);
        }
Exemplo n.º 2
0
        public async Task Can_downgrade_protocol_on_version_receiving()
        {
            // Arrange
            var server = new NullServer();

            AutoMockContainer.Register <IServer>(server);

            var messageHandler = AutoMockContainer.Get <VersionMessageHandler>();
            var versionMessage = GetPeerVersionMessage(server);

            server.ProtocolVersion         = 2;
            versionMessage.Payload.Version = 1;

            var peerMock = AutoMockContainer.GetMock <IPeer>();

            peerMock.SetupProperty(x => x.Version);

            // Act
            await messageHandler.Handle(versionMessage, peerMock.Object);

            // Assert
            peerMock.Verify(x => x.DowngradeProtocol(It.IsAny <uint>()), Times.Once);
        }
Exemplo n.º 3
0
        public void Throw_on_the_same_nonce_on_version_receiving()
        {
            // Arrange
            var server = new NullServer();

            AutoMockContainer.Register <IServer>(server);

            var versionMessage = GetPeerVersionMessage(server);

            versionMessage.Payload.Nonce = server.Nonce;

            var peerMock = AutoMockContainer.GetMock <IPeer>();

            peerMock.SetupProperty(x => x.Version);

            var messageHandler = AutoMockContainer.Get <VersionMessageHandler>();

            // Act
            Action a = () => messageHandler.Handle(versionMessage, peerMock.Object).Wait();

            // Assert
            a.Should().Throw <InvalidOperationException>();
        }