コード例 #1
0
        public void DisconnectNode(object sender, NodeAnnoucementEventArgs e)
        {
            string disconnectingNodeId = NodeConnections.Connections.FindNodeIdByAddress(e.Address);

            NodeConnections.Connections.RemoveNodeFromConnections(e.Address);

            MessageWriter.Writer.Message("Node Id {0} at address {1} has disconnected.", disconnectingNodeId, e.Address);
        }
コード例 #2
0
        public void AHandShakeErrorAfterADelayWillAttemptHandShakeAgain()
        {
            StubHelpers(HelperFlags.Address);
            IServiceHostHelper serviceHostHelper = StubServiceHostHelper();

            var announcementService = Mocks.DynamicMock<IAnnouncementService>();

            IPAddress ipAddress = IPAddress.Parse("55.55.55.55");

            var args = new NodeAnnoucementEventArgs
                           {
                               Address = ipAddress
                           };

            var nodeConnections = Mocks.DynamicMock<INodeConnections>();

            nodeConnections.Expect(v => v.AddNodeToConnections(ipAddress)).Return(NodeConnectionStatus.ErrorInHandShake).Repeat.Twice();
            nodeConnections.Expect(v => v.FindNodeIdByAddress(ipAddress)).IgnoreArguments().Repeat.Never();

            var messageWriter = Mocks.DynamicMock<IMessageWriter>();

            messageWriter.Expect(v => v.Message("An error in handshake with node at {0}.", ipAddress));

            var timeHelper = Mocks.DynamicMock<ITimeHelper>();

            timeHelper.Expect(v => v.Sleep(250));

            TimeHelper.Helper = timeHelper;

            Mocks.ReplayAll();

            NodeConnections.Connections = nodeConnections;
            MessageWriter.Writer = messageWriter;

            var connectionHandler = new ConnectionsHandler(NodeId)
                                        {
                                            AnnouncementService = announcementService,
                                            ServiceHostHelper = serviceHostHelper
                                        };

            connectionHandler.Start();

            announcementService.Raise(v => v.OnOnlineEvent += null, this, args);

            Mocks.ReplayAll();

            NodeConnections.Connections = nodeConnections;
        }
コード例 #3
0
        public void ConnectNode(object sender, NodeAnnoucementEventArgs eventArgs)
        {
            AddToConnections(eventArgs.Address);

            ResetConnectionAttempts();
        }
コード例 #4
0
        public void OnSuccessfullyConnectionAMessageWillBeSentToMessageWriter()
        {
            StubHelpers(HelperFlags.Address);
            IServiceHostHelper serviceHostHelper = StubServiceHostHelper();

            var announcementService = Mocks.DynamicMock<IAnnouncementService>();

            IPAddress ipAddress = IPAddress.Parse("55.55.55.55");

            var args = new NodeAnnoucementEventArgs
                           {
                               Address = ipAddress
                           };

            var nodeConnections = Mocks.DynamicMock<INodeConnections>();

            nodeConnections.Expect(v => v.AddNodeToConnections(ipAddress)).Return(NodeConnectionStatus.Connected);
            nodeConnections.Expect(v => v.FindNodeIdByAddress(ipAddress)).Return("Node2");

            var messageWriter = Mocks.DynamicMock<IMessageWriter>();

            messageWriter.Expect(v => v.Message("A node with Id '{0}' connected from address {1}", "Node2", ipAddress));

            Mocks.ReplayAll();

            NodeConnections.Connections = nodeConnections;
            MessageWriter.Writer = messageWriter;

            var connectionHandler = new ConnectionsHandler(NodeId)
                                        {
                                            AnnouncementService = announcementService,
                                            ServiceHostHelper = serviceHostHelper
                                        };

            connectionHandler.Start();

            announcementService.Raise(v => v.OnOnlineEvent += null, this, args);

            Mocks.ReplayAll();
        }
コード例 #5
0
        public void OnConnectionEventTheNodeWillBeAddedToConnections()
        {
            StubHelpers(HelperFlags.Address);
            IServiceHostHelper serviceHostHelper = StubServiceHostHelper();

            var announcementService = Mocks.DynamicMock<IAnnouncementService>();

            IPAddress ipAddress = IPAddress.Parse("55.55.55.55");

            var args = new NodeAnnoucementEventArgs
                           {
                               Address = ipAddress
                           };

            var nodeConnections = Mocks.DynamicMock<INodeConnections>();

            nodeConnections.Expect(v => v.AddNodeToConnections(ipAddress)).Return(NodeConnectionStatus.Connected);

            Mocks.ReplayAll();

            NodeConnections.Connections = nodeConnections;

            var connectionHandler = new ConnectionsHandler(NodeId)
                                        {
                                            AnnouncementService = announcementService,
                                            ServiceHostHelper = serviceHostHelper
                                        };

            connectionHandler.Start();

            announcementService.Raise(v => v.OnOnlineEvent += null, this, args);

            Mocks.ReplayAll();
        }
