public void SubscribeDecodeAvanceTestsv5()
        {
            // Arrange
            byte[] encodedCorrect = new byte[] { 249, 1, 0, 42, 223, 1, 11, 253, 255, 255, 127, 38, 0, 8, 108, 111, 110, 103, 32, 111, 110, 101, 0, 210,
                                                 111, 110, 101, 32, 118, 101, 114, 121, 32, 108, 111, 110, 103, 32, 111, 110, 101, 32, 116, 111, 32, 116,
                                                 101, 115, 116, 32, 102, 111, 114, 32, 111, 110, 99, 101, 32, 104, 111, 119, 32, 116, 104, 105, 115, 32,
                                                 119, 105, 108, 108, 32, 101, 110, 99, 111, 100, 101, 32, 97, 110, 100, 32, 109, 97, 107, 101, 32, 105,
                                                 116, 32, 114, 101, 97, 108, 108, 108, 108, 108, 108, 121, 121, 121, 121, 121, 121, 121, 32, 115, 111,
                                                 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 32, 115, 111, 111, 111, 111, 111, 111, 111, 111,
                                                 111, 111, 111, 111, 111, 111, 32, 115, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111,
                                                 111, 111, 111, 32, 115, 111, 111, 111, 111, 111, 111, 111, 111, 111, 32, 108, 111, 110, 103, 46, 32, 89,
                                                 101, 97, 44, 32, 116, 104, 97, 116, 32, 115, 104, 111, 117, 108, 100, 32, 98, 101, 32, 116, 101, 115, 116,
                                                 101, 100, 32, 102, 111, 114, 32, 114, 101, 97, 108, 32, 105, 110, 32, 116, 104, 101, 32, 114, 101, 97,
                                                 108, 32, 108, 105, 102, 101, 32, 97, 115, 32, 119, 101, 108, 108, 0, 5, 102, 105, 114, 115, 116, 1, 0, 6,
                                                 115, 101, 99, 111, 110, 100, 2 };
            MokChannel mokChannel = new MokChannel(encodedCorrect);
            // Act
            MqttMsgSubscribe subscribe = MqttMsgSubscribe.Parse(130, MqttProtocolVersion.Version_5, mokChannel);

            // Assert
            Assert.Equal(subscribe.MessageId, (ushort)42);
            Assert.Equal(subscribe.QoSLevels, new MqttQoSLevel[] { MqttQoSLevel.AtLeastOnce, MqttQoSLevel.ExactlyOnce });
            Assert.Equal(subscribe.Topics, new string[] { "first", "second" });
            Assert.Equal(subscribe.SubscriptionIdentifier, 268435453);
            var prop = new UserProperty("long one", "one very long one to test for once how this will encode and make it reallllllyyyyyyy soooooooooooo soooooooooooooo soooooooooooooooo sooooooooo long. Yea, that should be tested for real in the real life as well");

            Assert.Equal(((UserProperty)subscribe.UserProperties[0]).Name, prop.Name);
            Assert.Equal(((UserProperty)subscribe.UserProperties[0]).Value, prop.Value);
        }
