コード例 #1
0
        private void testReceiveX10Command(string houseCode, X10Command command, byte x10Code)
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                .IncomingMessage(0x02, 0x52, x10Code, 0x80);

                var plm  = buildPlmForTest(scenario.Playback());
                var test = plm.Network.X10;

                int        eventCount     = 0;
                object     sender         = null;
                string     eventHouseCode = null;
                X10Command eventCommand   = 0;
                test.CommandReceived += new X10CommandReceivedHandler((s, e) =>
                {
                    sender         = s;
                    eventHouseCode = e.HouseCode;
                    eventCommand   = e.Command;
                    eventCount++;
                });

                plm.Receive();
                Assert.AreEqual(1, eventCount);
                Assert.AreEqual(test, sender);
                Assert.AreEqual(houseCode, eventHouseCode);
                Assert.AreEqual(command, eventCommand);
            }
        }
コード例 #2
0
        public void Can_get_a_database_with_one_record()
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                .ShouldSend(0x02, 0x69)
                .AndReceive(0x02, 0x69, 0x06);     // has at least one record

                scenario
                .WaitsForMessageOfType(0x57)
                .AndReceives(0x02, 0x57, FLAGS_NOT_MASTER, ALL_LINK_GROUP, ID1_HI, ID1_MIDDLE, ID1_LO, 0xAA, 0xBB, 0xCC);

                scenario
                .ShouldSend(0x02, 0x6A)
                .AndReceive(0x02, 0x6A, 0x15);     // no more

                var test = buildObjectForTest(scenario.Playback());
                Assert.AreEqual(1, test.Records.Count);

                var record = test.Records[0];
                Assert.IsFalse(record.PlmIsMaster);
                Assert.AreEqual(0xAA, record.LinkSpecificData(0));
                Assert.AreEqual(0xBB, record.LinkSpecificData(1));
                Assert.AreEqual(0xCC, record.LinkSpecificData(2));
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        public void Can_get_a_database_with_one_record()
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .ShouldSend(0x02, 0x69)
                    .AndReceive(0x02, 0x69, 0x06); // has at least one record

                scenario
                    .WaitsForMessageOfType(0x57)
                    .AndReceives(0x02, 0x57, FLAGS_NOT_MASTER, ALL_LINK_GROUP, ID1_HI, ID1_MIDDLE, ID1_LO, 0xAA, 0xBB, 0xCC);

                scenario
                    .ShouldSend(0x02, 0x6A)
                    .AndReceive(0x02, 0x6A, 0x15); // no more

                var test = buildObjectForTest(scenario.Playback());
                Assert.AreEqual(1, test.Records.Count);

                var record = test.Records[0];
                Assert.IsFalse(record.PlmIsMaster);
                Assert.AreEqual(0xAA, record.LinkSpecificData(0));
                Assert.AreEqual(0xBB, record.LinkSpecificData(1));
                Assert.AreEqual(0xCC, record.LinkSpecificData(2));
            }
        }
コード例 #5
0
 public void Can_get_X10_context()
 {
     using (var scenario = new SerialPortScenario())
     {
         var           plm  = buildPlmForTest(scenario.Playback());
         var           test = plm.Network;
         PlmNetworkX10 x10  = test.X10;
     }
 }
コード例 #6
0
        public void Can_turn_off_LED()
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                .ShouldSend(0x02, 0x6E)
                .AndReceive(0x02, 0x6E, Constants.ACK);

                var test = buildObjectForTest(scenario.Playback());
                Assert.AreSame(test, test.TurnOff());
            }
        }
コード例 #7
0
        public void Can_turn_on_LED()
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .ShouldSend(0x02, 0x6D)
                    .AndReceive(0x02, 0x6D, Constants.ACK);

                var test = buildObjectForTest(scenario.Playback());
                Assert.AreSame(test, test.TurnOn());
            }
        }
コード例 #8
0
        public void Can_get_empty_database()
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                .ShouldSend(0x02, 0x69)
                .AndReceive(0x02, 0x69, 0x15);     // db empty

                var test = buildObjectForTest(scenario.Playback());
                Assert.AreEqual(0, test.Records.Count);
            }
        }
