public void AndExceptionThrown_ThenWrapsException()
        {
            _vehicleRepo
                .Setup(vr => vr.GetVehicle(It.IsAny<int>(), It.IsAny<int>()))
                .Throws(new InvalidOperationException());

            var handler = new DeleteVehicle(_vehicleRepo.Object);

            var ex = Assert.Throws<BusinessServicesException>(() => handler.Execute(UserId, DefaultVehicleId));
            Assert.IsType<InvalidOperationException>(ex.InnerException);
        }
        public void AndVehicleDoesNotExist_ThenThrows()
        {
            // this is the same test as FromOtherUser_ThenThrows

            // the repo throws an exception when it can't find a match with both the user and the vehicle
            _vehicleRepo
                .Setup(vr => vr.GetVehicle(UserId, It.IsAny<int>()))
                .Throws(new InvalidOperationException());

            var handler = new DeleteVehicle(_vehicleRepo.Object);

            Assert.Throws<BusinessServicesException>(() => handler.Execute(UserId, DefaultVehicleId));
        }
        public void FromOtherUser_ThenThrows()
        {
            const int someOtherUserId = 12;

            // the repo throws an exception when it can't find a match with both the user and the vehicle
            _vehicleRepo
                .Setup(vr => vr.GetVehicle(someOtherUserId, DefaultVehicleId))
                .Throws(new InvalidOperationException());

            var handler = new DeleteVehicle(_vehicleRepo.Object);

            Assert.Throws<BusinessServicesException>(() => handler.Execute(someOtherUserId, DefaultVehicleId));
        }
        public void ThenDelegatesToVehicleRepository()
        {
            var vehicle = new Model.Vehicle { VehicleId = DefaultVehicleId, Name = "Name" };

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

            var handler = new DeleteVehicle(_vehicleRepo.Object);
            handler.Execute(UserId, DefaultVehicleId);

            _vehicleRepo.Verify(r => r.Delete(DefaultVehicleId), Times.Once());
        }
 public DeleteVehicleController(DeleteVehicle deleteVehicle)
 {
     this.deleteVehicle = deleteVehicle;
 }