예제 #2
0
        public void ConnecAdvancedDecodeTestv5()
        {
            // Arrange
            byte[] correctEncoded = new byte[] { 122, 0, 4, 77, 81, 84, 84, 5, 246, 4, 210, 41, 21, 0, 10, 87, 111, 119, 111, 44, 32, 99, 111, 111, 108,
                                                 22, 0, 5, 0, 1, 2, 3, 4, 17, 0, 0, 212, 49, 33, 255, 105, 39, 255, 255, 255, 155, 34, 255, 245, 23, 1, 25, 1,
                                                 0, 8, 99, 108, 105, 101, 110, 116, 73, 68, 0, 10, 119, 105, 108, 108, 32, 116, 111, 112, 105, 99, 0, 12,
                                                 119, 105, 108, 108, 32, 109, 101, 115, 115, 97, 103, 101, 0, 9, 85, 115, 101, 114, 32, 78, 97, 109, 101,
                                                 0, 21, 65, 32, 116, 101, 120, 116, 32, 112, 97, 115, 115, 119, 111, 114, 100, 32, 36, 36, 39, 47, 37 };
            MokChannel mokChannel = new MokChannel(correctEncoded);
            // Act
            MqttMsgConnect connect = MqttMsgConnect.Parse((byte)MqttMessageType.Connect << 4, MqttProtocolVersion.Version_5, mokChannel);

            // Assert
            Assert.Equal((byte)MqttProtocolVersion.Version_5, (byte)connect.ProtocolVersion);
            Assert.Equal(ClientID, connect.ClientId);
            Assert.Equal(UserName, connect.Username);
            Assert.Equal(Password, connect.Password);
            Assert.Equal(WillTopic, connect.WillTopic);
            Assert.Equal(WillMessage, connect.WillMessage);
            Assert.Equal(KeepAlivePeriod, connect.KeepAlivePeriod);
            Assert.Equal(true, connect.CleanSession);
            Assert.Equal(new byte[5] {
                0, 1, 2, 3, 4
            }, connect.AuthenticationData);
            Assert.Equal("Wowo, cool", connect.AuthenticationMethod);
            Assert.Equal(uint.MaxValue - 100, connect.MaximumPacketSize);
            Assert.Equal((ushort)(ushort.MaxValue - 10), connect.TopicAliasMaximum);
            Assert.Equal((ushort)(ushort.MaxValue - 150), connect.ReceiveMaximum);
            Assert.Equal(true, connect.RequestProblemInformation);
            Assert.Equal(true, connect.RequestResponseInformation);
            Assert.Equal(54321, connect.SessionExpiryInterval);
        }
예제 #3
0
 public void AuthenticationExceptionTestsv311()
 {
     Assert.Throws(typeof(NotSupportedException), () =>
     {
         MqttMsgAuthentication authentication = new();
         authentication.GetBytes(MqttProtocolVersion.Version_3_1_1);
     });
     Assert.Throws(typeof(NotSupportedException), () =>
     {
         MqttMsgAuthentication authentication = new();
         authentication.GetBytes(MqttProtocolVersion.Version_3_1);
     });
     Assert.Throws(typeof(NotSupportedException), () =>
     {
         MokChannel mokChannel = new MokChannel(new byte[1] {
             42
         });
         MqttMsgAuthentication authentication = MqttMsgAuthentication.Parse(42, MqttProtocolVersion.Version_3_1_1, mokChannel);
     });
     Assert.Throws(typeof(NotSupportedException), () =>
     {
         MokChannel mokChannel = new MokChannel(new byte[1] {
             42
         });
         MqttMsgAuthentication authentication = MqttMsgAuthentication.Parse(42, MqttProtocolVersion.Version_3_1, mokChannel);
     });
 }
