/// <summary> /// Private method to create a protocol driver stack, using the mock class /// for the telegram stack. /// </summary> /// <param name="deviceId">Device Id to setup the stack.</param> /// <param name="commConfig">Communication Configuration to setup the stack.</param> private void createProtocolDriver(int deviceId, Communication commConfig) { _nuvoTelegramMock = new NuvoTelegramMock(); _essentiaProtocol = new NuvoEssentiaProtocol(deviceId, _nuvoTelegramMock); _protDriver = new NuvoEssentiaProtocolDriver(); _protDriver.Open(ENuvoSystem.NuVoEssentia, deviceId, commConfig, _essentiaProtocol); }
public void SendMultipleCommandWithSpontaneousAdditionalAnswers1Test() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol target = new NuvoEssentiaProtocol(1, nuvoTelegram); target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived); // Send ReadStatusCONNECT NuvoEssentiaSingleCommand command1 = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusCONNECT, ENuvoEssentiaZones.Zone2); target.SendCommand(command1); // Send ReadStatusZONE NuvoEssentiaSingleCommand command2 = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusZONE, ENuvoEssentiaZones.Zone2); target.SendCommand(command2); // Send ReadStatusCONNECT NuvoEssentiaSingleCommand command3 = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusCONNECT, ENuvoEssentiaZones.Zone3); target.SendCommand(command3); // Send ReadStatusZONE NuvoEssentiaSingleCommand command4 = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusZONE, ENuvoEssentiaZones.Zone3); target.SendCommand(command4); // Return command for ReadStatusCONNECT nuvoTelegram.passDataToTestClass("Z02PWRON,SRC3,GRP0,VOL-50"); ConreteProtocolEventArgs event1 = _nuvoProtocolEventArgs; // save return argument // Return command for ReadStatusZONE nuvoTelegram.passDataToTestClass("Z02OR0,BASS-00,TREB+00,GRP0,VRST0"); ConreteProtocolEventArgs event2 = _nuvoProtocolEventArgs; // save return argument // Return command for ReadStatusCONNECT nuvoTelegram.passDataToTestClass("Z03PWRON,SRC3,GRP0,VOL-50"); ConreteProtocolEventArgs event3 = _nuvoProtocolEventArgs; // save return argument // Additional command nuvoTelegram.passDataToTestClass("Z06PWRON,SRC6,GRP0,VOL-50"); ConreteProtocolEventArgs eventx = _nuvoProtocolEventArgs; // save return argument // Return command for ReadStatusZONE nuvoTelegram.passDataToTestClass("Z03OR0,BASS-00,TREB+00,GRP0,VRST0"); ConreteProtocolEventArgs event4 = _nuvoProtocolEventArgs; // save return argument Assert.IsTrue(_eventRaisedCount == 5); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, command1.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, event1.Command.Command); Assert.AreEqual(command1.Guid, event1.Command.Guid); // return same instance of command Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusZONE, command2.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusZONE, event2.Command.Command); Assert.AreEqual(command2.Guid, event2.Command.Guid); // return same instance of command Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, command3.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, event3.Command.Command); Assert.AreEqual(command3.Guid, event3.Command.Guid); // return same instance of command Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusZONE, command4.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusZONE, event4.Command.Command); Assert.AreEqual(command4.Guid, event4.Command.Guid); // return same instance of command Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, eventx.Command.Command); }
public void SendCommand7Test() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol target = new NuvoEssentiaProtocol(1, nuvoTelegram); target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived); NuvoEssentiaCommand command = new NuvoEssentiaCommand(ENuvoEssentiaCommands.SetZoneStatus, ENuvoEssentiaZones.Zone4, ENuvoEssentiaSources.Source4, -50); target.SendCommand(command); // Three commands => TurnZoneON, SetVolume and SetSource. nuvoTelegram.passDataToTestClass("Z04PWRON,SRC1,GRP0,VOL-60"); Assert.IsTrue(_eventRaisedCount == 1); Assert.AreEqual(ENuvoEssentiaCommands.TurnZoneON, _nuvoProtocolEventArgs.Command.Command); Assert.AreEqual("Z04ON", _nuvoProtocolEventArgs.Command.OutgoingCommand); nuvoTelegram.passDataToTestClass("Z04PWRON,SRC1,GRP0,VOL-50"); Assert.IsTrue(_eventRaisedCount == 2); Assert.AreEqual(ENuvoEssentiaCommands.SetVolume, _nuvoProtocolEventArgs.Command.Command); Assert.AreEqual("Z04VOL50", _nuvoProtocolEventArgs.Command.OutgoingCommand); nuvoTelegram.passDataToTestClass("Z04PWRON,SRC4,GRP0,VOL-50"); Assert.IsTrue(_eventRaisedCount == 3); Assert.AreEqual(ENuvoEssentiaCommands.SetSource, _nuvoProtocolEventArgs.Command.Command); Assert.AreEqual("Z04SRC4", _nuvoProtocolEventArgs.Command.OutgoingCommand); }
public void SendCommand6Test() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol target = new NuvoEssentiaProtocol(1, nuvoTelegram); target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived); // Command: SetSOURCEIR56 { NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.SetSOURCEIR56, ENuvoEssentiaSources.Source3); target.SendCommand(command); nuvoTelegram.passDataToTestClass("IRSET:56,38,56,38,56,88"); Assert.IsTrue(_eventRaisedCount == 1); // event has been raised 1 times Assert.AreEqual(ENuvoEssentiaCommands.SetSOURCEIR56, command.Command); Assert.AreEqual(ENuvoEssentiaCommands.SetSOURCEIR56, _nuvoProtocolEventArgs.Command.Command); // return same command Assert.AreEqual(command.Guid, _nuvoProtocolEventArgs.Command.Guid); // return same instance of command Assert.AreEqual(EIRCarrierFrequency.IR56kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source1)); Assert.AreEqual(EIRCarrierFrequency.IR38kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source2)); Assert.AreEqual(EIRCarrierFrequency.IR56kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source3)); Assert.AreEqual(EIRCarrierFrequency.IR38kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source4)); Assert.AreEqual(EIRCarrierFrequency.IR56kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source5)); Assert.AreEqual(EIRCarrierFrequency.IRUnknown, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source6)); } // Command: MuteON { NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.MuteON, ENuvoEssentiaZones.Zone11); target.SendCommand(command); nuvoTelegram.passDataToTestClass("Z11PWRON,SRC6,GRP0,VOL-34"); // return value for ReadStatusCONNECT Assert.IsTrue(_eventRaisedCount == 2); Assert.AreEqual(ENuvoEssentiaCommands.MuteON, command.Command); Assert.AreEqual(ENuvoEssentiaCommands.MuteON, _nuvoProtocolEventArgs.Command.Command); // return same command Assert.AreEqual(command.Guid, _nuvoProtocolEventArgs.Command.Guid); // return same instance of command Assert.AreEqual(ENuvoEssentiaZones.Zone11, _nuvoProtocolEventArgs.Command.ZoneId); Assert.AreEqual(ENuvoEssentiaSources.Source6, _nuvoProtocolEventArgs.Command.SourceId); Assert.AreEqual(-34, _nuvoProtocolEventArgs.Command.VolumeLevel); Assert.AreEqual(EZonePowerStatus.ZoneStatusON, _nuvoProtocolEventArgs.Command.PowerStatus); Assert.AreEqual(ESourceGroupStatus.SourceGroupOFF, _nuvoProtocolEventArgs.Command.SourceGrupStatus); } // Command: SetBassLevel { NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.SetBassLevel, ENuvoEssentiaZones.Zone8, 4, 0); target.SendCommand(command); nuvoTelegram.passDataToTestClass("Z08OR0,BASS+04,TREB+00,GRP0,VRST1"); // return value for ReadStatusZONE Assert.IsTrue(_eventRaisedCount == 3); Assert.AreEqual(ENuvoEssentiaCommands.SetBassLevel, command.Command); Assert.AreEqual(ENuvoEssentiaCommands.SetBassLevel, _nuvoProtocolEventArgs.Command.Command); Assert.AreEqual(command.Guid, _nuvoProtocolEventArgs.Command.Guid); Assert.AreEqual(ENuvoEssentiaZones.Zone8, _nuvoProtocolEventArgs.Command.ZoneId); Assert.AreEqual(4, _nuvoProtocolEventArgs.Command.BassLevel); Assert.AreEqual(0, _nuvoProtocolEventArgs.Command.TrebleLevel); Assert.AreEqual(EVolumeResetStatus.VolumeResetON, _nuvoProtocolEventArgs.Command.VolumeResetStatus); Assert.AreEqual(EDIPSwitchOverrideStatus.DIPSwitchOverrideOFF, _nuvoProtocolEventArgs.Command.DIPSwitchOverrideStatus); Assert.AreEqual(ESourceGroupStatus.SourceGroupOFF, _nuvoProtocolEventArgs.Command.SourceGrupStatus); } }
public void NuvoEssentiaProtocolConstructorTest() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol target = new NuvoEssentiaProtocol(1, nuvoTelegram); target.Open(new SerialPortConnectInformation("COM1")); target.Close(); target = null; }
/// <summary> /// Private method to destroy the protocol stack. /// </summary> /// <param name="deviceId">Device Id used to setup the stack.</param> private void destroyProtocolDriver(int deviceId) { if (_protDriver != null) { _protDriver.Close(deviceId); } _protDriver = null; _essentiaProtocol = null; _nuvoTelegramMock = null; }
public void SendCommand8Test() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol target = new NuvoEssentiaProtocol(1, nuvoTelegram); INuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.NoCommand); target.SendCommand(command); // not supported anymore; quick-fix, uncomment unit test -> Assert.AreEqual(0, target._runningCommands.Count); }
public void SendCommand8Test() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol_Accessor target = new NuvoEssentiaProtocol_Accessor(1, nuvoTelegram); INuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.NoCommand); target.SendCommand(command); Assert.AreEqual(0, target._runningCommands.Count); }
public void SendCommand3Test() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol target = new NuvoEssentiaProtocol(1, nuvoTelegram); target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived); target.SendCommand("VER"); nuvoTelegram.passDataToTestClass("MPU_E6Dv1.23"); Assert.IsTrue(_eventRaisedCount == 1); // event has been raised 1 times Assert.AreEqual(ENuvoEssentiaCommands.ReadVersion, _nuvoProtocolEventArgs.Command.Command); // return same command }
public void ReceiveCommand2Test() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol target = new NuvoEssentiaProtocol(1, nuvoTelegram); target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived); // Return command for ReadStatusCONNECT nuvoTelegram.passDataToTestClass("ALLOFF"); ConreteProtocolEventArgs event1 = _nuvoProtocolEventArgs; // save return argument Assert.IsTrue(_eventRaisedCount == 1); Assert.AreEqual(ENuvoEssentiaCommands.TurnALLZoneOFF, event1.Command.Command); }
public void SendCommand4Test() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol target = new NuvoEssentiaProtocol(1, nuvoTelegram); target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived); // Command: ReadVersion { NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadVersion); target.SendCommand(command); nuvoTelegram.passDataToTestClass("MPU_E6Dv1.23"); Assert.IsTrue(_eventRaisedCount == 1); // event has been raised 1 times Assert.AreEqual(ENuvoEssentiaCommands.ReadVersion, command.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadVersion, _nuvoProtocolEventArgs.Command.Command); // return same command Assert.AreEqual(command.Guid, _nuvoProtocolEventArgs.Command.Guid); // return same instance of command } // Command: ReadStatusCONNECT { NuvoEssentiaSingleCommand command2 = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusCONNECT, ENuvoEssentiaZones.Zone2); target.SendCommand(command2); nuvoTelegram.passDataToTestClass("ZxxPWRppp,SRCs,GRPq,VOL-yy"); Assert.IsTrue(_eventRaisedCount == 2); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, command2.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, _nuvoProtocolEventArgs.Command.Command); // return same command Assert.AreEqual(command2.Guid, _nuvoProtocolEventArgs.Command.Guid); // return same instance of command Assert.AreEqual("Z02CONSR", nuvoTelegram.Telegram); } // Command: ReadStatusCONNECT { NuvoEssentiaSingleCommand command3 = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusCONNECT, ENuvoEssentiaZones.Zone6); target.SendCommand(command3); nuvoTelegram.passDataToTestClass("Z06ORp,BASSuuu,TREBttt,GRPq,VRSTr"); // return value for ReadStatusZONE Assert.IsTrue(_eventRaisedCount == 3); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, command3.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusZONE, _nuvoProtocolEventArgs.Command.Command); Assert.AreNotEqual(command3.Guid, _nuvoProtocolEventArgs.Command.Guid); } }
public void ReceiveCommand1Test() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol target = new NuvoEssentiaProtocol(1, nuvoTelegram); target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived); // Return command for ReadStatusCONNECT nuvoTelegram.passDataToTestClass("Z02PWRON,SRC3,GRP0,VOL-50"); ConreteProtocolEventArgs event1 = _nuvoProtocolEventArgs; // save return argument // Return command for ReadStatusCONNECT nuvoTelegram.passDataToTestClass("Z03PWRON,SRC3,GRP0,VOL-50"); ConreteProtocolEventArgs event2 = _nuvoProtocolEventArgs; // save return argument Assert.IsTrue(_eventRaisedCount == 2); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, event1.Command.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, event2.Command.Command); }
public void SendCommand5Test() { NuvoTelegramMock nuvoTelegram = new NuvoTelegramMock(); NuvoEssentiaProtocol target = new NuvoEssentiaProtocol(1, nuvoTelegram); target.onCommandReceived += new ConcreteProtocolEventHandler(serialPort_CommandReceived); // Command: ReadVersion { NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadVersion); target.SendCommand(command); nuvoTelegram.passDataToTestClass("MPU_E6Dv1.23"); Assert.IsTrue(_eventRaisedCount == 1); // event has been raised 1 times Assert.AreEqual(ENuvoEssentiaCommands.ReadVersion, command.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadVersion, _nuvoProtocolEventArgs.Command.Command); // return same command Assert.AreEqual(command.Guid, _nuvoProtocolEventArgs.Command.Guid); // return same instance of command Assert.AreEqual("v1.23", _nuvoProtocolEventArgs.Command.FirmwareVersion); } // Command: ReadStatusSOURCEIR { NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusSOURCEIR); target.SendCommand(command); nuvoTelegram.passDataToTestClass("IRSET:38,56,56,38,38,56"); Assert.IsTrue(_eventRaisedCount == 2); // event has been raised 1 times Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusSOURCEIR, command.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusSOURCEIR, _nuvoProtocolEventArgs.Command.Command); // return same command Assert.AreEqual(command.Guid, _nuvoProtocolEventArgs.Command.Guid); // return same instance of command Assert.AreEqual(EIRCarrierFrequency.IR38kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source1)); Assert.AreEqual(EIRCarrierFrequency.IR38kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source4)); Assert.AreEqual(EIRCarrierFrequency.IR38kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source5)); Assert.AreEqual(EIRCarrierFrequency.IR56kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source2)); Assert.AreEqual(EIRCarrierFrequency.IR56kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source3)); Assert.AreEqual(EIRCarrierFrequency.IR56kHz, _nuvoProtocolEventArgs.Command.IrCarrierFrequencySource(ENuvoEssentiaSources.Source6)); } // Command: ReadStatusCONNECT { NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusCONNECT, ENuvoEssentiaZones.Zone7); target.SendCommand(command); nuvoTelegram.passDataToTestClass("Z07PWROFF,SRC3,GRP1,VOL-34"); Assert.IsTrue(_eventRaisedCount == 3); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, command.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, _nuvoProtocolEventArgs.Command.Command); // return same command Assert.AreEqual(command.Guid, _nuvoProtocolEventArgs.Command.Guid); // return same instance of command Assert.AreEqual(ENuvoEssentiaZones.Zone7, _nuvoProtocolEventArgs.Command.ZoneId); Assert.AreEqual(ENuvoEssentiaSources.Source3, _nuvoProtocolEventArgs.Command.SourceId); Assert.AreEqual(-34, _nuvoProtocolEventArgs.Command.VolumeLevel); Assert.AreEqual(EZonePowerStatus.ZoneStatusOFF, _nuvoProtocolEventArgs.Command.PowerStatus); Assert.AreEqual(ESourceGroupStatus.SourceGroupON, _nuvoProtocolEventArgs.Command.SourceGrupStatus); } // Command: ReadStatusCONNECT { NuvoEssentiaSingleCommand command = new NuvoEssentiaSingleCommand(ENuvoEssentiaCommands.ReadStatusCONNECT, ENuvoEssentiaZones.Zone12); target.SendCommand(command); nuvoTelegram.passDataToTestClass("Z12OR1,BASS-10,TREB+02,GRP1,VRST0"); // return value for ReadStatusZONE Assert.IsTrue(_eventRaisedCount == 4); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusCONNECT, command.Command); Assert.AreEqual(ENuvoEssentiaCommands.ReadStatusZONE, _nuvoProtocolEventArgs.Command.Command); Assert.AreNotEqual(command.Guid, _nuvoProtocolEventArgs.Command.Guid); Assert.AreEqual(ENuvoEssentiaZones.Zone12, _nuvoProtocolEventArgs.Command.ZoneId); Assert.AreEqual(-10, _nuvoProtocolEventArgs.Command.BassLevel); Assert.AreEqual(2, _nuvoProtocolEventArgs.Command.TrebleLevel); Assert.AreEqual(EVolumeResetStatus.VolumeResetOFF, _nuvoProtocolEventArgs.Command.VolumeResetStatus); Assert.AreEqual(EDIPSwitchOverrideStatus.DIPSwitchOverrideON, _nuvoProtocolEventArgs.Command.DIPSwitchOverrideStatus); Assert.AreEqual(ESourceGroupStatus.SourceGroupON, _nuvoProtocolEventArgs.Command.SourceGrupStatus); } }