コード例 #9
0
        public void testAllLinkingCompletedEvent(byte linkCode, byte group)
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                .IncomingMessage(0x02, 0x53, linkCode, group,
                                 TestDeviceHelper.PEER_ID_HI,
                                 TestDeviceHelper.PEER_ID_MI,
                                 TestDeviceHelper.PEER_ID_LO,
                                 PEER_DEVCAT,
                                 PEER_DEVSUB,
                                 0xFF);

                var plm  = buildPlmForTest(scenario.Playback());
                var test = plm.Network;

                int eventCount = 0;
                test.AllLinkingCompleted += new AllLinkingCompletedHandler((s, e) =>
                {
                    Assert.AreSame(test, s);
                    Assert.AreEqual(group, e.AllLinkGroup);
                    switch (linkCode)
                    {
                    case 0x00:
                        Assert.AreEqual(AllLinkingAction.LinkedWithPlmAsSlave, e.AllLinkingAction);
                        break;

                    case 0x01:
                        Assert.AreEqual(AllLinkingAction.LinkedWithPlmAsMaster, e.AllLinkingAction);
                        break;

                    case 0xFF:
                        Assert.AreEqual(AllLinkingAction.LinkDeleted, e.AllLinkingAction);
                        break;

                    default:
                        throw new InvalidOperationException();
                    }
                    Assert.AreEqual(TestDeviceHelper.PEER_ID_STRING, e.PeerId.ToString());
                    Assert.AreEqual(PEER_DEVCAT, e.DeviceCategoryCode);
                    Assert.AreEqual(PEER_DEVSUB, e.DeviceSubcategoryCode);
                    string devCat    = Constants.DeviceCategoryLookup[PEER_DEVCAT];
                    string devSubcat = Constants.DeviceSubcategoryLookup[PEER_DEVCAT][PEER_DEVSUB];
                    Assert.AreEqual(devCat, e.DeviceCategory);
                    Assert.AreEqual(devSubcat, e.DeviceSubcategory);
                    eventCount++;
                });

                plm.Receive();
                Assert.AreEqual(1, eventCount);
            }
        }
コード例 #10
0
        private void testX10Command(string houseCode, X10Command command, byte x10Code)
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                .ShouldSend(0x02, 0x63, x10Code, 0x80)
                .AndReceive(0x02, 0x63, x10Code, 0x80, Constants.ACK);

                var plm = buildPlmForTest(scenario.Playback());

                plm.Network.X10
                .House(houseCode)
                .Command(command);
            }
        }
コード例 #11
0
        private void testConfigurationChange(byte initialConfiguration, byte newConfiguration, Func <PlmLed, PlmLed> testAction)
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                .ShouldSend(0x02, 0x73)
                .AndReceive(0x02, 0x73, initialConfiguration, 0x00, 0x00, Constants.ACK);
                scenario
                .ShouldSend(0x02, 0x6B, newConfiguration)
                .AndReceive(0x02, 0x6B, newConfiguration, Constants.ACK);

                var test = buildObjectForTest(scenario.Playback());
                Assert.AreSame(test, testAction(test));
            }
        }
コード例 #12
0
        private void testHouseCodeAndUnit(string houseCode, byte unitCode, byte x10Code)
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                .ShouldSend(0x02, 0x63, x10Code, 0x00)
                .AndReceive(0x02, 0x63, x10Code, 0x00, Constants.ACK);

                var plm = buildPlmForTest(scenario.Playback());

                plm.Network.X10
                .House(houseCode)
                .Unit(unitCode);
            }
        }
コード例 #13
0
        public void Can_get_configuration()
        {
            const byte CONFIGURATION = Constants.CONFIG_MANUAL_LED_CONTROL | Constants.CONFIG_DISABLE_AUTO_LINKING;

            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .ShouldSend(0x02, 0x73)
                    .AndReceive(0x02, 0x73, CONFIGURATION, 0x00, 0x00, Constants.ACK);

                var test = buildObjectForTest(scenario.Playback());
                var configuration = test.GetConfiguration();

                Assert.IsTrue(configuration.AutoLinkingDisabled);
                Assert.IsFalse(configuration.MonitorMode);
                Assert.IsTrue(configuration.ManualLedControl);
                Assert.IsFalse(configuration.Rs232Deadman);
            }
        }