예제 #4
0
        public void ConnectUserPropDecodeTestv5()
        {
            // Arrange
            byte[] correctEncoded = new byte[] { 115, 0, 4, 77, 81, 84, 84, 5, 246, 4, 210, 34, 38, 0, 3, 79, 110, 101, 0, 8, 80, 114, 111, 112, 101, 114,
                                                 116, 121, 38, 0, 3, 84, 119, 111, 0, 10, 80, 114, 111, 112, 101, 114, 116, 105, 101, 115, 0, 8, 99, 108,
                                                 105, 101, 110, 116, 73, 68, 0, 10, 119, 105, 108, 108, 32, 116, 111, 112, 105, 99, 0, 12, 119, 105, 108,
                                                 108, 32, 109, 101, 115, 115, 97, 103, 101, 0, 9, 85, 115, 101, 114, 32, 78, 97, 109, 101, 0, 21, 65, 32,
                                                 116, 101, 120, 116, 32, 112, 97, 115, 115, 119, 111, 114, 100, 32, 36, 36, 39, 47, 37 };
            MokChannel mokChannel = new MokChannel(correctEncoded);
            // Act
            MqttMsgConnect connect = MqttMsgConnect.Parse((byte)MqttMessageType.Connect << 4, MqttProtocolVersion.Version_5, mokChannel);

            // Assert
            Assert.Equal((byte)MqttProtocolVersion.Version_5, (byte)connect.ProtocolVersion);
            Assert.Equal(ClientID, connect.ClientId);
            Assert.Equal(UserName, connect.Username);
            Assert.Equal(Password, connect.Password);
            Assert.Equal(WillTopic, connect.WillTopic);
            Assert.Equal(WillMessage, connect.WillMessage);
            Assert.Equal(KeepAlivePeriod, connect.KeepAlivePeriod);
            Assert.Equal(true, connect.CleanSession);
            Assert.Equal(2, connect.UserProperties.Count);
            var prop = new UserProperty("One", "Property");

            Assert.Equal(((UserProperty)connect.UserProperties[0]).Name, prop.Name);
            Assert.Equal(((UserProperty)connect.UserProperties[0]).Value, prop.Value);
            prop = new UserProperty("Two", "Properties");
            Assert.Equal(((UserProperty)connect.UserProperties[1]).Name, prop.Name);
            Assert.Equal(((UserProperty)connect.UserProperties[1]).Value, prop.Value);
        }
 public void DisconnectBasicDecodeTestv5()
 {
     // Arrange
     byte[]     encodedCorrect = new byte[] { 0 };
     MokChannel mokChannel     = new MokChannel(encodedCorrect);
     // Act
     MqttMsgDisconnect disconnect = MqttMsgDisconnect.Parse(224, MqttProtocolVersion.Version_5, mokChannel);
     // Assert
 }
        public void DisconnectBasicDecodeErrorCodeTestv5()
        {
            // Arrange
            byte[]     encodedCorrect = new byte[] { 2, 143, 0 };
            MokChannel mokChannel     = new MokChannel(encodedCorrect);
            // Act
            MqttMsgDisconnect disconnect = MqttMsgDisconnect.Parse(224, MqttProtocolVersion.Version_5, mokChannel);

            // Assert
            Assert.Equal((byte)disconnect.ResonCode, (byte)MqttReasonCode.TopicFilterInvalid);
        }
        public void ConnackBasicDecodeTest5()
        {
            // Arrange
            byte[]     correctEncoded = new byte[] { 3, 1, 138, 0 };
            MokChannel mokChannel     = new MokChannel(correctEncoded);
            // Act
            MqttMsgConnack connack = MqttMsgConnack.Parse((byte)(MqttMessageType.ConnectAck) << 4, MqttProtocolVersion.Version_5, mokChannel);

            // Assert
            Assert.Equal(true, connack.SessionPresent);
            Assert.Equal((byte)MqttReasonCode.Banned, (byte)connack.ReturnCode);
        }
예제 #8
0
        public void SubackBasicDecodingTestsv311()
        {
            // Arrange
            byte[]     encodedCorrect = new byte[] { 4, 0, 42, 1, 2 };
            MokChannel mokChannel     = new MokChannel(encodedCorrect);
            // Act
            MqttMsgSuback suback = MqttMsgSuback.Parse(144, MqttProtocolVersion.Version_3_1_1, mokChannel);

            // Assert
            Assert.Equal((ushort)42, suback.MessageId);
            Assert.Equal(suback.GrantedQoSLevels, new MqttQoSLevel[] { MqttQoSLevel.AtLeastOnce, MqttQoSLevel.ExactlyOnce });
        }
        public void SubscribeDecodeBasicTestsv5()
        {
            // Arrange
            byte[]     encodedCorrect = new byte[] { 20, 0, 42, 0, 0, 5, 102, 105, 114, 115, 116, 1, 0, 6, 115, 101, 99, 111, 110, 100, 2 };
            MokChannel mokChannel     = new MokChannel(encodedCorrect);
            // Act
            MqttMsgSubscribe subscribe = MqttMsgSubscribe.Parse(130, MqttProtocolVersion.Version_5, mokChannel);

            // Assert
            Assert.Equal(subscribe.MessageId, (ushort)42);
            Assert.Equal(subscribe.QoSLevels, new MqttQoSLevel[] { MqttQoSLevel.AtLeastOnce, MqttQoSLevel.ExactlyOnce });
            Assert.Equal(subscribe.Topics, new string[] { "first", "second" });
        }
예제 #10
0
        public void SubackBasicDecodingTestsv5()
        {
            // Arrange
            byte[]     encodedCorrect = new byte[] { 5, 0, 42, 0, 1, 2 };
            MokChannel mokChannel     = new MokChannel(encodedCorrect);
            // Act
            MqttMsgSuback suback = MqttMsgSuback.Parse(144, MqttProtocolVersion.Version_5, mokChannel);

            // Assert
            Assert.Equal((ushort)42, suback.MessageId);
            Assert.Equal(suback.GrantedQoSLevels, new MqttQoSLevel[] { MqttQoSLevel.AtLeastOnce, MqttQoSLevel.ExactlyOnce });
            Assert.Equal(suback.ReasonCodes, new MqttReasonCode[] { MqttReasonCode.GrantedQoS1, MqttReasonCode.GrantedQoS2 });
            // And this should work as well as it's value comparison
            Assert.Equal(suback.GrantedQoSLevels, new MqttReasonCode[] { MqttReasonCode.GrantedQoS1, MqttReasonCode.GrantedQoS2 });
        }