コード例 #6
0
        public void OnANodeDisconnectNodeWillBeWrittenToStatusWriter()
        {
            StubAddressHelper();

            var announcementService = Mocks.DynamicMock<IAnnouncementService>();

            announcementService.OnOfflineEvent += null;
            LastCall.IgnoreArguments();

            announcementService.OnOnlineEvent += null;
            LastCall.IgnoreArguments();

            IPAddress ipAddress = IPAddress.Parse("55.55.55.55");

            var nodeConnections = Mocks.DynamicMock<INodeConnections>();

            nodeConnections.Expect(v => v.FindNodeIdByAddress(ipAddress)).Return("Node2");
            nodeConnections.Expect(v => v.RemoveNodeFromConnections(ipAddress));

            var messageWriter = Mocks.DynamicMock<IMessageWriter>();

            messageWriter.Expect(v => v.Message("Node Id {0} at address {1} has disconnected.", "Node2", ipAddress));

            var args = new NodeAnnoucementEventArgs
                           {
                               Address = ipAddress
                           };

            Mocks.ReplayAll();

            NodeConnections.Connections = nodeConnections;
            MessageWriter.Writer = messageWriter;

            var connectionHandler = new ConnectionsHandler(NodeId)
                                        {
                                            AnnouncementService = announcementService
                                        };

            connectionHandler.Start();

            announcementService.Raise(v => v.OnOfflineEvent += null, this, args);

            Mocks.ReplayAll();

            NodeConnections.Connections = nodeConnections;
        }
コード例 #7
0
        public void OnANodeDisconnectNodeWillBeRemovedFromConnections()
        {
            StubAddressHelper();

            var announcementService = Mocks.DynamicMock<IAnnouncementService>();

            announcementService.OnOfflineEvent += null;
            LastCall.IgnoreArguments();

            announcementService.OnOnlineEvent += null;
            LastCall.IgnoreArguments();

            IPAddress ipAddress = IPAddress.Parse("55.55.55.55");

            var nodeConnections = Mocks.DynamicMock<INodeConnections>();

            nodeConnections.Expect(v => v.RemoveNodeFromConnections(ipAddress));

            var args = new NodeAnnoucementEventArgs
                           {
                               Address = ipAddress
                           };

            Mocks.ReplayAll();

            NodeConnections.Connections = nodeConnections;

            ConnectionsHandler connectionHandler = CreateConnectionsHandler();

            connectionHandler.AnnouncementService = announcementService;

            connectionHandler.Start();

            announcementService.Raise(v => v.OnOfflineEvent += null, this, args);

            Mocks.ReplayAll();
        }
コード例 #8
0
        public void IfANodeIsAlreadyConnectedAMessageIsWritten()
        {
            StubHelpers(HelperFlags.Address);
            IServiceHostHelper serviceHostHelper = StubServiceHostHelper();

            var announcementService = Mocks.DynamicMock<IAnnouncementService>();

            IPAddress ipAddress = IPAddress.Parse("55.55.55.55");

            var args = new NodeAnnoucementEventArgs
                           {
                               Address = ipAddress
                           };

            var nodeConnections = Mocks.DynamicMock<INodeConnections>();

            nodeConnections.Expect(v => v.AddNodeToConnections(ipAddress)).Return(NodeConnectionStatus.AlreadyConnected);
            nodeConnections.Expect(v => v.FindNodeIdByAddress(ipAddress)).Return("Node2");

            var messageWriter = Mocks.DynamicMock<IMessageWriter>();

            messageWriter.Expect(v => v.Message("A node from address {0} is already connected with an Id of {1}.", ipAddress, "Node2"));

            Mocks.ReplayAll();

            NodeConnections.Connections = nodeConnections;
            MessageWriter.Writer = messageWriter;

            var connectionHandler = new ConnectionsHandler(NodeId)
                                        {
                                            AnnouncementService = announcementService,
                                            ServiceHostHelper = serviceHostHelper
                                        };

            connectionHandler.Start();

            announcementService.Raise(v => v.OnOnlineEvent += null, this, args);

            Mocks.ReplayAll();

            NodeConnections.Connections = nodeConnections;
        }
コード例 #9
0
        public void IfANodeCannotBeConnectedToAMessageWritten()
        {
            StubHelpers(HelperFlags.Address);
            IServiceHostHelper serviceHostHelper = StubServiceHostHelper();

            var announcementService = Mocks.DynamicMock<IAnnouncementService>();

            IPAddress ipAddress = IPAddress.Parse("55.55.55.55");

            var args = new NodeAnnoucementEventArgs
                           {
                               Address = ipAddress
                           };

            var nodeConnections = Mocks.DynamicMock<INodeConnections>();

            nodeConnections.Expect(v => v.AddNodeToConnections(ipAddress)).Return(NodeConnectionStatus.CouldNotConnect);
            nodeConnections.Expect(v => v.FindNodeIdByAddress(ipAddress)).IgnoreArguments().Repeat.Never();

            var messageWriter = Mocks.DynamicMock<IMessageWriter>();

            messageWriter.Expect(v => v.Message("A node from address {0} could not be connected.", ipAddress));

            Mocks.ReplayAll();

            NodeConnections.Connections = nodeConnections;
            MessageWriter.Writer = messageWriter;

            var connectionHandler = new ConnectionsHandler(NodeId)
                                        {
                                            AnnouncementService = announcementService,
                                            ServiceHostHelper = serviceHostHelper
                                        };

            connectionHandler.Start();

            announcementService.Raise(v => v.OnOnlineEvent += null, this, args);

            Mocks.ReplayAll();

            NodeConnections.Connections = nodeConnections;
        }
コード例 #10
0
 private void OnOnlineEvent(object sender, NodeAnnoucementEventArgs e)
 {
 }