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(); } }
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(); }
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(); }