예제 #11
0
        public void ConnectBasicDecodeTestv5()
        {
            // Arrange
            byte[] correctEncoded = new byte[] { 81, 0, 4, 77, 81, 84, 84, 5, 246, 4, 210, 0, 0, 8, 99, 108, 105, 101, 110, 116, 73, 68, 0, 10, 119, 105, 108, 108, 32, 116, 111, 112, 105, 99, 0, 12, 119, 105, 108, 108, 32, 109, 101, 115, 115, 97, 103, 101, 0, 9, 85, 115, 101, 114, 32, 78, 97,
                                                 109, 101, 0, 21, 65, 32, 116, 101, 120, 116, 32, 112, 97, 115, 115, 119, 111, 114, 100, 32, 36, 36, 39, 47, 37 };
            MokChannel mokChannel = new MokChannel(correctEncoded);
            // Act
            MqttMsgConnect connect = MqttMsgConnect.Parse((byte)MqttMessageType.Connect << 4, MqttProtocolVersion.Version_5, mokChannel);

            // Assert
            Assert.Equal((byte)MqttProtocolVersion.Version_5, (byte)connect.ProtocolVersion);
            Assert.Equal(ClientID, connect.ClientId);
            Assert.Equal(UserName, connect.Username);
            Assert.Equal(Password, connect.Password);
            Assert.Equal(WillTopic, connect.WillTopic);
            Assert.Equal(WillMessage, connect.WillMessage);
            Assert.Equal(KeepAlivePeriod, connect.KeepAlivePeriod);
            Assert.Equal(true, connect.CleanSession);
        }
        public void DisconnectAdvanceDecodeTestv5()
        {
            // Arrange
            byte[] encodedCorrect = new byte[] { 62, 143, 60, 17, 0, 0, 48, 57, 31, 0, 13, 73, 110, 118, 97, 108, 105, 100, 32, 116, 111, 112, 105, 99,
                                                 38, 0, 6, 115, 116, 97, 116, 117, 115, 0, 3, 49, 48, 49, 28, 0, 22, 110, 101, 119, 115, 101, 114, 118, 101,
                                                 114, 46, 115, 111, 109, 116, 104, 105, 110, 103, 46, 110, 101, 116 };
            MokChannel mokChannel = new MokChannel(encodedCorrect);
            // Act
            MqttMsgDisconnect disconnect = MqttMsgDisconnect.Parse(224, MqttProtocolVersion.Version_5, mokChannel);

            // Assert
            Assert.Equal((byte)disconnect.ResonCode, (byte)MqttReasonCode.TopicFilterInvalid);
            Assert.Equal(disconnect.SessionExpiryInterval, 12345);
            Assert.Equal(disconnect.Reason, "Invalid topic");
            Assert.Equal(disconnect.ServerReference, "newserver.somthing.net");
            var prop = new UserProperty("status", "101");

            Assert.Equal(((UserProperty)disconnect.UserProperties[0]).Name, prop.Name);
            Assert.Equal(((UserProperty)disconnect.UserProperties[0]).Value, prop.Value);
        }
