private void testGettingDevice(Func <PlmNetwork, DeviceBase> testFunc) { using (var scenario = new SerialPortScenario()) { const byte RECV_MESSAGE_FLAGS_SB = Constants.MSG_FLAGS_BROADCAST; scenario.SetupSendStandardCommandReceiveAck(0x10, 0x00); scenario .WaitsForMessageOfType(0x50) .AndReceives(0x02, 0x50, TestDeviceHelper.PEER_ID_HI, TestDeviceHelper.PEER_ID_MI, TestDeviceHelper.PEER_ID_LO, PEER_DEVCAT, PEER_DEVSUB, PEER_FIRMWARE, RECV_MESSAGE_FLAGS_SB, 0x01, 0xFF); var plm = buildPlmForTest(scenario.Playback()); var test = plm.Network; var device = testFunc(test); Assert.IsNotNull(device); Assert.AreEqual(TestDeviceHelper.PEER_ID_STRING, device.DeviceId.ToString()); string devCat = Constants.DeviceCategoryLookup[PEER_DEVCAT]; string devSubcat = Constants.DeviceSubcategoryLookup[PEER_DEVCAT][PEER_DEVSUB]; Assert.AreEqual(devCat, device.DeviceCategory); Assert.AreEqual(devSubcat, device.DeviceSubcategory); Assert.IsInstanceOf <LightingControl>(device); Assert.IsInstanceOf <DimmableLightingControl>(device); } }
public void Caches_devices_and_returns_same_object_if_called_twice() { using (var scenario = new SerialPortScenario()) { const byte RECV_MESSAGE_FLAGS_SB = Constants.MSG_FLAGS_BROADCAST; scenario.SetupSendStandardCommandReceiveAck(0x10, 0x00); scenario .WaitsForMessageOfType(0x50) .AndReceives(0x02, 0x50, TestDeviceHelper.PEER_ID_HI, TestDeviceHelper.PEER_ID_MI, TestDeviceHelper.PEER_ID_LO, PEER_DEVCAT, PEER_DEVSUB, PEER_FIRMWARE, RECV_MESSAGE_FLAGS_SB, 0x01, 0xFF); var plm = buildPlmForTest(scenario.Playback()); var test = plm.Network; DeviceBase firstDevice; DeviceBase secondDevice; Assert.IsTrue(test.TryConnectToDevice(TestDeviceHelper.PEER_ID_STRING, out firstDevice)); Assert.IsTrue(test.TryConnectToDevice(TestDeviceHelper.PEER_ID_STRING, out secondDevice)); Assert.AreSame(firstDevice, secondDevice); } }
public void Caches_devices_and_returns_same_object_if_called_twice() { using (var scenario = new SerialPortScenario()) { const byte RECV_MESSAGE_FLAGS_SB = Constants.MSG_FLAGS_BROADCAST; scenario.SetupSendStandardCommandReceiveAck(0x10, 0x00); scenario .WaitsForMessageOfType(0x50) .AndReceives(0x02, 0x50, TestDeviceHelper.PEER_ID_HI, TestDeviceHelper.PEER_ID_MI, TestDeviceHelper.PEER_ID_LO, PEER_DEVCAT, PEER_DEVSUB, PEER_FIRMWARE, RECV_MESSAGE_FLAGS_SB, 0x01, 0xFF); var plm = buildPlmForTest(scenario.Playback()); var test = plm.Network; DeviceBase firstDevice; DeviceBase secondDevice; Assert.IsTrue(test.TryConnectToDevice(TestDeviceHelper.PEER_ID_STRING, out firstDevice)); Assert.IsTrue(test.TryConnectToDevice(TestDeviceHelper.PEER_ID_STRING, out secondDevice)); Assert.AreSame(firstDevice, secondDevice); } }
private void testGettingDevice(Func<PlmNetwork, DeviceBase> testFunc) { using (var scenario = new SerialPortScenario()) { const byte RECV_MESSAGE_FLAGS_SB = Constants.MSG_FLAGS_BROADCAST; scenario.SetupSendStandardCommandReceiveAck(0x10, 0x00); scenario .WaitsForMessageOfType(0x50) .AndReceives(0x02, 0x50, TestDeviceHelper.PEER_ID_HI, TestDeviceHelper.PEER_ID_MI, TestDeviceHelper.PEER_ID_LO, PEER_DEVCAT, PEER_DEVSUB, PEER_FIRMWARE, RECV_MESSAGE_FLAGS_SB, 0x01, 0xFF); var plm = buildPlmForTest(scenario.Playback()); var test = plm.Network; var device = testFunc(test); Assert.IsNotNull(device); Assert.AreEqual(TestDeviceHelper.PEER_ID_STRING, device.DeviceId.ToString()); string devCat = Constants.DeviceCategoryLookup[PEER_DEVCAT]; string devSubcat = Constants.DeviceSubcategoryLookup[PEER_DEVCAT][PEER_DEVSUB]; Assert.AreEqual(devCat, device.DeviceCategory); Assert.AreEqual(devSubcat, device.DeviceSubcategory); Assert.IsInstanceOf<LightingControl>(device); Assert.IsInstanceOf<DimmableLightingControl>(device); } }