public void ForOtherUser_ThenNullReturned()
        {
            const int notTheCurrentUserId = UserId + 1;

            var vehicle = new Vehicle { VehicleId = DefaultVehicleId, Name = "vehicle" };

            _vehicleRepo
                .Setup(vr => vr.GetVehicle(notTheCurrentUserId, DefaultVehicleId))
                .Throws(new InvalidOperationException());

            var handler = new GetVehicleById(_vehicleRepo.Object);
            var retrievedVehicle = handler.Execute(notTheCurrentUserId, vehicle.VehicleId);

            Assert.Null(retrievedVehicle);
        }
        public void ThenVehicleReturned()
        {
            var vehicle = new Vehicle { VehicleId = 1, Name = "vehicle" };

            _vehicleRepo
                .Setup(vr => vr.GetVehicle(UserId, vehicle.VehicleId))
                .Returns(vehicle);

            var handler = new GetVehicleById(_vehicleRepo.Object);

            var retrievedVehicle = handler.Execute(UserId, vehicle.VehicleId);

            Assert.NotNull(retrievedVehicle);
            Assert.Equal("vehicle", retrievedVehicle.Name);
        }
        public void ThenVehiclePhotoIdSet()
        {
            const int photoId = 99;

            var vehicle = new Vehicle { VehicleId = DefaultVehicleId, Name = "vehicle", PhotoId = photoId };

            _vehicleRepo
                .Setup(vr => vr.GetVehicle(UserId, DefaultVehicleId))
                .Returns(vehicle);

            var handler = new GetVehicleById(_vehicleRepo.Object);

            var retrievedVehicle = handler.Execute(UserId, vehicle.VehicleId);

            Assert.Equal(photoId, retrievedVehicle.PhotoId);
        }
 public GetReminderController(GetReminder getReminder, GetVehicleById getVehicleById)
 {
     this.getReminder = getReminder;
     this.getVehicleById = getVehicleById;
 }
        public void WhenGettingVehicle_ThenVehicleStatisticsReturned()
        {
            var fillups = new List<FillupEntry>
                              {
                                  new FillupEntry
                                      {
                                          Date = DateTime.UtcNow.AddDays(-10),
                                          Odometer = 500,
                                          PricePerUnit = 10.0,
                                          TotalUnits = 10.0
                                      },
                                  new FillupEntry
                                      {
                                          Date = DateTime.UtcNow.AddDays(-5),
                                          Odometer = 1000,
                                          PricePerUnit = 10.0,
                                          TotalUnits = 10.0
                                      }
                              };

            var vehicle = new Vehicle
                              {
                                  VehicleId = DefaultVehicleId,
                                  Fillups = fillups
                              };

            _vehicleRepo
                .Setup(vr => vr.GetVehicle(UserId, DefaultVehicleId))
                .Returns(vehicle);

            var handler = new GetVehicleById(_vehicleRepo.Object);
            var retrievedVehicle = handler.Execute(UserId, vehicle.VehicleId);

            Assert.NotNull(retrievedVehicle);
            Assert.Equal(1000, retrievedVehicle.Odometer);
        }
 public GetVehicleController(GetVehicleById getVehicleById)
 {
     this.getVehicleById = getVehicleById;
 }
 public GetRemindersController(GetAllRemindersForVehicle getAllRemindersForVehicle, GetVehicleById getVehicleById)
 {
     this.getAllRemindersForVehicle = getAllRemindersForVehicle;
     this.getVehicleById = getVehicleById;
 }
 public GetVehiclePhotoController(GetVehicleById getVehicleById, GetVehiclePhoto getVehiclePhoto)
 {
     this.getVehicleById = getVehicleById;
     this.getVehiclePhoto = getVehiclePhoto;
 }
        public void ForOtherUser_ThenNullReturned()
        {
            const int notTheCurrentUserId = UserId + 1;

            var vehicle = new Vehicle { VehicleId = DefaultVehicleId, Name = "vehicle" };

            _vehicleRepo
                .Setup(vr => vr.GetVehicle(notTheCurrentUserId, DefaultVehicleId))
                .Returns((Vehicle)null);

            var handler = new GetVehicleById(_vehicleRepo.Object, _fillupRepo.Object);
            var retrievedVehicle = handler.Execute(notTheCurrentUserId, vehicle.VehicleId);

            Assert.Null(retrievedVehicle);
        }
        public void WhenGettingVehicleWithOneFillup_ThenVehicleOdometerReflectsFillup()
        {
            var fillups = new List<FillupEntry>
                              {
                                  new FillupEntry
                                      {
                                          Date = DateTime.UtcNow.AddDays(-10),
                                          Odometer = 500,
                                          PricePerUnit = 10.0,
                                          TotalUnits = 10.0
                                      },
                              };

            var vehicle = new Vehicle { VehicleId = DefaultVehicleId };

            _vehicleRepo
                .Setup(vr => vr.GetVehicle(UserId, DefaultVehicleId))
                .Returns(vehicle);

            _fillupRepo
                .Setup(r => r.GetFillups(DefaultVehicleId))
                .Returns(fillups);

            var handler = new GetVehicleById(_vehicleRepo.Object, _fillupRepo.Object);
            var retrievedVehicle = handler.Execute(UserId, vehicle.VehicleId);

            Assert.Equal(500, retrievedVehicle.Odometer);
        }