Ejemplo n.º 1
0
 public void ConnectToInvalidPortInFaultedStateAfterConnectionException()
 {
     var ch = new SynchronousMqttConnectionHandler();
     Assert.Throws<ConnectionException>(() => ch.Connect(mockBrokerAddress, badPort,
         new MqttConnectMessage().WithClientIdentifier(testClientId)));
     Assert.Equal<ConnectionState>(ConnectionState.Faulted, ch.ConnectionState);
 }
Ejemplo n.º 2
0
 public void ConnectToBadHostNameInFaultedStateAfterConnectionException()
 {
     var ch = new SynchronousMqttConnectionHandler();
     Assert.Throws<ConnectionException>(() => ch.Connect(nonExistantHostName, mockBrokerPort,
         new MqttConnectMessage().WithClientIdentifier(testClientId)));
     Assert.Equal<ConnectionState>(ConnectionState.Faulted, ch.ConnectionState);
 }
Ejemplo n.º 3
0
 public void ConnectWithNoConnectAckThrowsExceptionAndSetsConnectionToFaulted()
 {
     var ch = new SynchronousMqttConnectionHandler();
     var ex = Assert.Throws<ConnectionException>(() => ch.Connect(mockBrokerAddress, mockBrokerPort,
         new MqttConnectMessage().WithClientIdentifier(testClientId)));
     Console.WriteLine("Exception Message Received {0}", ex.ToString());
     Assert.Equal<ConnectionState>(ConnectionState.Faulted, ch.ConnectionState);
 }
Ejemplo n.º 4
0
        public void SuccessfullResponseCausesConnectionStateConnected()
        {
            // register a method to process the Connect message and respond with a ConnectAck message
            broker.SetMessageHandler((messageArrived) =>
                {
                    MqttConnectMessage connect = (MqttConnectMessage)MqttMessage.CreateFrom(messageArrived);
                    MqttConnectAckMessage ack = new MqttConnectAckMessage().WithReturnCode(MqttConnectReturnCode.ConnectionAccepted);
                    broker.SendMessage(ack);
                });

            var ch = new SynchronousMqttConnectionHandler();
            Assert.Equal<ConnectionState>(ConnectionState.Connected, 
                ch.Connect(mockBrokerAddress, mockBrokerPort, new MqttConnectMessage().WithClientIdentifier(testClientId)));
        }
Ejemplo n.º 5
0
 public void ConnectToInvalidPortThrowsConnectionException()
 {
     var ch = new SynchronousMqttConnectionHandler();
     Assert.Throws<ConnectionException>(() => ch.Connect(mockBrokerAddress, badPort,
         new MqttConnectMessage().WithClientIdentifier(testClientId)));
 }
Ejemplo n.º 6
0
 public void ConnectToBadHostNameThrowsConnectionException()
 {
     var ch = new SynchronousMqttConnectionHandler();
     Assert.Throws<ConnectionException>(() => ch.Connect(nonExistantHostName, mockBrokerPort, 
         new MqttConnectMessage().WithClientIdentifier(testClientId)));
 }