コード例 #14
0
ファイル: TestPlm.cs プロジェクト: kouweizhong/FluentDwelling
        public void Can_get_configuration()
        {
            const byte CONFIGURATION = Constants.CONFIG_MANUAL_LED_CONTROL | Constants.CONFIG_DISABLE_AUTO_LINKING;

            using (var scenario = new SerialPortScenario())
            {
                scenario
                .ShouldSend(0x02, 0x73)
                .AndReceive(0x02, 0x73, CONFIGURATION, 0x00, 0x00, Constants.ACK);

                var test          = buildObjectForTest(scenario.Playback());
                var configuration = test.GetConfiguration();

                Assert.IsTrue(configuration.AutoLinkingDisabled);
                Assert.IsFalse(configuration.MonitorMode);
                Assert.IsTrue(configuration.ManualLedControl);
                Assert.IsFalse(configuration.Rs232Deadman);
            }
        }
コード例 #15
0
        public void Fires_event_when_set_button_pressed_and_held()
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .IncomingMessage(0x02, 0x54, 0x03);

                var plm = buildPlmForTest(scenario.Playback());
                var test = plm.SetButton;

                int eventCount = 0;
                test.PressedAndHeld += new EventHandler((s, e) =>
                {
                    Assert.AreSame(test, s);
                    eventCount++;
                });

                plm.Receive();
                Assert.AreEqual(1, eventCount);
            }
        }
コード例 #16
0
        public void Fires_event_when_set_button_released_after_being_held()
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                .IncomingMessage(0x02, 0x54, 0x04);

                var plm  = buildPlmForTest(scenario.Playback());
                var test = plm.SetButton;

                int eventCount = 0;
                test.ReleasedAfterHolding += new EventHandler((s, e) =>
                {
                    Assert.AreSame(test, s);
                    eventCount++;
                });

                plm.Receive();
                Assert.AreEqual(1, eventCount);
            }
        }
コード例 #17
0
        public void Fires_event_when_set_button_held_during_power_up()
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                .IncomingMessage(0x02, 0x55);

                var plm  = buildPlmForTest(scenario.Playback());
                var test = plm.SetButton;

                int eventCount = 0;
                test.UserReset += new EventHandler((s, e) =>
                {
                    Assert.AreSame(test, s);
                    eventCount++;
                });

                plm.Receive();
                Assert.AreEqual(1, eventCount);
            }
        }
コード例 #18
0
        public void Can_get_a_database_with_two_records()
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                .ShouldSend(0x02, 0x69)
                .AndReceive(0x02, 0x69, 0x06);     // has at least one record

                scenario
                .WaitsForMessageOfType(0x57)
                .AndReceives(0x02, 0x57, FLAGS, ALL_LINK_GROUP, ID1_HI, ID1_MIDDLE, ID1_LO, 0, 0, 0);

                scenario
                .ShouldSend(0x02, 0x6A)
                .AndReceive(0x02, 0x6A, 0x06);     // more

                scenario
                .WaitsForMessageOfType(0x57)
                .AndReceives(0x02, 0x57, FLAGS_NOT_IN_USE, ALL_LINK_GROUP, ID2_HI, ID2_MIDDLE, ID2_LO, 0, 0, 0);

                scenario
                .ShouldSend(0x02, 0x6A)
                .AndReceive(0x02, 0x6A, 0x15);     // no more

                var test = buildObjectForTest(scenario.Playback());
                Assert.AreEqual(2, test.Records.Count);

                var record1 = test.Records[0];
                Assert.AreEqual(ID1, record1.DeviceId.ToString());
                Assert.AreEqual(ALL_LINK_GROUP, record1.AllLinkGroup);
                Assert.IsTrue(record1.InUse);
                Assert.IsTrue(record1.PlmIsMaster);

                var record2 = test.Records[1];
                Assert.AreEqual(ID2, record2.DeviceId.ToString());
                Assert.AreEqual(ALL_LINK_GROUP, record2.AllLinkGroup);
                Assert.IsFalse(record2.InUse);
                Assert.IsTrue(record2.PlmIsMaster);
            }
        }
