Exemplo n.º 1
0
        public void when_adding_new_client_then_connection_list_increases()
        {
            ConnectionProvider provider = new ConnectionProvider();

            int    existingClients = provider.Connections;
            string clientId        = Guid.NewGuid().ToString();

            provider.AddConnection(clientId, Mock.Of <IMqttChannel <IPacket> >(c => c.IsConnected == true));
            provider.Connections.Should().Be(existingClients + 1);
        }
        public void when_adding_disconnected_client_then_active_clients_list_does_not_increases()
        {
            var provider = new ConnectionProvider();

            var existingClients = provider.ActiveClients.Count();
            var clientId        = Guid.NewGuid().ToString();

            provider.AddConnection(clientId, Mock.Of <IMqttChannel <IPacket> > (c => c.IsConnected == false));

            Assert.Equal(existingClients, provider.ActiveClients.Count());
        }
        public void when_adding_new_client_then_connection_list_increases()
        {
            var provider = new ConnectionProvider();

            var existingClients = provider.Connections;
            var clientId        = Guid.NewGuid().ToString();

            provider.AddConnection(clientId, Mock.Of <IMqttChannel <IPacket> > (c => c.IsConnected == true));

            Assert.Equal(existingClients + 1, provider.Connections);
        }
        public void when_getting_connection_from_disconnected_client_then_no_connection_is_returned()
        {
            var provider = new ConnectionProvider();
            var clientId = Guid.NewGuid().ToString();

            provider.AddConnection(clientId, Mock.Of <IMqttChannel <IPacket> > (c => c.IsConnected == false));

            var connection = provider.GetConnection(clientId);

            Assert.Null(connection);
        }
        public void when_getting_connection_from_client_then_succeeds()
        {
            var provider = new ConnectionProvider();
            var clientId = Guid.NewGuid().ToString();

            provider.AddConnection(clientId, Mock.Of <IMqttChannel <IPacket> > (c => c.IsConnected == true));

            var connection = provider.GetConnection(clientId);

            Assert.NotNull(connection);
        }
Exemplo n.º 6
0
        public void when_adding_disconnected_client_then_active_clients_list_does_not_increases()
        {
            ConnectionProvider provider = new ConnectionProvider();

            int    existingClients = provider.ActiveClients.Count();
            string clientId        = Guid.NewGuid().ToString();

            provider.AddConnection(clientId, Mock.Of <IMqttChannel <IPacket> >(c => c.IsConnected == false));

            provider.ActiveClients.Should().HaveCount(existingClients);
        }
        public void when_adding_existing_client_id_then_existing_client_is_disconnected()
        {
            var provider = new ConnectionProvider();

            var receiver1 = new Subject <IPacket> ();
            var channel1  = new Mock <IMqttChannel <IPacket> > ();

            channel1.Setup(c => c.ReceiverStream).Returns(receiver1);
            channel1.Setup(c => c.IsConnected).Returns(true);

            var receiver2 = new Subject <IPacket> ();
            var channel2  = new Mock <IMqttChannel <IPacket> > ();

            channel2.Setup(c => c.ReceiverStream).Returns(receiver2);
            channel2.Setup(c => c.IsConnected).Returns(true);

            var clientId = Guid.NewGuid().ToString();

            provider.AddConnection(clientId, channel1.Object);
            provider.AddConnection(clientId, channel2.Object);

            channel1.Verify(c => c.Dispose());
            channel2.Verify(c => c.Dispose(), Times.Never);
        }
        public void when_removing_private_connection_then_private_client_list_decreases()
        {
            var provider = new ConnectionProvider();

            var clientId = Guid.NewGuid().ToString();

            provider.AddConnection(clientId, Mock.Of <IMqttChannel <IPacket> > (c => c.IsConnected == true));
            provider.RegisterPrivateClient(clientId);

            var previousPrivateClients = provider.PrivateClients.Count();

            provider.RemoveConnection(clientId);

            var currentPrivateClients = provider.PrivateClients.Count();

            Assert.Equal(previousPrivateClients - 1, currentPrivateClients);
        }
Exemplo n.º 9
0
        public void when_removing_private_connection_then_private_client_list_decreases()
        {
            ConnectionProvider provider = new ConnectionProvider();

            string clientId = Guid.NewGuid().ToString();

            provider.AddConnection(clientId, Mock.Of <IMqttChannel <IPacket> >(c => c.IsConnected == true));
            provider.RegisterPrivateClient(clientId);

            int previousPrivateClients = provider.PrivateClients.Count();

            provider.RemoveConnection(clientId);

            int currentPrivateClients = provider.PrivateClients.Count();

            currentPrivateClients.Should().Be(previousPrivateClients - 1);
        }
        public void when_removing_clients_then_connection_list_decreases()
        {
            var provider = new ConnectionProvider();

            var initialClients = provider.Connections;

            var clientId = Guid.NewGuid().ToString();

            provider.AddConnection(clientId, Mock.Of <IMqttChannel <IPacket> > (c => c.IsConnected == true));

            var newClients = provider.Connections;

            provider.RemoveConnection(clientId);

            var finalClients = provider.Connections;

            Assert.Equal(initialClients + 1, newClients);
            Assert.Equal(initialClients, finalClients);
        }
Exemplo n.º 11
0
        public void when_removing_clients_then_connection_list_decreases()
        {
            ConnectionProvider provider = new ConnectionProvider();

            int initialClients = provider.Connections;

            string clientId = Guid.NewGuid().ToString();

            provider.AddConnection(clientId, Mock.Of <IMqttChannel <IPacket> >(c => c.IsConnected == true));

            int newClients = provider.Connections;

            provider.RemoveConnection(clientId);

            int finalClients = provider.Connections;

            newClients.Should().Be(initialClients + 1);
            initialClients.Should().Be(finalClients);
        }
        public void when_adding_new_client_and_disconnect_it_then_active_clients_list_decreases()
        {
            var provider = new ConnectionProvider();

            var existingClients = provider.ActiveClients.Count();
            var clientId        = Guid.NewGuid().ToString();

            var connection = new Mock <IMqttChannel <IPacket> > ();

            connection.Setup(c => c.IsConnected).Returns(true);

            provider.AddConnection(clientId, connection.Object);

            var currentClients = provider.ActiveClients.Count();

            connection.Setup(c => c.IsConnected).Returns(false);

            var finalClients = provider.ActiveClients.Count();

            Assert.Equal(existingClients + 1, currentClients);
            Assert.Equal(existingClients, finalClients);
        }
Exemplo n.º 13
0
        public void when_adding_new_client_and_disconnect_it_then_active_clients_list_decreases()
        {
            ConnectionProvider provider = new ConnectionProvider();

            int    existingClients = provider.ActiveClients.Count();
            string clientId        = Guid.NewGuid().ToString();

            Mock <IMqttChannel <IPacket> > connection = new Mock <IMqttChannel <IPacket> >();

            connection.Setup(c => c.IsConnected).Returns(true);

            provider.AddConnection(clientId, connection.Object);

            int currentClients = provider.ActiveClients.Count();

            connection.Setup(c => c.IsConnected).Returns(false);

            int finalClients = provider.ActiveClients.Count();

            currentClients.Should().Be(existingClients + 1);
            existingClients.Should().Be(finalClients);
        }