예제 #13
0
        public void ConnackAdvanceDecodeTestv5()
        {
            //Arrange
            byte[] encodedCorrect = new byte[] { 124, 1, 138, 121, 17, 0, 0, 9, 164, 33, 0, 89, 36, 1, 37, 1, 39, 0, 0, 17, 215, 18, 0, 6, 84, 97, 103, 97,
                                                 100, 97, 34, 0, 148, 31, 0, 4, 110, 111, 110, 101, 38, 0, 3, 79, 110, 101, 0, 8, 80, 114, 111, 112, 101, 114,
                                                 116, 121, 38, 0, 3, 84, 119, 111, 0, 10, 80, 114, 111, 112, 101, 114, 116, 105, 101, 115, 40, 1, 41, 1, 42,
                                                 1, 19, 5, 77, 26, 0, 11, 105, 110, 102, 114, 111, 109, 97, 116, 105, 111, 110, 28, 0, 9, 114, 101, 102, 101,
                                                 114, 101, 110, 99, 101, 21, 0, 6, 109, 101, 116, 104, 111, 100, 22, 0, 4, 1, 2, 3, 4 };
            MokChannel mokChannel = new MokChannel(encodedCorrect);
            // Act
            MqttMsgConnack connack = MqttMsgConnack.Parse((byte)(MqttMessageType.ConnectAck) << 4, MqttProtocolVersion.Version_5, mokChannel);

            // Assert
            Assert.Equal(true, connack.SessionPresent);
            Assert.Equal((byte)MqttReasonCode.Banned, (byte)connack.ReturnCode);
            Assert.Equal(connack.AssignedClientIdentifier, "Tagada");
            Assert.Equal(connack.AuthenticationData, new byte[] { 1, 2, 3, 4 });
            Assert.Equal(connack.AuthenticationMethod, "method");
            Assert.Equal(connack.MaximumPacketSize, 4567);
            Assert.Equal(connack.MaximumQoS, true);
            Assert.Equal(connack.Reason, "none");
            Assert.Equal(connack.ReceiveMaximum, (ushort)89);
            Assert.Equal(connack.ResponseInformation, "infromation");
            Assert.Equal(connack.RetainAvailable, true);
            Assert.Equal(connack.ServerKeepAlive, (ushort)1357);
            Assert.Equal(connack.ServerReference, "reference");
            Assert.Equal(connack.SessionExpiryInterval, 2468);
            Assert.Equal(connack.SharedSubscriptionAvailable, true);
            Assert.Equal(connack.SubscriptionIdentifiersAvailable, true);
            Assert.Equal(connack.TopicAliasMaximum, (ushort)148);
            Assert.Equal(connack.UserProperties.Count, 2);
            var prop = new UserProperty("One", "Property");

            Assert.Equal(((UserProperty)connack.UserProperties[0]).Name, prop.Name);
            Assert.Equal(((UserProperty)connack.UserProperties[0]).Value, prop.Value);
            prop = new UserProperty("Two", "Properties");
            Assert.Equal(((UserProperty)connack.UserProperties[1]).Name, prop.Name);
            Assert.Equal(((UserProperty)connack.UserProperties[1]).Value, prop.Value);
            Assert.Equal(connack.WildcardSubscriptionAvailable, true);
        }
예제 #14
0
        public void SubackAdvancedDecodingTestsv5()
        {
            // Arrange
            byte[] encodedCorrect = new byte[] { 93, 0, 42, 87, 31, 0, 49, 84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 103, 111, 111, 100, 32, 114,
                                                 101, 97, 115, 111, 110, 58, 32, 121, 111, 117, 114, 32, 97, 114, 101, 32, 110, 111, 116, 32, 97, 117, 116,
                                                 104, 111, 114, 105, 122, 101, 100, 33, 33, 33, 38, 0, 4, 80, 114, 111, 112, 0, 26, 111, 110, 108, 121, 32,
                                                 111, 110, 101, 32, 116, 104, 105, 115, 32, 116, 105, 109, 101, 32, 102, 111, 114, 32, 102, 117, 110, 1,
                                                 2, 135 };
            MokChannel mokChannel = new MokChannel(encodedCorrect);
            // Act
            MqttMsgSuback suback = MqttMsgSuback.Parse(144, MqttProtocolVersion.Version_5, mokChannel);

            // Assert
            Assert.Equal((ushort)42, suback.MessageId);
            Assert.Equal(suback.GrantedQoSLevels, new MqttQoSLevel[] { MqttQoSLevel.AtLeastOnce, MqttQoSLevel.ExactlyOnce, (MqttQoSLevel)MqttReasonCode.NotAuthorized });
            Assert.Equal(suback.ReasonCodes, new MqttReasonCode[] { MqttReasonCode.GrantedQoS1, MqttReasonCode.GrantedQoS2, MqttReasonCode.NotAuthorized });
            // And this should work as well as it's value comparison
            Assert.Equal(suback.GrantedQoSLevels, new MqttReasonCode[] { MqttReasonCode.GrantedQoS1, MqttReasonCode.GrantedQoS2, MqttReasonCode.NotAuthorized });
            var prop = new UserProperty("Prop", "only one this time for fun");

            Assert.Equal(((UserProperty)suback.UserProperties[0]).Name, prop.Name);
            Assert.Equal(((UserProperty)suback.UserProperties[0]).Value, prop.Value);
        }