コード例 #19
0
        private void testStandardMessageReceivedEvent(byte command1, byte command2)
        {
            const byte FLAGS = Constants.MSG_FLAGS_GROUP_BROADCAST | Constants.MSG_FLAGS_MAX_HOPS;

            using (var scenario = new SerialPortScenario())
            {
                scenario
                .IncomingMessage(0x02, 0x50,
                                 TestDeviceHelper.PEER_ID_HI,
                                 TestDeviceHelper.PEER_ID_MI,
                                 TestDeviceHelper.PEER_ID_LO,
                                 0x00, // ignored
                                 0x00, // ignored
                                 0x04, // ignored
                                 FLAGS,
                                 command1,
                                 command2);

                var plm  = buildPlmForTest(scenario.Playback());
                var test = plm.Network;

                int eventCount = 0;
                test.StandardMessageReceived += new StandardMessageReceivedHandler((s, e) =>
                {
                    Assert.AreSame(test, s);
                    Assert.AreEqual(FLAGS, e.RawFlags);
                    Assert.AreEqual(command1, e.Command1);
                    Assert.AreEqual(command2, e.Command2);

                    Assert.AreEqual(TestDeviceHelper.PEER_ID_STRING, e.PeerId.ToString());
                    eventCount++;
                });

                plm.Receive();
                Assert.AreEqual(1, eventCount);
            }
        }
コード例 #20
0
        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);
            }
        }
コード例 #21
0
ファイル: TestPlm.cs プロジェクト: kouweizhong/FluentDwelling
        public void Can_get_info()
        {
            const byte ID_HI              = 0x08;
            const byte ID_MIDDLE          = 0x09;
            const byte ID_LO              = 0x0A;
            const byte DEVICE_CATEGORY    = 0x0B;
            const byte DEVICE_SUBCATEGORY = 0x0C;
            const byte FIRMWARE_VERSION   = 0x0D;

            using (var scenario = new SerialPortScenario())
            {
                scenario
                .ShouldSend(0x02, 0x60)
                .AndReceive(0x02, 0x60, ID_HI, ID_MIDDLE, ID_LO, DEVICE_CATEGORY, DEVICE_SUBCATEGORY, FIRMWARE_VERSION, Constants.ACK);

                var test = buildObjectForTest(scenario.Playback());
                var info = test.GetInfo();

                Assert.AreEqual("08.09.0A", info.DeviceId.ToString());
                Assert.AreEqual(DEVICE_CATEGORY, info.DeviceCategoryCode);
                Assert.AreEqual(DEVICE_SUBCATEGORY, info.DeviceSubcategoryCode);
                Assert.AreEqual(FIRMWARE_VERSION, info.FirmwareVersion);
            }
        }
コード例 #22
0
        public void Can_get_info()
        {
            const byte ID_HI = 0x08;
            const byte ID_MIDDLE = 0x09;
            const byte ID_LO = 0x0A;
            const byte DEVICE_CATEGORY = 0x0B;
            const byte DEVICE_SUBCATEGORY = 0x0C;
            const byte FIRMWARE_VERSION = 0x0D;

            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .ShouldSend(0x02, 0x60)
                    .AndReceive(0x02, 0x60, ID_HI, ID_MIDDLE, ID_LO, DEVICE_CATEGORY, DEVICE_SUBCATEGORY, FIRMWARE_VERSION, Constants.ACK);

                var test = buildObjectForTest(scenario.Playback());
                var info = test.GetInfo();

                Assert.AreEqual("08.09.0A", info.DeviceId.ToString());
                Assert.AreEqual(DEVICE_CATEGORY, info.DeviceCategoryCode);
                Assert.AreEqual(DEVICE_SUBCATEGORY, info.DeviceSubcategoryCode);
                Assert.AreEqual(FIRMWARE_VERSION, info.FirmwareVersion);
            }
        }
