Example #1
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));
            }
        }
        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));
            }
        }
Example #3
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));
            }
        }
        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());
            }
        }
Example #5
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());
            }
        }
Example #6
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);
            }
        }
Example #7
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);
            }
        }
Example #8
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);
            }
        }
Example #9
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);
            }
        }
Example #10
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);
            }
        }
Example #11
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);
            }
        }
        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);

            }
        }
Example #13
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);
            }
        }
Example #14
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);
            }
        }
        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);
            }
        }
        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);
            }
        }
        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));
            }
        }
        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);
            }
        }