public void GetCarByID_ShouldReturnCorrectCar()//Read
        {
            //Arrange
            GasCar    car  = new GasCar("ford", "mustang", 2020);
            HybridCar car2 = new HybridCar("toyota", "prius", 2019);
            Car_Repo  repo = new Car_Repo();

            repo.AddCar(car);
            repo.AddCar(car2);

            string id = "2020fordmustang";

            //Act
            var localCar = repo.GetCarByID(id);

            //assert
            Assert.AreEqual(localCar.CarID, id);
        }
Ejemplo n.º 2
0
        public void AddCar()
        {
            Car        newItem     = new Car();
            List <Car> _list       = _carRepo.GetCars();
            ushort     carNum      = 0;
            bool       numberFound = false;
            bool       numberCheck = true;

            do
            {
                Console.Write("Enter an ID Number > ");
                //carNum = Convert.ToUInt16(Console.ReadLine());
                string verifyInput = Console.ReadLine();
                if (ushort.TryParse(verifyInput, out carNum))
                {
                    foreach (var item in _list)
                    {
                        if (item.Id == carNum)
                        {
                            numberFound = true;
                        }
                    }//foreach
                    if (numberFound)
                    {
                        int maxID = _list.Max(x => x.Id);
                        Console.WriteLine($"pick another number. FYI: The highest number in the inventory is {maxID}");
                        numberFound = false;
                    }
                    else
                    {
                        numberFound = false; numberCheck = false;
                    }
                }
                else
                {
                    Console.WriteLine("Error: Invalid input. Try again."); numberCheck = true;
                }
            } while (numberCheck);

            AddCarDetails(newItem, carNum);
            _carRepo.AddCar(newItem);
            Console.WriteLine();
        }
        public void AddCar_ShouldGetCorrectBool() //Create
        {
            //Arrange
            HybridCar hybridCar = new HybridCar();
            Car_Repo  repo      = new Car_Repo();

            //Act
            bool addResult = repo.AddCar(hybridCar);


            //Assert
            Assert.IsTrue(addResult);
        }
Ejemplo n.º 4
0
        public void CreatingItems()
        {
            SeedThis();
            foreach (var item in _carList)
            {
                _carRepo.AddCar(item);
            }

            int itemCheck = _carRepo.GetCars().Count;

            Assert.AreEqual(2, itemCheck);
            Car item3 = new Car(3, "TestAdd", "TestModelADD", "electric", .1, .1, .1);

            _carRepo.AddCar(item3);
            //bool isAdded = _carRepo.AddCar(item3);
            Assert.AreEqual(2, itemCheck);
            Console.WriteLine(itemCheck);

            itemCheck = _carRepo.GetCars().Count;
            //  Assert.IsTrue(isAdded);
            Assert.AreEqual(3, itemCheck);
        }
        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 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);
        }
        public void DeleteCar()//Delete a car from repo
        {
            //Arrange
            GasCar   car  = new GasCar("ford", "mustang", 2020);
            Car_Repo repo = new Car_Repo();

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


            //Act
            Car  oldCar       = repo.GetCarByID(id);
            bool removeResult = repo.DeleteCar(oldCar);

            //Assert
            Assert.IsTrue(removeResult);
        }
Ejemplo n.º 8
0
        public void SeedCars()
        {
            GasCar      car  = new GasCar("Ford", "Mustang", 2020, VehicleType.SportsCar, 100, 19);
            GasCar      car2 = new GasCar("Toyota", "Camry", 2019, VehicleType.Sedan, 624, 32);
            HybridCar   car3 = new HybridCar("Toyota", "Prius", 2020, VehicleType.Sedan, 655, 52, 8.8);
            HybridCar   car4 = new HybridCar("Honda", "Accord Hybrd", 2020, VehicleType.Sedan, 614.4, 48, 1.3);
            ElectricCar car5 = new ElectricCar("Tesla", "ModelS", 2020, VehicleType.Sedan, 322, 75, 10);
            ElectricCar car6 = new ElectricCar("Hyundai", "Kona", 2020, VehicleType.HatchBack, 258, 64, 9);

            _repo.AddCar(car);
            _repo.AddCar(car2);
            _repo.AddCar(car3);
            _repo.AddCar(car4);
            _repo.AddCar(car5);
            _repo.AddCar(car6);
        }