public async Task TestSetValue(short heater, double value, bool autoDew, string expectedDewHeaterCommand, string expectedAutoDewCommand) { _sut = new DewHeater(heater) { Sdk = _mockSdk.Object }; var dewCommand = string.Empty; var autoDewCommand = string.Empty; _mockSdk.Setup(m => m.SendCommand <SetDewHeaterPowerResponse>(It.IsAny <SetDewHeaterPowerCommand>())) .Callback <ICommand>(arg => { dewCommand = arg.CommandString; }); var response = new StatusResponse { DeviceResponse = "UPB:12.2:0.0:0:23.2:59:14.7:1111:111111:0:0:0:0:0:0:0:0:0:0:0000000:0" }; _mockSdk.Setup(m => m.SendCommand <StatusResponse>(It.IsAny <StatusCommand>())) .Returns(Task.FromResult(response)); _mockSdk.Setup(m => m.SendCommand <SetAutoDewResponse>(It.IsAny <SetAutoDewCommand>())) .Callback <ICommand>(arg => { autoDewCommand = arg.CommandString; }); _sut.TargetValue = value; _sut.AutoDewOnTarget = autoDew; await _sut.SetValue(); Assert.That(dewCommand, Is.EqualTo(expectedDewHeaterCommand)); Assert.That(autoDewCommand, Is.EqualTo(expectedAutoDewCommand)); }
public void TestConstructor() { _sut = new DewHeater(0) { Sdk = _mockSdk.Object }; Assert.That(_sut.Id, Is.EqualTo(0)); Assert.That(_sut.Minimum, Is.EqualTo(0d)); Assert.That(_sut.Maximum, Is.EqualTo(100d)); Assert.That(_sut.StepSize, Is.EqualTo(1d)); }
public async Task TestPollSerialPortClosed() { _sut = new DewHeater(0) { Sdk = _mockSdk.Object }; _mockSdk.Setup(m => m.SendCommand <StatusResponse>(It.IsAny <StatusCommand>())) .Throws(new SerialPortClosedException()); var result = await _sut.Poll(); Assert.That(result, Is.False); }
public async Task TestPoll(short heater, string deviceResponse, double dutyCycle, double amps, bool overCurrent, bool autoDewOn) { _sut = new DewHeater(heater) { Sdk = _mockSdk.Object }; var response = new StatusResponse { DeviceResponse = deviceResponse }; _mockSdk.Setup(m => m.SendCommand <StatusResponse>(It.IsAny <StatusCommand>())) .Returns(Task.FromResult(response)); var result = await _sut.Poll(); Assert.That(result, Is.True); Assert.That(_sut.Value, Is.EqualTo(dutyCycle)); Assert.That(_sut.CurrentAmps, Is.EqualTo(amps)); Assert.That(_sut.ExcessCurrent, Is.EqualTo(overCurrent)); Assert.That(_sut.AutoDewOn, Is.EqualTo(autoDewOn)); }