コード例 #23
0
        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);
            }
        }
コード例 #24
0
        private void testX10Command(string houseCode, X10Command command, byte x10Code)
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .ShouldSend(0x02, 0x63, x10Code, 0x80)
                    .AndReceive(0x02, 0x63, x10Code, 0x80, Constants.ACK);

                var plm = buildPlmForTest(scenario.Playback());

                plm.Network.X10
                    .House(houseCode)
                    .Command(command);
            }
        }
コード例 #25
0
        private void testReceiveX10HouseAndUnit(string houseCode, byte unitCode, byte x10Code)
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .IncomingMessage(0x02, 0x52, x10Code, 0x00);

                var plm = buildPlmForTest(scenario.Playback());
                var test = plm.Network.X10;

                int eventCount = 0;
                object sender = null;
                string eventHouseCode = null;
                byte eventUnitCode = 0;
                test.UnitAddressed += new X10UnitAddressedHandler((s, e) =>
                {
                    sender = s;
                    eventHouseCode = e.HouseCode;
                    eventUnitCode = e.UnitCode;
                    eventCount++;
                });

                plm.Receive();
                Assert.AreEqual(1, eventCount);
                Assert.AreEqual(test, sender);
                Assert.AreEqual(houseCode, eventHouseCode);
                Assert.AreEqual(unitCode, eventUnitCode);
            }
        }
コード例 #26
0
        private void testHouseCodeAndUnit(string houseCode, byte unitCode, byte x10Code)
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .ShouldSend(0x02, 0x63, x10Code, 0x00)
                    .AndReceive(0x02, 0x63, x10Code, 0x00, Constants.ACK);

                var plm = buildPlmForTest(scenario.Playback());

                plm.Network.X10
                    .House(houseCode)
                    .Unit(unitCode);
            }
        }
コード例 #27
0
        private void testConfigurationChange(byte initialConfiguration, byte newConfiguration, Func<PlmLed,PlmLed> testAction)
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .ShouldSend(0x02, 0x73)
                    .AndReceive(0x02, 0x73, initialConfiguration, 0x00, 0x00, Constants.ACK);
                scenario
                    .ShouldSend(0x02, 0x6B, newConfiguration)
                    .AndReceive(0x02, 0x6B, newConfiguration, Constants.ACK);

                var test = buildObjectForTest(scenario.Playback());
                Assert.AreSame(test, testAction(test));
            }
        }
コード例 #28
0
        private void testStandardMessageReceivedEvent(byte command1, byte command2)
        {
            const byte FLAGS = Constants.MSG_FLAGS_GROUP_BROADCAST | Constants.MSG_FLAGS_MAX_HOPS;
            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .IncomingMessage(0x02, 0x50,
                        TestDeviceHelper.PEER_ID_HI,
                        TestDeviceHelper.PEER_ID_MI,
                        TestDeviceHelper.PEER_ID_LO,
                        0x00, // ignored
                        0x00, // ignored
                        0x04, // ignored
                        FLAGS,
                        command1,
                        command2);

                var plm = buildPlmForTest(scenario.Playback());
                var test = plm.Network;

                int eventCount = 0;
                test.StandardMessageReceived += new StandardMessageReceivedHandler((s, e) =>
                {
                    Assert.AreSame(test, s);
                    Assert.AreEqual(FLAGS, e.RawFlags);
                    Assert.AreEqual(command1, e.Command1);
                    Assert.AreEqual(command2, e.Command2);

                    Assert.AreEqual(TestDeviceHelper.PEER_ID_STRING, e.PeerId.ToString());
                    eventCount++;
                });

                plm.Receive();
                Assert.AreEqual(1, eventCount);
            }
        }
コード例 #29
0
        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);
            }
        }
コード例 #30
0
        public void Can_get_empty_database()
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .ShouldSend(0x02, 0x69)
                    .AndReceive(0x02, 0x69, 0x15); // db empty

                var test = buildObjectForTest(scenario.Playback());
                Assert.AreEqual(0, test.Records.Count);
            }
        }
