public void GetAllCars_ShouldReturnCorrectCollection() //Read { //Arrange GasCar car = new GasCar("ford", "mustang", 2020); Car_Repo repo = new Car_Repo(); repo.AddCar(car); //Act List <Car> localCars = repo.GetAllCars(); bool hasCar = localCars.Contains(car); //Assert Assert.IsTrue(hasCar); }
public void ViewMenu() { bool keepRunning = true; while (keepRunning) { Console.Clear(); KomodoLogo(); Console.WriteLine("<<<<<<<< View Menu >>>>>>>"); Console.WriteLine("1> View All Cars"); Console.WriteLine("2> View Gas Cars"); Console.WriteLine("3> View Hybrid Cars"); Console.WriteLine("4> View Electric Cars"); Console.WriteLine("5> Return to main menu"); string menuSelection = Console.ReadLine(); List <Car> cars = _repo.GetAllCars(); switch (menuSelection) { case "1": Console.Clear(); KomodoLogo(); Console.WriteLine("<<<<<<<< View All Cars>>>>>>>"); Console.WriteLine(""); Console.WriteLine("{0,-10} {1,15} {2,-6} {3,-12} {4,10} {5,10}", "Make", "Model", "Year", "Type", "Class", "Avg Range"); foreach (Car car in cars) { string carClassType = ""; if (car is HybridCar) { carClassType = "Hybrid Car"; } else if (car is GasCar) { carClassType = "Gas Car"; } else if (car is ElectricCar) { carClassType = "Electric Car"; } Console.WriteLine("{0,-10} {1,15} {2,-6} {3,-12:N2} {4,10} {5,8}mi", car.Make, car.Model, car.Year, carClassType, car.Type.ToString(), car.AvgRange); } Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); break; case "2": Console.Clear(); KomodoLogo(); Console.WriteLine("<<<<<<<< View All Gas Cars >>>>>>>"); Console.WriteLine(""); Console.WriteLine("{0,-10} {1,15} {2,-6} {3,-12} {4,10} {5,10} {6,8}", "Make", "Model", "Year", "Type", "Class", "Avg Range", "Avg MPG"); foreach (Car car in cars) { string carClassType = ""; if (car is GasCar) { carClassType = "Gas Car"; Console.WriteLine("{0,-10} {1,15} {2,-6} {3,-12:N2} {4,10} {5,8}mi {6,8}", car.Make, car.Model, car.Year, carClassType, car.Type.ToString(), car.AvgRange, ((GasCar)car).AvgMPG); } } Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); break; case "3": Console.Clear(); KomodoLogo(); Console.WriteLine("<<<<<<<< View All Hybrid Cars >>>>>>>"); Console.WriteLine(""); Console.WriteLine("{0,-10} {1,15} {2,-6} {3,-12} {4,10} {5,10} {6,8} {7,18}", "Make", "Model", "Year", "Type", "Class", "Avg Range", "Avg MPG", "Battery Capacity"); foreach (Car car in cars) { string carClassType = ""; if (car is HybridCar) { carClassType = "Hybrid"; Console.WriteLine("{0,-10} {1,15} {2,-6} {3,-12:N2} {4,10} {5,8}mi {6,8} {7,15}kWh", car.Make, car.Model, car.Year, carClassType, car.Type.ToString(), car.AvgRange, ((HybridCar)car).AvgMPG, ((HybridCar)car).BatteryCapacity); } } Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); break; case "4": Console.Clear(); KomodoLogo(); Console.WriteLine("<<<<<<<< View All Electric Cars >>>>>>>"); Console.WriteLine(""); Console.WriteLine("{0,-10} {1,15} {2,-6} {3,-12} {4,10} {5,10} {6,13} {7,18}", "Make", "Model", "Year", "Type", "Class", "Avg Range", "Charge Time", "Battery Capacity"); foreach (Car car in cars) { string carClassType = ""; if (car is ElectricCar) { carClassType = "Electric"; Console.WriteLine("{0,-10} {1,15} {2,-6} {3,-12:N2} {4,10} {5,8}mi {6,11}hr {7,15}kWh", car.Make, car.Model, car.Year, carClassType, car.Type.ToString(), car.AvgRange, ((ElectricCar)car).ChargeTime, ((ElectricCar)car).BatteryCapacity); } } Console.WriteLine(); Console.WriteLine("Press any key to continue."); Console.ReadKey(); break; case "5": keepRunning = false; break; default: break; } } }