public void Verify_Solenoid_Close_Command() { TestStandMapping mapping = new TestStandMapping(); Session session = new Session(mapping); DataStore dataStore = new DataStore(session); Mock <IUserInterface> ui = new Mock <IUserInterface>(); Mock <LogThread> logThread = new Mock <LogThread>(dataStore); IOThread ioThread = new IOThread(dataStore, ref session); Program p = new Program(dataStore, logThread.Object, ioThread, ui.Object); SolenoidCommand sc = new SolenoidCommand(3, false); byte[] actual = {}; Mock <ISerialPort> serial = new Mock <ISerialPort>(); serial.Setup(x => x.IsOpen).Returns(true); serial.Setup(x => x.Write(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>())) .Callback((byte[] b, int o, int c) => { actual = b; }); ioThread.StartConnection(serial.Object, null); p.OnCommand(sc); Thread.Sleep(IOThread.AckWaitMillis - 10); ioThread.StopConnection(); byte[] expected = { 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x00, 0x03, 0x03, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF }; Assert.AreEqual(expected, actual); }
public void OnSolenoidPressed(SolenoidComponent solenoid, bool open) { SolenoidCommand command = new SolenoidCommand(solenoid.BoardID, open); _listener.OnCommand(command); }