public void TestDeviceListCmdVersion0() { void CheckMsg(DeviceListVersion0 aMsg) { aMsg.Id.Should().Be(6); aMsg.Devices.Length.Should().Be(2); aMsg.Devices[0].DeviceName.Should().Be("testDev0"); aMsg.Devices[0].DeviceIndex.Should().Be(2); aMsg.Devices[0].DeviceMessages.Length.Should().Be(2); aMsg.Devices[0].DeviceMessages.Should().Contain("StopDeviceCmd", "VibrateCmd"); aMsg.Devices[1].DeviceName.Should().Be("testDev1"); aMsg.Devices[1].DeviceIndex.Should().Be(5); aMsg.Devices[1].DeviceMessages.Length.Should().Be(2); aMsg.Devices[1].DeviceMessages.Should().Contain("StopDeviceCmd", "RotateCmd"); } var msg = new DeviceListVersion0(new[] { new DeviceMessageInfoVersion0(2, "testDev0", new[] { "StopDeviceCmd", "VibrateCmd" }), new DeviceMessageInfoVersion0(5, "testDev1", new[] { "StopDeviceCmd", "RotateCmd" }), }, 6); CheckMsg(msg); var newMsg = CheckParsedVersion <DeviceListVersion0>(msg, 0, "[{\"DeviceList\":{\"Devices\":[{\"DeviceName\":\"testDev0\",\"DeviceIndex\":2,\"DeviceMessages\":[\"StopDeviceCmd\",\"VibrateCmd\"]},{\"DeviceName\":\"testDev1\",\"DeviceIndex\":5,\"DeviceMessages\":[\"StopDeviceCmd\",\"RotateCmd\"]}],\"Id\":6}}]" ); CheckMsg(newMsg); }
public void TestDeviceListCmd() { var msg = new DeviceList(new[] { new DeviceMessageInfo(2, "testDev0", new Dictionary <string, MessageAttributes> { { "StopDeviceCmd", new MessageAttributes() }, { "VibrateCmd", new MessageAttributes() { FeatureCount = 1 } }, }), new DeviceMessageInfo(5, "testDev1", new Dictionary <string, MessageAttributes> { { "StopDeviceCmd", new MessageAttributes() }, { "RotateCmd", new MessageAttributes() { FeatureCount = 2 } }, }), }, 6); Assert.AreEqual(6, msg.Id); Assert.AreEqual(2, msg.Devices.Length); Assert.AreEqual("testDev0", msg.Devices[0].DeviceName); Assert.AreEqual(2, msg.Devices[0].DeviceIndex); Assert.AreEqual(2, msg.Devices[0].DeviceMessages.Count); Assert.Contains("StopDeviceCmd", msg.Devices[0].DeviceMessages.Keys); Assert.Null(msg.Devices[0].DeviceMessages["StopDeviceCmd"].FeatureCount); Assert.Contains("VibrateCmd", msg.Devices[0].DeviceMessages.Keys); Assert.AreEqual(1, msg.Devices[0].DeviceMessages["VibrateCmd"].FeatureCount); Assert.AreEqual("testDev1", msg.Devices[1].DeviceName); Assert.AreEqual(5, msg.Devices[1].DeviceIndex); Assert.AreEqual(2, msg.Devices[1].DeviceMessages.Count); Assert.Contains("StopDeviceCmd", msg.Devices[1].DeviceMessages.Keys); Assert.Null(msg.Devices[1].DeviceMessages["StopDeviceCmd"].FeatureCount); Assert.Contains("RotateCmd", msg.Devices[1].DeviceMessages.Keys); Assert.AreEqual(2, msg.Devices[1].DeviceMessages["RotateCmd"].FeatureCount); var str1 = _parser.Serialize(msg, 1); Assert.AreEqual( "[{\"DeviceList\":{\"Devices\":[{\"DeviceName\":\"testDev0\",\"DeviceIndex\":2,\"DeviceMessages\":{\"StopDeviceCmd\":{},\"VibrateCmd\":{\"FeatureCount\":1}}},{\"DeviceName\":\"testDev1\",\"DeviceIndex\":5,\"DeviceMessages\":{\"StopDeviceCmd\":{},\"RotateCmd\":{\"FeatureCount\":2}}}],\"Id\":6}}]", str1); var msgs = _parser.Deserialize(str1); Assert.AreEqual(1, msgs.Length); Assert.True(msgs[0] is DeviceList); var msg1 = (DeviceList)msgs[0]; Assert.AreEqual(6, msg1.Id); Assert.AreEqual(2, msg1.Devices.Length); Assert.AreEqual("testDev0", msg1.Devices[0].DeviceName); Assert.AreEqual(2, msg1.Devices[0].DeviceIndex); Assert.AreEqual(2, msg1.Devices[0].DeviceMessages.Count); Assert.Contains("StopDeviceCmd", msg1.Devices[0].DeviceMessages.Keys); Assert.Null(msg1.Devices[0].DeviceMessages["StopDeviceCmd"].FeatureCount); Assert.Contains("VibrateCmd", msg1.Devices[0].DeviceMessages.Keys); Assert.AreEqual(1, msg1.Devices[0].DeviceMessages["VibrateCmd"].FeatureCount); Assert.AreEqual("testDev1", msg1.Devices[1].DeviceName); Assert.AreEqual(5, msg1.Devices[1].DeviceIndex); Assert.AreEqual(2, msg1.Devices[1].DeviceMessages.Count); Assert.Contains("StopDeviceCmd", msg1.Devices[1].DeviceMessages.Keys); Assert.Null(msg1.Devices[1].DeviceMessages["StopDeviceCmd"].FeatureCount); Assert.Contains("RotateCmd", msg1.Devices[1].DeviceMessages.Keys); Assert.AreEqual(2, msg1.Devices[1].DeviceMessages["RotateCmd"].FeatureCount); var str0 = _parser.Serialize(msg, 0); Assert.AreEqual( "[{\"DeviceList\":{\"Devices\":[{\"DeviceName\":\"testDev0\",\"DeviceIndex\":2,\"DeviceMessages\":[\"StopDeviceCmd\",\"VibrateCmd\"]},{\"DeviceName\":\"testDev1\",\"DeviceIndex\":5,\"DeviceMessages\":[\"StopDeviceCmd\",\"RotateCmd\"]}],\"Id\":6}}]", str0); msgs = _parser.Deserialize(str0); Assert.AreEqual(1, msgs.Length); Assert.True(msgs[0] is DeviceListVersion0); var msg0 = (DeviceListVersion0)msgs[0]; Assert.AreEqual(6, msg0.Id); Assert.AreEqual(2, msg0.Devices.Length); Assert.AreEqual("testDev0", msg0.Devices[0].DeviceName); Assert.AreEqual(2, msg0.Devices[0].DeviceIndex); Assert.AreEqual(2, msg0.Devices[0].DeviceMessages.Length); Assert.Contains("StopDeviceCmd", msg0.Devices[0].DeviceMessages); Assert.Contains("VibrateCmd", msg0.Devices[0].DeviceMessages); Assert.AreEqual("testDev1", msg0.Devices[1].DeviceName); Assert.AreEqual(5, msg0.Devices[1].DeviceIndex); Assert.AreEqual(2, msg0.Devices[1].DeviceMessages.Length); Assert.Contains("StopDeviceCmd", msg0.Devices[1].DeviceMessages); Assert.Contains("RotateCmd", msg0.Devices[1].DeviceMessages); msg0 = new DeviceListVersion0(new[] { new DeviceMessageInfoVersion0(2, "testDev0", new[] { "StopDeviceCmd", "VibrateCmd" }), new DeviceMessageInfoVersion0(5, "testDev1", new[] { "StopDeviceCmd", "RotateCmd" }), }, 6); Assert.AreEqual(6, msg0.Id); Assert.AreEqual(2, msg0.Devices.Length); Assert.AreEqual("testDev0", msg0.Devices[0].DeviceName); Assert.AreEqual(2, msg0.Devices[0].DeviceIndex); Assert.AreEqual(2, msg0.Devices[0].DeviceMessages.Length); Assert.Contains("StopDeviceCmd", msg0.Devices[0].DeviceMessages); Assert.Contains("VibrateCmd", msg0.Devices[0].DeviceMessages); Assert.AreEqual("testDev1", msg0.Devices[1].DeviceName); Assert.AreEqual(5, msg0.Devices[1].DeviceIndex); Assert.AreEqual(2, msg0.Devices[1].DeviceMessages.Length); Assert.Contains("StopDeviceCmd", msg0.Devices[1].DeviceMessages); Assert.Contains("RotateCmd", msg0.Devices[1].DeviceMessages); }