public void CurrentInformation_Cache() { var stream = new TestStream(); using var device = new CyberCard(stream); // we have data stream.SetupRead(Encoding.ASCII.GetBytes("#I121.0O121.0L042B088F060.1R073S\x80\x84\x90\x80\x80\r")); Assert.Equal(121, device.GetInputVoltage()); Assert.Equal(121, device.GetOutputVoltage()); Assert.Equal(60.1, device.GetFrequency()); Assert.Equal(0.42, device.GetLoadPercentage()); Assert.Equal(0.88, device.GetBatteryPercentage()); Assert.Equal(73, device.GetBatteryRuntime()); Assert.Equal("D\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried only once // subsequent read goes from cache Assert.Equal(121, device.GetInputVoltage()); Assert.Equal(121, device.GetOutputVoltage()); Assert.Equal(60.1, device.GetFrequency()); Assert.Equal(0.42, device.GetLoadPercentage()); Assert.Equal(0.88, device.GetBatteryPercentage()); Assert.Equal(73, device.GetBatteryRuntime()); Assert.Equal("D\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // no new reads // expire cache Thread.Sleep(1000); Assert.Null(device.GetInputVoltage()); Assert.Null(device.GetOutputVoltage()); Assert.Null(device.GetFrequency()); Assert.Null(device.GetLoadPercentage()); Assert.Null(device.GetBatteryPercentage()); Assert.Null(device.GetBatteryRuntime()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // cache failure causes a new read every time // new data stream.SetupRead(Encoding.ASCII.GetBytes("#I121.4O122L41B087F060.4R033S\x80\x84\x90\x80\x80\r")); Assert.Equal(121.4, device.GetInputVoltage()); Assert.Equal(122, device.GetOutputVoltage()); Assert.Equal(60.4, device.GetFrequency()); Assert.Equal(0.41, device.GetLoadPercentage()); Assert.Equal(0.87, device.GetBatteryPercentage()); Assert.Equal(33, device.GetBatteryRuntime()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // only one new read once we have data // subsequent read goes from cache Assert.Equal(121.4, device.GetInputVoltage()); Assert.Equal(122, device.GetOutputVoltage()); Assert.Equal(60.4, device.GetFrequency()); Assert.Equal(0.41, device.GetLoadPercentage()); Assert.Equal(0.87, device.GetBatteryPercentage()); Assert.Equal(33, device.GetBatteryRuntime()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // no new reads }
public void CurrentInformation() { var stream = new TestStream(); using var device = new CyberCard(stream); // survive without data Assert.Null(device.GetInputVoltage()); Assert.Null(device.GetOutputVoltage()); Assert.Null(device.GetFrequency()); Assert.Null(device.GetLoadPercentage()); Assert.Null(device.GetBatteryPercentage()); Assert.Null(device.GetBatteryRuntime()); Assert.Equal("D\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried for each // now we have data stream.SetupRead(Encoding.ASCII.GetBytes("#I121.0O121.0L042B088F060.1R073S\x80\x84\x90\x80\x80\r")); Assert.Equal(121, device.GetInputVoltage()); Assert.Equal(121, device.GetOutputVoltage()); Assert.Equal(60.1, device.GetFrequency()); Assert.Equal(0.42, device.GetLoadPercentage()); Assert.Equal(0.88, device.GetBatteryPercentage()); Assert.Equal(73, device.GetBatteryRuntime()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried only once more // subsequent read goes from cache Assert.Equal(121, device.GetInputVoltage()); Assert.Equal(121, device.GetOutputVoltage()); Assert.Equal(60.1, device.GetFrequency()); Assert.Equal(0.42, device.GetLoadPercentage()); Assert.Equal(0.88, device.GetBatteryPercentage()); Assert.Equal(73, device.GetBatteryRuntime()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // no new reads }
public void CapabilityInformation() { var stream = new TestStream(); using var device = new CyberCard(stream); // survive without data Assert.Null(device.GetDeviceCapacity()); Assert.Null(device.GetDeviceCapacityVA()); Assert.Null(device.GetDeviceVoltage()); Assert.Equal("P2\rP2\rP2\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried for each // now we have data stream.SetupRead(Encoding.ASCII.GetBytes("#0700,0400,120,057,063\r")); Assert.Equal(400, device.GetDeviceCapacity()); Assert.Equal(700, device.GetDeviceCapacityVA()); Assert.Equal(120, device.GetDeviceVoltage()); Assert.Equal("P2\rP2\rP2\rP2\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried only once more // subsequent read goes from cache Assert.Equal(400, device.GetDeviceCapacity()); Assert.Equal(700, device.GetDeviceCapacityVA()); Assert.Equal(120, device.GetDeviceVoltage()); Assert.Equal("P2\rP2\rP2\rP2\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // no new reads }
public void ModelInformation() { var stream = new TestStream(); using var device = new CyberCard(stream); // survive without data Assert.Null(device.GetDeviceModel()); Assert.Null(device.GetDeviceFirmware()); Assert.Null(device.GetDeviceSerial()); Assert.Null(device.GetDeviceManufacturer()); Assert.Equal("P4\rP4\rP4\rP4\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried for each // now we have data stream.SetupRead(Encoding.ASCII.GetBytes("#OR700LCDRM1U,BFE7103_8S1,000000000000,CyberPower\r")); Assert.Equal("OR700LCDRM1U", device.GetDeviceModel()); Assert.Equal("BFE7103_8S1", device.GetDeviceFirmware()); Assert.Equal("", device.GetDeviceSerial()); // ignore all 0's serial Assert.Equal("CyberPower", device.GetDeviceManufacturer()); Assert.Equal("P4\rP4\rP4\rP4\rP4\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried only once more // subsequent read goes from cache Assert.Equal("OR700LCDRM1U", device.GetDeviceModel()); Assert.Equal("BFE7103_8S1", device.GetDeviceFirmware()); Assert.Equal("", device.GetDeviceSerial()); Assert.Equal("CyberPower", device.GetDeviceManufacturer()); Assert.Equal("P4\rP4\rP4\rP4\rP4\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // no new reads }
public void CurrentInformation_Flags() { var stream = new TestStream(); using var device = new CyberCard(stream); // survive without data Assert.Null(device.IsPendingPowerOn()); Assert.Null(device.IsPendingPowerOff()); Assert.Null(device.IsTestInProgress()); Assert.Null(device.IsAlarmActive()); Assert.Null(device.IsUsingBattery()); Assert.Null(device.IsBatteryLow()); Assert.Null(device.IsBatteryCharging()); Assert.Null(device.IsBatteryFull()); Assert.Null(device.IsPoweredOff()); Assert.Null(device.IsPoweredOn()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried for each // now we have data stream.SetupRead(Encoding.Latin1.GetBytes("#I121.0O121.0L042B088F060.1R073S\x80\x84\x90\x80\x80\r")); Assert.False(device.IsPendingPowerOn()); Assert.False(device.IsPendingPowerOff()); Assert.False(device.IsTestInProgress()); Assert.False(device.IsAlarmActive()); Assert.False(device.IsUsingBattery()); Assert.False(device.IsBatteryLow()); Assert.True(device.IsBatteryCharging()); Assert.False(device.IsBatteryFull()); Assert.False(device.IsPoweredOff()); Assert.True(device.IsPoweredOn()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried only once more // subsequent read goes from cache Assert.False(device.IsPendingPowerOn()); Assert.False(device.IsPendingPowerOff()); Assert.False(device.IsTestInProgress()); Assert.False(device.IsAlarmActive()); Assert.False(device.IsUsingBattery()); Assert.False(device.IsBatteryLow()); Assert.True(device.IsBatteryCharging()); Assert.False(device.IsBatteryFull()); Assert.False(device.IsPoweredOff()); Assert.True(device.IsPoweredOn()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // no new reads // wait for cache to expire Thread.Sleep(1000); stream.SetupRead(Encoding.Latin1.GetBytes("#I000.0O120.0L000B100F060.1R084S\xc0\x81\x88\x80\x80\r")); Assert.False(device.IsPendingPowerOn()); Assert.False(device.IsPendingPowerOff()); Assert.False(device.IsTestInProgress()); Assert.False(device.IsAlarmActive()); Assert.True(device.IsUsingBattery()); Assert.False(device.IsBatteryLow()); Assert.False(device.IsBatteryCharging()); Assert.False(device.IsBatteryFull()); Assert.False(device.IsPoweredOff()); Assert.True(device.IsPoweredOn()); Assert.Equal("D\rD\rD\rD\rD\rD\rD\rD\rD\rD\rD\rD\r", Encoding.ASCII.GetString(stream.ToWrittenArray())); // check we tried only once more }