public async Task connect_throw_timeout()
        {
            Queue <TestPacket> packets = new();

            packets.Enqueue(TestPacket.Outgoing("101600044d5154540402001e000a434b4d71747454657374"));
            PacketReplayer packetReplayer = new(packets);

            IMqtt3Client client = MqttClient.Factory.CreateMQTT3Client(TestConfigs.DefaultTestConfig(packetReplayer), (IActivityMonitor m, DisposableApplicationMessage msg) =>
            {
                msg.Dispose();
                return(new ValueTask());
            });
            Task <ConnectResult> connectTask = client.ConnectAsync(TestHelper.Monitor, new MqttClientCredentials("CKMqttTest", true));

            connectTask.IsCompleted.Should().BeFalse();
            await packetReplayer.LastWorkTask !;

            packetReplayer.TestDelayHandler.IncrementTime(TimeSpan.FromMilliseconds(4999));
            await Task.WhenAny(connectTask, Task.Delay(50));

            connectTask.IsCompleted.Should().BeFalse();
            packetReplayer.TestDelayHandler.IncrementTime(TimeSpan.FromMilliseconds(2));
            (await connectTask).ConnectError.Should().Be(ConnectError.Timeout);
            packetReplayer.LastWorkTask !.IsCompletedSuccessfully.Should().BeTrue();
        }
        public async Task connect_with_clean_session_but_connack_session_present_is_not_zero_should_fail()
        {
            Queue <TestPacket> packets       = new();
            TestPacket         connectPacket = TestPacket.Outgoing("101600044d5154540402001e000a434b4d71747454657374");

            for (byte i = 1; i != 0; i++)  //Ok there we loop over all non zero bytes.
            {
                packets.Enqueue(connectPacket);
                packets.Enqueue(TestPacket.Incoming("2002" + BitConverter.ToString(new byte[] { i }) + "00"));
            }

            PacketReplayer pcktReplayer = new(packets);

            IMqtt3Client client = MqttClient.Factory.CreateMQTT3Client(TestConfigs.DefaultTestConfig(pcktReplayer), (IActivityMonitor m, DisposableApplicationMessage msg) =>
            {
                msg.Dispose();
                return(new ValueTask());
            });
            ConnectResult res = await client.ConnectAsync(TestHelper.Monitor, new MqttClientCredentials( "CKMqttTest", true ));

            res.ConnectError.Should().Be(ConnectError.ProtocolError_SessionNotFlushed);
            for (byte i = 2; i != 0; i++)
            {
                res = await client.ConnectAsync(TestHelper.Monitor, new MqttClientCredentials( "CKMqttTest", true ));

                res.ConnectError.Should().Be(ConnectError.ProtocolError_InvalidConnackState);
            }
            pcktReplayer.LastWorkTask !.IsCompletedSuccessfully.Should().BeTrue();
        }
        public async Task connect_with_clean_session_but_connack_return_code_is_invalid_should_throw()
        {
            Queue <TestPacket> packets        = new();
            TestPacket         connectPacket  = TestPacket.Outgoing("101600044d5154540402001e000a434b4d71747454657374");
            const int          startSkipCount = 6;     // These packets are valid, so we skip them.

            for (byte i = startSkipCount; i != 0; i++) //Ok there we loop over all non zero bytes.
            {
                packets.Enqueue(connectPacket);
                packets.Enqueue(TestPacket.Incoming("200200" + BitConverter.ToString(new byte[] { i })));
            }

            PacketReplayer packetReplayer = new(packets);

            IMqtt3Client client = MqttClient.Factory.CreateMQTT3Client(TestConfigs.DefaultTestConfig(packetReplayer), (IActivityMonitor m, DisposableApplicationMessage msg) =>
            {
                msg.Dispose();
                return(new ValueTask());
            });

            for (byte i = startSkipCount; i != 0; i++)
            {
                ConnectResult res = await client.ConnectAsync(TestHelper.Monitor, new MqttClientCredentials( "CKMqttTest", true ));

                res.ConnectError.Should().Be(ConnectError.ProtocolError_UnknownReturnCode);
            }
            packetReplayer.LastWorkTask !.IsCompletedSuccessfully.Should().BeTrue();
        }
        public async Task connect_while_being_connected_should_throw_friendly_exception()
        {
            Queue <TestPacket> packets = new();

            packets.Enqueue(TestPacket.Outgoing("101600044d5154540402001e000a434b4d71747454657374"));
            packets.Enqueue(TestPacket.Incoming("20020000"));
            PacketReplayer packetReplayer = new(packets);

            IMqtt3Client client = MqttClient.Factory.CreateMQTT3Client(TestConfigs.DefaultTestConfig(packetReplayer), (IActivityMonitor m, DisposableApplicationMessage msg) =>
            {
                msg.Dispose();
                return(new ValueTask());
            });
            await client.ConnectAsync(TestHelper.Monitor, new MqttClientCredentials( "CKMqttTest", true ));

            try
            {
                await client.ConnectAsync(TestHelper.Monitor, new MqttClientCredentials( "CKMqttTest", true ));

                Assert.Fail();
            }
            catch (Exception e)
            {
                e.Should().BeOfType <InvalidOperationException>();
                e.Message.Should().Be("This client is already connected.");
            }
            packetReplayer.LastWorkTask !.IsCompletedSuccessfully.Should().BeTrue();
        }
        public async Task simple_connection_works()
        {
            PacketReplayer pcktReplayer = new(new Queue <TestPacket>(new List <TestPacket>()
            {
                TestPacket.Outgoing("101600044d5154540402001e000a434b4d71747454657374"),
                TestPacket.Incoming("20020000")
            }));

            IMqtt3Client client = MqttClient.Factory.CreateMQTT3Client(TestConfigs.DefaultTestConfig(pcktReplayer), (IActivityMonitor m, DisposableApplicationMessage msg) =>
            {
                msg.Dispose();
                return(new ValueTask());
            });
            await client.ConnectAsync(TestHelper.Monitor, new MqttClientCredentials( "CKMqttTest", true ));

            pcktReplayer.LastWorkTask !.IsCompletedSuccessfully.Should().BeTrue();
        }
        public async Task connect_after_failed_connect_works()
        {
            TestPacket         connectPacket = TestPacket.Outgoing("101600044d5154540402001e000a434b4d71747454657374");
            Queue <TestPacket> packets       = new();

            packets.Enqueue(connectPacket);
            packets.Enqueue(TestPacket.Incoming("20021000"));     // Invalid response.
            packets.Enqueue(connectPacket);
            packets.Enqueue(TestPacket.Incoming("20020000"));     // Valid response.
            PacketReplayer packetReplayer = new(packets);

            IMqtt3Client client = MqttClient.Factory.CreateMQTT3Client(TestConfigs.DefaultTestConfig(packetReplayer), (IActivityMonitor m, DisposableApplicationMessage msg) =>
            {
                msg.Dispose();
                return(new ValueTask());
            });
            ConnectResult res = await client.ConnectAsync(TestHelper.Monitor, new MqttClientCredentials( "CKMqttTest", true ));

            res.ConnectError.Should().NotBe(ConnectError.Ok);
            ConnectResult res2 = await client.ConnectAsync(TestHelper.Monitor, new MqttClientCredentials( "CKMqttTest", true ));

            res2.ConnectError.Should().Be(ConnectError.Ok);
            packetReplayer.LastWorkTask !.IsCompletedSuccessfully.Should().BeTrue();
        }
