Esempio n. 1
0
        public void SendBatch_Test()
        {
            IIotApi conn = new IotHubConnector();

            conn.Open(new Dictionary <string, object>()
            {
                { "ConnStr", ConfigurationManager.AppSettings["ConnStr"] },
                { "DeviceId", ConfigurationManager.AppSettings["DeviceId"] },
                { "NumOfMessagesPerBatch", 100 }
            }).Wait();


            for (int i = 0; i < 100; i++)
            {
                conn.SendAsync(
                    new { temperature = 22.0, sensor = "unittest", messageId = "123" },
                    (msgs) =>
                {
                    Assert.IsTrue(msgs.Count == 100);
                    dynamic msg = msgs[0];
                    Assert.IsTrue(msg.messageId == "123");
                },

                    (msgs, err) =>
                {
                    throw err;
                }).Wait();
            }
        }
Esempio n. 2
0
        public void InitWithDeviceIdInConnStr_Test()
        {
            string  conStr = $"{ConfigurationManager.AppSettings["ConnStr"]};DeviceId={ConfigurationManager.AppSettings["DeviceId"]}";
            IIotApi conn   = new IotHubConnector();

            conn.Open(new Dictionary <string, object>()
            {
                { "ConnStr", conStr },
            }).Wait();

            conn.SendAsync(
                new { temperature = 22.0, sensor = "unittest", messageId = "123" },
                (msgs) =>
            {
                Assert.IsTrue(msgs.Count == 1);
                dynamic msg = msgs[0];
                Assert.IsTrue(msg.messageId == "123");
            },

                (msgs, err) =>
            {
                throw err;
            }).Wait();
        }
Esempio n. 3
0
        public void InitWithExpliciteDeviceId_Test()
        {
            IotHubConnector conn = new IotHubConnector();

            conn.Open(new Dictionary <string, object>()
            {
                { "ConnStr", ConfigurationManager.AppSettings["ConnStr"] },
                { "DeviceId", ConfigurationManager.AppSettings["DeviceId"] },
            }).Wait();

            conn.SendAsync(
                new { temperature = 22.0, sensor = "unittest", messageId = "1" },
                (msgs) =>
            {
                Assert.IsTrue(msgs.Count == 1);
                dynamic msg = msgs[0];
                Assert.IsTrue(msg.messageId == "1");
            },

                (msgs, err) =>
            {
                throw err;
            }).Wait();
        }