public void UpdateExistingCar_ShouldReturnTrue() //Update a car
        {
            //Arrange
            GasCar   car  = new GasCar("ford", "mustang", 2020);
            GasCar   car2 = new GasCar("toyota", "camry", 2019, VehicleType.Sedan, 624, 32);
            Car_Repo repo = new Car_Repo();

            repo.AddCar(car);
            string id = "2020fordmustang";

            //Act
            bool UpdateResult = repo.UpdateExistingCar(id, car2);

            //Assert
            Assert.IsTrue(UpdateResult);
        }
示例#2
0
        public void UpdateCar()
        {
            Console.Clear();
            KomodoLogo();
            Console.WriteLine("<<<<<<<< Update Car >>>>>>>");
            Console.WriteLine("Enter Make:");
            string make = Console.ReadLine();

            Console.WriteLine("Enter Model:");
            string model = Console.ReadLine();

            Console.WriteLine("Enter Year:");
            string year     = Console.ReadLine();
            string oldCarID = year.ToString() + make.ToLower() + model.ToLower();
            Car    oldCar   = _repo.GetCarByID(oldCarID);

            if (oldCar != null)
            {
                Console.Clear();
                KomodoLogo();
                Console.WriteLine("<<<<<<<< Update Car >>>>>>>");
                DisplayCar(oldCar);
                Console.WriteLine();
                Console.WriteLine("---------------------------");
                bool looper = true;
                Car  car    = new Car();
                while (looper)
                {
                    Console.WriteLine("<<<<<<<< Updating >>>>>>>");
                    //Set car type
                    if (oldCar is GasCar)
                    {
                        car = new GasCar();
                    }
                    if (oldCar is HybridCar)
                    {
                        car = new HybridCar();
                    }
                    if (oldCar is ElectricCar)
                    {
                        car = new ElectricCar();
                    }
                    Console.WriteLine("Enter Make:");
                    car.Make = Console.ReadLine();
                    Console.WriteLine("Enter Model:");
                    car.Model = Console.ReadLine();
                    Console.WriteLine("Enter Model Year:");
                    car.Year = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Please Select Vehicle Type:");
                    //Sedan = 1, SUV, PickupTruck, Coupe, SportsCar, Wagon, HatchBack, Convertible, Minivan
                    Console.WriteLine("1> Sedan");
                    Console.WriteLine("2> SUV");
                    Console.WriteLine("3> Pickup Truck");
                    Console.WriteLine("4> Coupe");
                    Console.WriteLine("5> Sports Car");
                    Console.WriteLine("6> Wagon");
                    Console.WriteLine("7> Hatch Back");
                    Console.WriteLine("8> Convertible");
                    Console.WriteLine("9> Minivan");
                    bool   vehicleTypeLoop = true;
                    string vehicleType     = "";
                    while (vehicleTypeLoop)
                    {
                        vehicleType = Console.ReadLine();
                        if (vehicleType == "1" || vehicleType == "2" || vehicleType == "3" || vehicleType == "4" || vehicleType == "5" || vehicleType == "6" || vehicleType == "7" || vehicleType == "8" || vehicleType == "9")
                        {
                            vehicleTypeLoop = false;
                        }
                        else
                        {
                            Console.WriteLine("Please enter a valid selection. (1,2,3,4,5,6,7,8 or 9");
                        }
                    }
                    car.Type = (VehicleType)int.Parse(vehicleType);
                    Console.WriteLine("Enter avg fuel range:");
                    car.AvgRange = Convert.ToDouble(Console.ReadLine());
                    if (car is GasCar)
                    {
                        Console.WriteLine("Enter combined average MPG:");
                        ((GasCar)car).AvgMPG = Convert.ToDouble(Console.ReadLine());
                    }
                    else if (car is ElectricCar)
                    {
                        Console.WriteLine("Enter battery capacity (kWh):");
                        ((ElectricCar)car).BatteryCapacity = Convert.ToDouble(Console.ReadLine());
                        Console.WriteLine("Enter charge time (220v):");
                        ((ElectricCar)car).ChargeTime = Convert.ToDouble(Console.ReadLine());
                    }
                    else if (car is HybridCar)
                    {
                        Console.WriteLine("Enter combined average MPG:");
                        ((HybridCar)car).AvgMPG = Convert.ToDouble(Console.ReadLine());
                        Console.WriteLine("Enter battery capacity (kWh):");
                        ((HybridCar)car).BatteryCapacity = Convert.ToDouble(Console.ReadLine());
                    }
                    Console.Clear();
                    KomodoLogo();
                    Console.WriteLine("<<<<<<< Updating Car >>>>>>>");
                    Console.WriteLine("     <<    Old Car   >>");
                    DisplayCar(oldCar);
                    Console.WriteLine();
                    Console.WriteLine("     <<    New Car   >>");
                    DisplayCar(car);
                    Console.WriteLine("Does all of this look correct? \nEnter Y to add this car. \nEnter N to start over entering this car.");
                    string correct = Console.ReadLine();
                    if (correct.ToLower() == "y")
                    {
                        looper = false;
                    }
                }
                bool wasUpdated = _repo.UpdateExistingCar(oldCarID, car);
                if (wasUpdated == true)
                {
                    Console.WriteLine("Your car was update in the database.");
                    Console.WriteLine("Press any key to Continue.");
                }
                else
                {
                    Console.WriteLine("Oops. Something went wrong. Your car was not Updated.  Please Try Again");
                    Console.WriteLine("Press any key to continue.");
                }
            }
            else
            {
                Console.WriteLine("Car not found. \nPress any key to return to main menu.");
            }
            Console.ReadKey();
        }