示例#7
0
        public static void SendMessage(String FirstName, String LastName, String Email, String Message)
        {
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress("Daniel Ashcraft", "*****@*****.**"));
            message.To.Add(new MailboxAddress(FirstName + " " + LastName, Email));
            message.Subject = "Contact Form Submission";

            message.Body = new TextPart("plain")
            {
                Text = FirstName + "\n" + LastName + "\n" + Email + "\n" + Message
            };

            using (var client = new SmtpClient())
            {
                // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
                client.ServerCertificateValidationCallback = (s, c, h, e) => true;
                try{
                    TestConfigs config = new TestConfigs();
                    client.Connect("smtpout.secureserver.net", 80, false);

                    // Note: since we don't have an OAuth2 token, disable
                    // the XOAUTH2 authentication mechanism.
                    client.AuthenticationMechanisms.Remove("XOAUTH2");

                    // Note: only needed if the SMTP server requires authentication
                    client.Authenticate("*****@*****.**", config.emailPass);

                    client.Send(message);
                    client.Disconnect(true);
                }
                catch (Exception e) {
                    Console.WriteLine(e.ToString());
                }
            }
        }
示例#8
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            TestConfigs config = new TestConfigs();

            optionsBuilder.UseSqlServer(@config.testDBUrl);
        }
 public IEnumerator <object[]> GetEnumerator()
 {
     return(TestConfigs
            .SelectMany(config => TestCases, (config, testCase) => config.Concat(testCase).ToArray())
            .GetEnumerator());
 }