Ejemplo n.º 1
0
        public void EnterChargeDataWithNullBattery_ThrowsBatteryNotFoundException()
        {
            var battery = new Battery {
                Id = 0, AccountId = 1
            };
            var charge = new BatteryCharge {
                Battery = battery, ChargedOn = DateTime.Now, Type = ChargeType.Standard, Mah = 1000
            };

            _batteryRepositoryMock.Setup(x => x.GetById(It.IsAny <int>())).Returns(() => null);
            var service = new BatteryService(
                _batteryRepositoryMock.Object,
                _batteryTypeRepositoryMock.Object,
                _batteryChargeRepositoryMock.Object,
                _loggerMock.Object
                );

            Assert.ThrowsAsync <BatteryNotFoundException>(() => service.EnterChargeDataAsync(1, battery, charge.ChargedOn, charge.Type, charge.Mah));
        }
Ejemplo n.º 2
0
        public void EnterChargeDataWithExistingBattery_ReturnsBattery()
        {
            var battery = new Battery {
                Id = 1, IsActive = true, Notes = "Test battery", PurchaseDate = DateTime.Now.AddMonths(-1), AccountId = 1
            };
            var charge = new BatteryCharge {
                Battery = battery, ChargedOn = DateTime.Now, Type = ChargeType.Standard, Mah = 1000
            };

            _batteryRepositoryMock.Setup(x => x.GetById(It.IsAny <int>())).Returns(() => battery);
            _batteryChargeRepositoryMock.Setup(x => x.Add(It.IsAny <BatteryCharge>())).Returns(charge);
            var service = new BatteryService(
                _batteryRepositoryMock.Object,
                _batteryTypeRepositoryMock.Object,
                _batteryChargeRepositoryMock.Object,
                _loggerMock.Object
                );

            var result = service.EnterChargeDataAsync(1, battery, charge.ChargedOn, charge.Type, charge.Mah);

            Assert.NotNull(result);
        }