Beispiel #1
0
        IEnumerable <TestScenarioStep> GetEchoClientScenario(Func <object> currentMessageFunc)
        {
            string[] messages = { "message 1", string.Join(",", Enumerable.Range(1, 300)) };
            foreach (string message in messages)
            {
                yield return(TestScenarioStep.Message(Unpooled.WrappedBuffer(Encoding.UTF8.GetBytes(message))));

                var responseMessage = Assert.IsAssignableFrom <IByteBuffer>(currentMessageFunc());
                Assert.Equal(message, Encoding.UTF8.GetString(responseMessage.ToArray()));
            }
        }
Beispiel #2
0
        IEnumerable <TestScenarioStep> GetMqttServerScenario(Func <object> currentMessageFunc)
        {
            yield return(TestScenarioStep.MoreFeedbackExpected());

            var connectPacket = Assert.IsType <ConnectPacket>(currentMessageFunc());

            // todo verify

            yield return(TestScenarioStep.Message(new ConnAckPacket
            {
                ReturnCode = ConnectReturnCode.Accepted,
                SessionPresent = true
            }));

            var subscribePacket = Assert.IsType <SubscribePacket>(currentMessageFunc());

            // todo verify

            yield return(TestScenarioStep.Message(SubAckPacket.InResponseTo(subscribePacket, QualityOfService.ExactlyOnce)));

            var unsubscribePacket = Assert.IsType <UnsubscribePacket>(currentMessageFunc());

            // todo verify

            yield return(TestScenarioStep.Message(UnsubAckPacket.InResponseTo(unsubscribePacket)));

            var publishQos0Packet = Assert.IsType <PublishPacket>(currentMessageFunc());

            // todo verify

            yield return(TestScenarioStep.MoreFeedbackExpected());

            var publishQos1Packet = Assert.IsType <PublishPacket>(currentMessageFunc());
            // todo verify

            int publishQos1PacketId = GetRandomPacketId();

            yield return(TestScenarioStep.Messages(PubAckPacket.InResponseTo(publishQos1Packet),
                                                   new PublishPacket(QualityOfService.AtLeastOnce, false, false)
            {
                PacketId = publishQos1PacketId,
                TopicName = PublishS2CQos1Topic,
                Payload = Unpooled.WrappedBuffer(Encoding.UTF8.GetBytes(PublishS2CQos1Payload))
            }));

            var pubAckPacket = Assert.IsType <PubAckPacket>(currentMessageFunc());

            Assert.Equal(publishQos1PacketId, pubAckPacket.PacketId);

            yield return(TestScenarioStep.MoreFeedbackExpected());

            var disconnectPacket = Assert.IsType <DisconnectPacket>(currentMessageFunc());
        }
Beispiel #3
0
        IEnumerable <TestScenarioStep> GetMqttClientScenario(Func <object> currentMessageFunc)
        {
            yield return(TestScenarioStep.Message(new ConnectPacket
            {
                ClientId = ClientId,
                Username = "******",
                Password = "******",
                WillTopicName = "last/word",
                WillMessage = Unpooled.WrappedBuffer(Encoding.UTF8.GetBytes("oops"))
            }));

            var connAckPacket = Assert.IsType <ConnAckPacket>(currentMessageFunc());

            Assert.Equal(ConnectReturnCode.Accepted, connAckPacket.ReturnCode);

            int subscribePacketId   = GetRandomPacketId();
            int unsubscribePacketId = GetRandomPacketId();

            yield return(TestScenarioStep.Messages(
                             new SubscribePacket(subscribePacketId,
                                                 new SubscriptionRequest(SubscribeTopicFilter1, QualityOfService.ExactlyOnce),
                                                 new SubscriptionRequest(SubscribeTopicFilter2, QualityOfService.AtLeastOnce),
                                                 new SubscriptionRequest("for/unsubscribe", QualityOfService.AtMostOnce)),
                             new UnsubscribePacket(unsubscribePacketId, "for/unsubscribe")));

            var subAckPacket = Assert.IsType <SubAckPacket>(currentMessageFunc());

            Assert.Equal(subscribePacketId, subAckPacket.PacketId);
            Assert.Equal(3, subAckPacket.ReturnCodes.Count);
            Assert.Equal(QualityOfService.ExactlyOnce, subAckPacket.ReturnCodes[0]);
            Assert.Equal(QualityOfService.AtLeastOnce, subAckPacket.ReturnCodes[1]);
            Assert.Equal(QualityOfService.AtMostOnce, subAckPacket.ReturnCodes[2]);

            yield return(TestScenarioStep.MoreFeedbackExpected());

            var unsubAckPacket = Assert.IsType <UnsubAckPacket>(currentMessageFunc());

            Assert.Equal(unsubscribePacketId, unsubAckPacket.PacketId);

            int publishQoS1PacketId = GetRandomPacketId();

            yield return(TestScenarioStep.Messages(
                             new PublishPacket(QualityOfService.AtMostOnce, false, false)
            {
                TopicName = PublishC2STopic,
                Payload = Unpooled.WrappedBuffer(Encoding.UTF8.GetBytes(PublishC2SQos0Payload))
            },
                             new PublishPacket(QualityOfService.AtLeastOnce, false, false)
            {
                PacketId = publishQoS1PacketId,
                TopicName = PublishC2SQos1Topic,
                Payload = Unpooled.WrappedBuffer(Encoding.UTF8.GetBytes(PublishC2SQos1Payload))
            }));

            //new PublishPacket(QualityOfService.AtLeastOnce, false, false) { TopicName = "feedback/qos/One", Payload = Unpooled.WrappedBuffer(Encoding.UTF8.GetBytes("QoS 1 test. Different data length.")) });

            var pubAckPacket = Assert.IsType <PubAckPacket>(currentMessageFunc());

            Assert.Equal(publishQoS1PacketId, pubAckPacket.PacketId);

            yield return(TestScenarioStep.MoreFeedbackExpected());

            var publishPacket = Assert.IsType <PublishPacket>(currentMessageFunc());

            Assert.Equal(QualityOfService.AtLeastOnce, publishPacket.QualityOfService);
            Assert.Equal(PublishS2CQos1Topic, publishPacket.TopicName);
            Assert.Equal(PublishS2CQos1Payload, Encoding.UTF8.GetString(publishPacket.Payload.ToArray()));

            yield return(TestScenarioStep.Messages(
                             PubAckPacket.InResponseTo(publishPacket),
                             DisconnectPacket.Instance));
        }