コード例 #31
0
 public void Can_get_X10_context()
 {
     using (var scenario = new SerialPortScenario())
     {
         var plm = buildPlmForTest(scenario.Playback());
         var test = plm.Network;
         PlmNetworkX10 x10 = test.X10;
     }
 }
コード例 #32
0
        public void Can_get_a_database_with_two_records()
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .ShouldSend(0x02, 0x69)
                    .AndReceive(0x02, 0x69, 0x06); // has at least one record

                scenario
                    .WaitsForMessageOfType(0x57)
                    .AndReceives(0x02, 0x57, FLAGS, ALL_LINK_GROUP, ID1_HI, ID1_MIDDLE, ID1_LO, 0, 0, 0);

                scenario
                    .ShouldSend(0x02, 0x6A)
                    .AndReceive(0x02, 0x6A, 0x06); // more

                scenario
                    .WaitsForMessageOfType(0x57)
                    .AndReceives(0x02, 0x57, FLAGS_NOT_IN_USE, ALL_LINK_GROUP, ID2_HI, ID2_MIDDLE, ID2_LO, 0, 0, 0);

                scenario
                    .ShouldSend(0x02, 0x6A)
                    .AndReceive(0x02, 0x6A, 0x15); // no more

                var test = buildObjectForTest(scenario.Playback());
                Assert.AreEqual(2, test.Records.Count);

                var record1 = test.Records[0];
                Assert.AreEqual(ID1, record1.DeviceId.ToString());
                Assert.AreEqual(ALL_LINK_GROUP, record1.AllLinkGroup);
                Assert.IsTrue(record1.InUse);
                Assert.IsTrue(record1.PlmIsMaster);

                var record2 = test.Records[1];
                Assert.AreEqual(ID2, record2.DeviceId.ToString());
                Assert.AreEqual(ALL_LINK_GROUP, record2.AllLinkGroup);
                Assert.IsFalse(record2.InUse);
                Assert.IsTrue(record2.PlmIsMaster);

            }
        }
コード例 #33
0
        public void testAllLinkingCompletedEvent(byte linkCode, byte group)
        {
            using (var scenario = new SerialPortScenario())
            {
                scenario
                    .IncomingMessage(0x02, 0x53, linkCode, group,
                        TestDeviceHelper.PEER_ID_HI,
                        TestDeviceHelper.PEER_ID_MI,
                        TestDeviceHelper.PEER_ID_LO,
                        PEER_DEVCAT,
                        PEER_DEVSUB,
                        0xFF);

                var plm = buildPlmForTest(scenario.Playback());
                var test = plm.Network;

                int eventCount = 0;
                test.AllLinkingCompleted += new AllLinkingCompletedHandler((s, e) =>
                {
                    Assert.AreSame(test, s);
                    Assert.AreEqual(group, e.AllLinkGroup);
                    switch (linkCode)
                    {
                        case 0x00:
                            Assert.AreEqual(AllLinkingAction.LinkedWithPlmAsSlave, e.AllLinkingAction);
                            break;
                        case 0x01:
                            Assert.AreEqual(AllLinkingAction.LinkedWithPlmAsMaster, e.AllLinkingAction);
                            break;
                        case 0xFF:
                            Assert.AreEqual(AllLinkingAction.LinkDeleted, e.AllLinkingAction);
                            break;
                        default:
                            throw new InvalidOperationException();
                    }
                    Assert.AreEqual(TestDeviceHelper.PEER_ID_STRING, e.PeerId.ToString());
                    Assert.AreEqual(PEER_DEVCAT, e.DeviceCategoryCode);
                    Assert.AreEqual(PEER_DEVSUB, e.DeviceSubcategoryCode);
                    string devCat = Constants.DeviceCategoryLookup[PEER_DEVCAT];
                    string devSubcat = Constants.DeviceSubcategoryLookup[PEER_DEVCAT][PEER_DEVSUB];
                    Assert.AreEqual(devCat, e.DeviceCategory);
                    Assert.AreEqual(devSubcat, e.DeviceSubcategory);
                    eventCount++;
                });

                plm.Receive();
                Assert.AreEqual(1, eventCount);
            }
        }