Exemplo n.º 1
0
        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
        }