public void OnMessage_Test() { ClearQueue_Test(); string deviceId = ConfigurationManager.AppSettings["DeviceId"]; IIotApi conn = getConnector(); ServiceClient svcClient = ServiceClient.CreateFromConnectionString(ConfigurationManager.AppSettings["ServiceConnStr"]); for (int i = 0; i < 10; i++) { svcClient.SendAsync(deviceId, createServiceMessage(new { MessageId = i.ToString() })).Wait(); } int cnt = 0; var tokenSource = new CancellationTokenSource(); conn.OnMessage((msg) => { cnt++; if (cnt == 10) { tokenSource.Cancel(); } return(true); }, tokenSource.Token); }
public void Acknowledge_Test() { string deviceId = ConfigurationManager.AppSettings["DeviceId"]; IIotApi conn = getConnector(); ServiceClient svcClient = ServiceClient.CreateFromConnectionString(ConfigurationManager.AppSettings["ServiceConnStr"]); int msgId = new Random().Next(); svcClient.SendAsync(deviceId, createServiceMessage(new { Command = "testrcv", Value = "msg1", MessageId = msgId })).Wait(); for (int i = 0; i < 5; i++) { conn.ReceiveAsync((msg) => { if (msg != null) { dynamic obj = JsonConvert.DeserializeObject(Encoding.UTF8.GetString((byte[])msg)); // This will remove unexpected messages from queue. if (obj.MessageId != msgId) { return(true); } if (i < 3) { return(false); } else { return(true); } } else { return(true); } }, (err) => { throw err; }, 0).Wait(); } }
public IotMockDevice(IIotApi deviceTransport, Dictionary <string, object> rcvAckArgs, Dictionary <string, object> onMsgRcvArgs, Dictionary <string, object> sndArgs, Dictionary <string, object> sndAckArgs, Action <string> traceMethod) { if (m_Transport == null) { throw new ArgumentNullException(); } m_Transport = deviceTransport; m_TraceMethod = traceMethod; m_OnMsgRcvArg = onMsgRcvArgs; m_RcvAckArgs = rcvAckArgs; m_SndAckArgs = sndAckArgs; m_SndAckArgs = sndAckArgs; }
public void ClearQueue_Test() { string deviceId = ConfigurationManager.AppSettings["DeviceId"]; IIotApi conn = getConnector(); ServiceClient svcClient = ServiceClient.CreateFromConnectionString(ConfigurationManager.AppSettings["ServiceConnStr"]); int cnt = 0; var tokenSource = new CancellationTokenSource(); conn.OnMessage((msg) => { if (msg == null) { tokenSource.Cancel(); } return(true); }, tokenSource.Token).Wait(); }
public void MessagePump_Test() { string deviceId = ConfigurationManager.AppSettings["DeviceId"]; IIotApi conn = getConnector(); ServiceClient svcClient = ServiceClient.CreateFromConnectionString(ConfigurationManager.AppSettings["ServiceConnStr"]); for (int j = 0; j < 1000; j++) { for (int i = 0; i < 50; i++) { svcClient.SendAsync(deviceId, createServiceMessage( new { CommandType = "UnitTest", MessageId = i.ToString(), Data = new { Prop1 = "prop1", Prop2 = "prop2" } })).Wait(); } Thread.Sleep(60000); } }
public void ReceiveBatch_Test() { string deviceId = ConfigurationManager.AppSettings["DeviceId"]; IIotApi conn = getConnector(); ServiceClient svcClient = ServiceClient.CreateFromConnectionString(ConfigurationManager.AppSettings["ServiceConnStr"]); int msgId = new Random().Next(); svcClient.SendAsync(deviceId, createServiceMessage(new { Command = "testrcv", Value = "msg1", MessageId = msgId })).Wait(); conn.ReceiveAsync((msg) => { if (msg != null) { dynamic obj = JsonConvert.DeserializeObject(Encoding.UTF8.GetString((byte[])msg)); Assert.IsTrue(obj.Command == "testrcv"); Assert.IsTrue(obj.Value == "msg1"); Assert.IsTrue(obj.MessageId == msgId); } else { Assert.Inconclusive("No message received during test. This might be typically timeout issue. Please restart test."); } return(true); }, (err) => { throw err; }, 0).Wait(); }
public void Open(string hostName, IIotApi client) { throw new NotImplementedException(); }
//public void Open(IIotApi connector, IInjectableModule nextModule, Dictionary<string, object> args = null) //{ // if (connector == null) // throw new IotApiException("Connector must be specified!"); // connector.Open(args); // m_NextModule = nextModule; // m_Connector = connector; //} public bool BeforeReceive(IIotApi connector, object sensorMessage, Dictionary <string, object> args = null) { throw new NotImplementedException(); }