コード例 #1
0
ファイル: SubscriptionsManager.cs プロジェクト: madrang/nmqtt
        public void GetSubscriptionForPendingSubscriptionReturnsNull()
        {
            var chMock = new Mock <IMqttConnectionHandler>();

            string  topic = "testtopic";
            MqttQos qos   = MqttQos.AtMostOnce;

            // run and verify the mocks were called.
            Nmqtt.SubscriptionsManager subs = new Nmqtt.SubscriptionsManager(chMock.Object);
            var subid = subs.RegisterSubscription <AsciiPublishDataConverter>(topic, qos);

            Assert.Null(subs.GetSubscription(topic));
        }
コード例 #2
0
        /// <summary>
        /// Handles the processing of messages arriving from the message broker.
        /// </summary>
        /// <param name="mqttMessage"></param>
        private bool HandlePublishMessage(MqttMessage message)
        {
            MqttPublishMessage pubMsg = (MqttPublishMessage)message;
            Subscription       subs   = subscriptionsManager.GetSubscription(pubMsg.VariableHeader.TopicName);

            if (subs == null)
            {
                return(false);
            }

            // pass it on to the event subscribers.
            OnMessageAvailable(pubMsg.VariableHeader.TopicName, subs.DataProcessor.ConvertFromBytes(pubMsg.Payload.Message.ToArray()));
            return(true);
        }
コード例 #3
0
ファイル: SubscriptionsManager.cs プロジェクト: madrang/nmqtt
        public void GetSubscriptionWithValidTopicReturnsSubscription()
        {
            Func <MqttMessage, bool> theCallback = null;
            var chMock = new Mock <IMqttConnectionHandler>();

            chMock.Setup((x) => x.RegisterForMessage(MqttMessageType.SubscribeAck, It.IsAny <Func <MqttMessage, bool> >()))
            .Callback((MqttMessageType msgtype, Func <MqttMessage, bool> cb) => theCallback = cb);

            string  topic = "testtopic";
            MqttQos qos   = MqttQos.AtMostOnce;

            // run and verify the mocks were called.
            Nmqtt.SubscriptionsManager subs = new Nmqtt.SubscriptionsManager(chMock.Object);
            var subid = subs.RegisterSubscription <AsciiPublishDataConverter>(topic, qos);

            // execute the callback that would normally be initiated by the connection handler when a sub ack message arrived.
            theCallback(new MqttSubscribeAckMessage().WithMessageIdentifier(subid).AddQosGrant(MqttQos.AtMostOnce));

            Assert.NotNull(subs.GetSubscription(topic));
        }
コード例 #4
0
ファイル: SubscriptionsManager.cs プロジェクト: fm0597/nmqtt
        public void GetSubscriptionForPendingSubscriptionReturnsNull() {
            var chMock = new Mock<IMqttConnectionHandler>();
            var pubMock = new Mock<IPublishingManager>();

            const string topic = "testtopic";
            const MqttQos qos = MqttQos.AtMostOnce;

            // run and verify the mocks were called.
            var subs = new Nmqtt.SubscriptionsManager(chMock.Object, pubMock.Object);
            subs.RegisterSubscription<string, AsciiPayloadConverter>(topic, qos);

            Assert.Null(subs.GetSubscription(topic));
        }
コード例 #5
0
ファイル: SubscriptionsManager.cs プロジェクト: fm0597/nmqtt
        public void GetSubscriptionWithInvalidTopicReturnsNull()
        {
            Func<MqttMessage, bool> theCallback = null;
            var pubMock = new Mock<IPublishingManager>();

            var chMock = new Mock<IMqttConnectionHandler>();
            chMock.Setup(x => x.RegisterForMessage(MqttMessageType.SubscribeAck, It.IsAny<Func<MqttMessage, bool>>()))
                .Callback((MqttMessageType msgtype, Func<MqttMessage, bool> cb) => theCallback = cb);

            const string topic = "testtopic";
            const MqttQos qos = MqttQos.AtMostOnce;

            // run and verify the mocks were called.
            var subs = new Nmqtt.SubscriptionsManager(chMock.Object, pubMock.Object);
            subs.RegisterSubscription<string, AsciiPayloadConverter>(topic, qos);

            // execute the callback that would normally be initiated by the connection handler when a sub ack message arrived.
            theCallback(new MqttSubscribeAckMessage().WithMessageIdentifier(1).AddQosGrant(MqttQos.AtMostOnce));

            Assert.Null(subs.GetSubscription("abc_badTopic"));
        }