Inheritance: IConnectionManager
 public void MonitoringTest()
 {
     m_SiblingProxyMock.Setup(m => m.Ping()).Verifiable();
     var connectionManager = new ConnectionManager();
     connectionManager.OpenOutcomingConnections();
     Thread.Sleep(100);
     m_SiblingProxyMock.Verify();
 }
        public void CloseOutcommingConnectionsTest()
        {
            m_SiblingProxyMock.Setup(m => m.Close()).Verifiable();

            var connectionManager = new ConnectionManager();
            connectionManager.CloseOutcomingConnections();

            m_SiblingProxyMock.Verify();
        }
        public void MonitoringInterruptedTest()
        {
            m_SiblingProxyMock.Setup(m => m.Ping()).Verifiable();
            var connectionManager = new ConnectionManager();
            connectionManager.OpenOutcomingConnections();
            Thread.Sleep(100);
            m_SiblingProxyMock.Verify();

            connectionManager.CloseOutcomingConnections();
            m_SiblingProxyMock.Setup(m => m.Ping()).Throws(new AssertionException("Ping after connection closed"));
            Thread.Sleep(100);
        }
        public void LostConnectionTest()
        {
            m_SiblingProxyMock.Setup(m => m.Ping()).Throws<ConnectionErrorException>().Verifiable();
            m_SiblingMock.SetupGet(m => m.ServerId).Returns(123);
            var connectionManager = new ConnectionManager();

            var lostId = 0;
            connectionManager.OnConnectionLoss += (id) => { lostId = id; };

            connectionManager.OpenOutcomingConnections();
            Thread.Sleep(100);
            Assert.AreEqual(lostId, 123);
        }
        public void TryReplicate_ConnectionLost_Test()
        {
            //Assert.Fail("Change CommunicationException by some more generic");

            m_SiblingProxyMock.Setup(m => m.Open()).Verifiable("Server hasn't opened connections before replication");
            m_SiblingProxyMock.Setup(m => m.Push("a", 123, "b")).Throws(new ConnectionErrorException()); // it's the only place in assembly that requires ServiceModel lib

            var connectionManager = new ConnectionManager();
            var connectionLostFired = false;
            connectionManager.OnConnectionLoss += (id) => { connectionLostFired = true; };
            connectionManager.OpenOutcomingConnections();
            Assert.IsFalse(connectionManager.TryReplicate("a", 123, "b"));

            m_SiblingProxyMock.Verify();
            Assert.IsTrue(connectionLostFired);
        }
        public void TryReplicate_Success_Test()
        {
            m_SiblingProxyMock.Setup(m => m.Open()).Verifiable("Server hasn't opened connections before replication");
            m_SiblingProxyMock.Setup(m => m.Push("a", 123, "b")).Verifiable("Server hasn't pushed data to siblings");

            var connectionManager = new ConnectionManager();
            connectionManager.OpenOutcomingConnections();
            Assert.IsTrue(connectionManager.TryReplicate("a", 123, "b"));

            m_SiblingProxyMock.Verify();
        }
        public void TryReplicate_GeneralError_Test()
        {
            m_SiblingProxyMock.Setup(m => m.Open()).Verifiable("Server hasn't opened connections before replication");
            m_SiblingProxyMock.Setup(m => m.Push("a", 123, "b")).Throws(new Exception());

            var connectionManager = new ConnectionManager();
            var connectionLostFired = false;
            connectionManager.OnConnectionLoss += (id) => { connectionLostFired = true; };
            connectionManager.OpenOutcomingConnections();
            Assert.IsFalse(connectionManager.TryReplicate("a", 123, "b"));

            m_SiblingProxyMock.Verify();
            Assert.IsFalse(connectionLostFired);
        }
 public MonitoringThread(ConnectionManager manager)
     : base("ConnectionMonitoring")
 {
     m_Manager = manager;
 }