public void RemoveConnection_WhenBrokerIsInList_ShouldRemoveBroker()
        {
            var sut = new BrokerConnectionManager();

            // Act
            sut.AddConnection("conn1", 1, new DateTime(2010, 10, 10, 10, 10, 10));
            sut.AddConnection("conn2", 1, new DateTime(2010, 10, 10, 10, 10, 10));
            sut.RemoveConnection("conn1");

            // Assert
            Assert.AreEqual(sut.NumberOfConnectedBrokers, 1);
        }
        public void RemoveConnection_WhenBrokerIsInList_ShouldRemoveBroker()
        {
            var sut = new BrokerConnectionManager();

            // Act
            sut.AddConnection("conn1", 1, new DateTime(2010, 10, 10, 10, 10, 10));
            sut.AddConnection("conn2", 1, new DateTime(2010, 10, 10, 10, 10, 10));
            sut.RemoveConnection("conn1");

            // Assert
            Assert.AreEqual(sut.NumberOfConnectedBrokers, 1);
        }
        public void AddConnection_WhenBrokerIsAlreadyInList_ShouldAddNewBrokerConnection()
        {
            // Arrange
            var sut = new BrokerConnectionManager();

            // Act
            sut.AddConnection("conn1", 1, new DateTime(2010, 10, 10, 10, 10, 10));
            sut.AddConnection("conn2", 1, new DateTime(2010, 10, 10, 10, 10, 10));

            // Assert
            Assert.AreEqual(sut.NumberOfConnectedBrokers, 1);
        }
        public void AddConnection_WhenBrokerIsAlreadyInList_ShouldAddNewBrokerConnection()
        {
            // Arrange
            var sut = new BrokerConnectionManager();

            // Act
            sut.AddConnection("conn1", 1, new DateTime(2010, 10, 10, 10, 10, 10));
            sut.AddConnection("conn2", 1, new DateTime(2010, 10, 10, 10, 10, 10));

            // Assert
            Assert.AreEqual(sut.NumberOfConnectedBrokers, 1);
        }
        public void ActiveBrokerTokenIsDueToExpire_WhenMostRecentConnectionsTokenHasLessThan5Minutes_ShouldReturnTrue()
        {
            var sut = new BrokerConnectionManager();

            sut.AddConnection("oldconn1", 1, new DateTime(2010, 10, 10, 10, 10, 10));
            sut.AddConnection("oldconn2", 1, new DateTime(2011, 10, 10, 10, 10, 10));
            sut.AddConnection("newestConn", 1, DateTime.Now.AddMinutes(2));

            // Act
            var result = sut.ActiveBrokerTokenIsDueToExpire(1);

            // Assert
            Assert.IsTrue(result);
        }
        public void NumberOfConnectionBrokers_ShouldReturnNumberOfConnectedBrokers()
        {
            var sut = new BrokerConnectionManager();

            sut.AddConnection("conn1", 1, new DateTime(2010, 10, 10, 10, 10, 10));
            sut.AddConnection("conn2", 2, new DateTime(2011, 10, 10, 10, 10, 10));
            sut.AddConnection("conn", 1, DateTime.Now.AddMinutes(6));

            // Act
            var result = sut.NumberOfConnectedBrokers;

            // Assert
            Assert.AreEqual(result, 2);
        }
        public void ActiveBrokerTokenIsDueToExpire_WhenBrokerIsNotInList_ShouldThrowApplicationException()
        {
            var sut = new BrokerConnectionManager();

            sut.AddConnection("oldconn1", 1, new DateTime(2010, 10, 10, 10, 10, 10));
            sut.AddConnection("oldconn2", 1, new DateTime(2011, 10, 10, 10, 10, 10));
            sut.AddConnection("newestConn", 1, DateTime.Now.AddMinutes(6));

            // Act
            var exception = Assert.Throws <ApplicationException>(() => sut.ActiveBrokerTokenIsDueToExpire(2));

            // Assert
            Assert.AreEqual("Cannot find Broker in list of connections", exception.Message);
        }
        public void IsBrokerConnected_WhenBrokerIsInList_ShouldReturnTrue()
        {
            // Arrange
            var sut = new BrokerConnectionManager();
            sut.AddConnection("conn1", 1, new DateTime(2010, 10, 10, 10, 10, 10));

            // Act
            var result = sut.IsBrokerConnected(1);

            // Assert
            Assert.IsTrue(result);
        }
        public void IsBrokerConnected_WhenBrokerIsInList_ShouldReturnTrue()
        {
            // Arrange
            var sut = new BrokerConnectionManager();

            sut.AddConnection("conn1", 1, new DateTime(2010, 10, 10, 10, 10, 10));

            // Act
            var result = sut.IsBrokerConnected(1);

            // Assert
            Assert.IsTrue(result);
        }
        public void ActiveBrokerTokenIsDueToExpire_WhenMostRecentConnectionsTokenHasLessThan5Minutes_ShouldReturnTrue()
        {
            var sut = new BrokerConnectionManager();

            sut.AddConnection("oldconn1", 1, new DateTime(2010, 10, 10, 10, 10, 10));
            sut.AddConnection("oldconn2", 1, new DateTime(2011, 10, 10, 10, 10, 10));
            sut.AddConnection("newestConn", 1, DateTime.Now.AddMinutes(2));

            // Act
            var result = sut.ActiveBrokerTokenIsDueToExpire(1);

            // Assert
            Assert.IsTrue(result);
        }
        public void NumberOfConnectionBrokers_ShouldReturnNumberOfConnectedBrokers()
        {
            var sut = new BrokerConnectionManager();

            sut.AddConnection("conn1", 1, new DateTime(2010, 10, 10, 10, 10, 10));
            sut.AddConnection("conn2", 2, new DateTime(2011, 10, 10, 10, 10, 10));
            sut.AddConnection("conn", 1, DateTime.Now.AddMinutes(6));

            // Act
            var result = sut.NumberOfConnectedBrokers;

            // Assert
            Assert.AreEqual(result, 2);
        }
        public void ActiveBrokerTokenIsDueToExpire_WhenBrokerIsNotInList_ShouldThrowApplicationException()
        {
            var sut = new BrokerConnectionManager();

            sut.AddConnection("oldconn1", 1, new DateTime(2010, 10, 10, 10, 10, 10));
            sut.AddConnection("oldconn2", 1, new DateTime(2011, 10, 10, 10, 10, 10));
            sut.AddConnection("newestConn", 1, DateTime.Now.AddMinutes(6));

            // Act
            var exception = Assert.Throws<ApplicationException>(() => sut.ActiveBrokerTokenIsDueToExpire(2));

            // Assert
            Assert.AreEqual("Cannot find Broker in list of connections", exception.Message);
        }