Ejemplo n.º 1
0
        public void WhenCanAddFillupWithInvalidVehicleId_ThenReturnsValidationResult()
        {
            var fillUp = new FillupEntryFormModel
            {
                Date         = DateTime.UtcNow,
                TotalUnits   = 10,
                PricePerUnit = 1.0,
            };

            var fillUps = new List <FillupEntry>();

            _vehicleRepo
            .Setup(r => r.GetVehicle(DefaultUserId, DefaultVehicleId))
            .Returns((Vehicle)null);

            _fillupRepo
            .Setup(x => x.GetFillups(DefaultVehicleId))
            .Returns(fillUps);

            var handler = new CanAddFillup(_vehicleRepo.Object, _fillupRepo.Object);
            var actual  = handler.Execute(DefaultUserId, DefaultVehicleId, fillUp);

            var actualList = new List <ValidationResult>(actual);

            Assert.Equal(1, actualList.Count);
            Assert.Contains("not found", actualList[0].Message, StringComparison.CurrentCultureIgnoreCase);
        }
Ejemplo n.º 2
0
        public void WhenCanAddFillupWithInvalidFillupOdometer_ThenReturnsValidationResult()
        {
            var fillUp = new FillupEntryFormModel
            {
                Date         = DateTime.UtcNow,
                TotalUnits   = 10,
                PricePerUnit = 1.0,
                Odometer     = 1500              //less than prior fillup
            };

            var fillUps = new List <FillupEntry>
            {
                new FillupEntry
                {
                    FillupEntryId = 1,
                    Date          = DateTime.UtcNow.AddDays(-10),
                    Odometer      = 1000
                },
                new FillupEntry
                {
                    FillupEntryId = 2,
                    Date          = DateTime.UtcNow.AddDays(-1),
                    Odometer      = 2000
                }
            };

            _vehicleRepo
            .Setup(vr => vr.GetVehicle(DefaultUserId, DefaultVehicleId))
            .Returns(new Vehicle {
                VehicleId = DefaultVehicleId, Name = "Vehicle"
            });

            _fillupRepo
            .Setup(x => x.GetFillups(DefaultVehicleId))
            .Returns(fillUps);

            var handler = new CanAddFillup(_vehicleRepo.Object, _fillupRepo.Object);
            var actual  = handler.Execute(DefaultUserId, DefaultVehicleId, fillUp);

            var actualList = new List <ValidationResult>(actual);

            Assert.Equal(1, actualList.Count);
            Assert.Contains("odometer ", actualList[0].Message, StringComparison.CurrentCultureIgnoreCase);
        }
Ejemplo n.º 3
0
        public void WhenCanAddFillup_ThenReturnsEmptyCollection()
        {
            var fillUp = new FillupEntryFormModel
            {
                Date         = DateTime.UtcNow,
                TotalUnits   = 10,
                PricePerUnit = 1.0,
            };

            _vehicleRepo
            .Setup(vr => vr.GetVehicle(DefaultUserId, DefaultVehicleId))
            .Returns(new Vehicle {
                VehicleId = DefaultVehicleId, Name = "Vehicle"
            });

            _fillupRepo
            .Setup(x => x.GetFillups(It.IsAny <int>()))
            .Returns(new List <FillupEntry>());

            var handler = new CanAddFillup(_vehicleRepo.Object, _fillupRepo.Object);
            var actual  = handler.Execute(DefaultUserId, DefaultVehicleId, fillUp);

            Assert.Empty(actual);
        }