Exemplo n.º 1
0
        public void From_FullChargedCapacityIsNull_ReturnsBattery()
        {
            //Arrange
            var batteryFullChargedCapacity = new BatteryFullChargedCapacity
            {
                FullChargedCapacity = null
            };
            var batteryStaticData = new BatteryStaticData
            {
                DesignedCapacity = 1100
            };
            var win32Battery = new Win32_Battery
            {
                BatteryStatus            = 1,
                EstimatedChargeRemaining = 90
            };

            //Act
            var result = BatteryMapper.From(batteryFullChargedCapacity, win32Battery, batteryStaticData);

            //Assert
            Assert.NotNull(result);
            Assert.True(result.ID == 0);
            Assert.True(result.Deleted == false);
            Assert.True(result.DesignedCapacity == batteryStaticData.DesignedCapacity);
            Assert.True(result.ChargeLevel == win32Battery.EstimatedChargeRemaining);
            Assert.True(result.Status == win32Battery.BatteryStatus);
            Assert.True(double.IsNaN(result.WearLevel));
        }
Exemplo n.º 2
0
        public async Task <Result <IEnumerable <Battery> > > GetPhysicalBatteriesAsync()
        {
            var output = new List <Battery>();

            var staticDataResult = await GetPhysicalData(() => _componentRepository.Get <BatteryStaticData>());

            if (!staticDataResult.IsSuccess)
            {
                return(Result <IEnumerable <Battery> > .Fail(staticDataResult.Exception));
            }

            var win32batteryResult = await GetPhysicalData(() => _componentRepository.Get <Win32_Battery>());

            if (!win32batteryResult.IsSuccess)
            {
                return(Result <IEnumerable <Battery> > .Fail(win32batteryResult.Exception));
            }

            var fullChargedCapacityResult = await GetPhysicalData(() => _componentRepository.Get <BatteryFullChargedCapacity>());

            if (!fullChargedCapacityResult.IsSuccess)
            {
                return(Result <IEnumerable <Battery> > .Fail(fullChargedCapacityResult.Exception));
            }

            if (!win32batteryResult.Output.Any() || !staticDataResult.Output.Any() || !fullChargedCapacityResult.Output.Any())
            {
                return(Result <IEnumerable <Battery> > .Ok(output));
            }

            try
            {
                foreach (var staticData in staticDataResult.Output)
                {
                    var fulChargedCapacity = fullChargedCapacityResult.Output.First(x => x.Tag == staticData.Tag);
                    var win32battery       = win32batteryResult.Output.First(x => x.DeviceID == staticData.UniqueID);
                    output.Add(BatteryMapper.From(fulChargedCapacity, win32battery, staticData));
                }

                return(Result <IEnumerable <Battery> > .Ok(output));
            }
            catch (Exception e)
            {
                return(Result <IEnumerable <Battery> > .Fail(e));
            }
        }
Exemplo n.º 3
0
        public void From_ParameterWin32BatteryIsNull_ThrowsNullReferenceEception()
        {
            //Arrange
            var batteryFullChargedCapacity = new BatteryFullChargedCapacity
            {
                FullChargedCapacity = 1000
            };
            var batteryStaticData = new BatteryStaticData
            {
                DesignedCapacity = 1100
            };
            Win32_Battery win32Battery = null;

            //Act
            //Assert
            Assert.Throws <NullReferenceException>(() => BatteryMapper.From(batteryFullChargedCapacity, win32Battery, batteryStaticData));
        }
Exemplo n.º 4
0
        public void From_ParameterBatteryStaticDataIsNull_ThrowsNullReferenceEception()
        {
            //Arrange
            var batteryFullChargedCapacity = new BatteryFullChargedCapacity
            {
                FullChargedCapacity = 1000
            };
            BatteryStaticData batteryStaticData = null;
            var win32Battery = new Win32_Battery
            {
                BatteryStatus            = 1,
                EstimatedChargeRemaining = null
            };

            //Act
            //Assert
            Assert.Throws <NullReferenceException>(() => BatteryMapper.From(batteryFullChargedCapacity, win32Battery, batteryStaticData));
        }