public List <Vehicle> GetVehiclesBySearchParameters(string searchTerm, decimal priceMin, decimal priceMax, int yearMin, int yearMax, int mileage)
        {
            var makes  = MakeRepositoryFactory.GetMakeRepository().GetMakes();
            var models = ModelRepositoryFactory.GetModelRepository().GetModels();

            // used vehicle search, no search terms entered
            if (searchTerm == "" && priceMin == 0.00m && priceMax == 100000.00m && yearMin == 2000 && yearMax == 2021 && mileage == -1)
            {
                return(_vehicles.Where(v => v.Mileage > 1000).OrderBy(v => v.MSRP).Take(20).ToList()); // 4 VEHICLES
            }
            // new vehicle search, no search terms entered
            else if (searchTerm == "" && priceMin == 0.00m && priceMax == 100000.00m && yearMin == 2000 && yearMax == 2021 && mileage == -2)
            {
                return(_vehicles.Where(v => v.Mileage < 1000).OrderBy(v => v.MSRP).Take(20).ToList()); // 3 VEHICLES
            }
            // admin or sales vehicle search, no search terms entered
            else if (searchTerm == "" && priceMin == 0.00m && priceMax == 100000.00m && yearMin == 2000 && yearMax == 2021 && mileage == -3)
            {
                return(_vehicles.OrderBy(v => v.MSRP).Take(20).ToList()); // 7 VEHICLES
            }
            else if (mileage == -1)                                       // used vehicle, searchTerm, price min/max or year min/max was entered
            {
                List <Vehicle> vehicles         = _vehicles.Where(v => v.Mileage > 1000).ToList();
                var            vehiclesToReturn = new List <Vehicle>();
                if (searchTerm != "")
                {
                    foreach (var vehicle in vehicles)
                    {
                        var model = new VehicleWithNames();

                        model.Vehicle = vehicle;
                        model.Model   = models.FirstOrDefault(m => m.ModelID == vehicle.ModelID);
                        model.Make    = makes.FirstOrDefault(m => m.MakeID == vehicle.MakeID);

                        if (model.Make.MakeName.Contains(searchTerm) || model.Model.ModelName.Contains(searchTerm) || model.Vehicle.Year.ToString().Contains(searchTerm))
                        {
                            vehiclesToReturn.Add(model.Vehicle);
                        }
                    }
                }

                if (vehiclesToReturn.Count() > 0)
                {
                    vehiclesToReturn.RemoveAll(v => v.SalePrice < priceMin);
                    vehiclesToReturn.RemoveAll(v => v.SalePrice > priceMax);
                    vehiclesToReturn.RemoveAll(v => v.Year < yearMin);
                    vehiclesToReturn.RemoveAll(v => v.Year > yearMax);

                    return(vehiclesToReturn);
                }
                else
                {
                    vehicles.RemoveAll(v => v.SalePrice < priceMin);
                    vehicles.RemoveAll(v => v.SalePrice > priceMax);
                    vehicles.RemoveAll(v => v.Year < yearMin);
                    vehicles.RemoveAll(v => v.Year > yearMax);
                }

                return(vehicles);
            }
            else if (mileage == -2) // new vehicle, searchterm, price min/max or year min/max selected
            {
                List <Vehicle> vehicles         = _vehicles.Where(v => v.Mileage < 1000).ToList();
                var            vehiclesToReturn = new List <Vehicle>();
                if (searchTerm != "")
                {
                    foreach (var vehicle in vehicles)
                    {
                        var model = new VehicleWithNames();

                        model.Vehicle = vehicle;
                        model.Model   = models.FirstOrDefault(m => m.ModelID == vehicle.ModelID);
                        model.Make    = makes.FirstOrDefault(m => m.MakeID == vehicle.MakeID);

                        if (model.Make.MakeName.Contains(searchTerm) || model.Model.ModelName.Contains(searchTerm) || model.Vehicle.Year.ToString().Contains(searchTerm))
                        {
                            vehiclesToReturn.Add(model.Vehicle);
                        }
                    }
                }

                if (vehiclesToReturn.Count() > 0)
                {
                    vehiclesToReturn.RemoveAll(v => v.SalePrice < priceMin);
                    vehiclesToReturn.RemoveAll(v => v.SalePrice > priceMax);
                    vehiclesToReturn.RemoveAll(v => v.Year < yearMin);
                    vehiclesToReturn.RemoveAll(v => v.Year > yearMax);

                    return(vehiclesToReturn);
                }
                else
                {
                    vehicles.RemoveAll(v => v.SalePrice < priceMin);
                    vehicles.RemoveAll(v => v.SalePrice > priceMax);
                    vehicles.RemoveAll(v => v.Year < yearMin);
                    vehicles.RemoveAll(v => v.Year > yearMax);
                }

                return(vehicles);
            }
            else
            {
                List <Vehicle> vehicles         = _vehicles;
                var            vehiclesToReturn = new List <Vehicle>();
                if (searchTerm != "")
                {
                    foreach (var vehicle in vehicles)
                    {
                        var model = new VehicleWithNames();

                        model.Vehicle = vehicle;
                        model.Model   = models.FirstOrDefault(m => m.ModelID == vehicle.ModelID);
                        model.Make    = makes.FirstOrDefault(m => m.MakeID == vehicle.MakeID);

                        if (model.Make.MakeName.Contains(searchTerm) || model.Model.ModelName.Contains(searchTerm) || model.Vehicle.Year.ToString().Contains(searchTerm))
                        {
                            vehiclesToReturn.Add(model.Vehicle);
                        }
                    }
                }

                if (vehiclesToReturn.Count() > 0)
                {
                    vehiclesToReturn.RemoveAll(v => v.SalePrice < priceMin);
                    vehiclesToReturn.RemoveAll(v => v.SalePrice > priceMax);
                    vehiclesToReturn.RemoveAll(v => v.Year < yearMin);
                    vehiclesToReturn.RemoveAll(v => v.Year > yearMax);

                    return(vehiclesToReturn);
                }
                else
                {
                    vehicles.RemoveAll(v => v.SalePrice < priceMin);
                    vehicles.RemoveAll(v => v.SalePrice > priceMax);
                    vehicles.RemoveAll(v => v.Year < yearMin);
                    vehicles.RemoveAll(v => v.Year > yearMax);
                }

                return(vehicles);
            }
        }
示例#2
0
        [TestCase("Ni", 0.00, 1000000.00, 2000, 2021, -1)] // used inventory test - searchTerm provided
        //[TestCase("Ni", 0.00, 9000.00, 2015, 2017, -1)] // used inventory test - searchTerm provided, priceMax set

        //[TestCase("", 0.00, 100000.00, 2000, 2021, -2)] // new inventory test - no search terms entered
        //[TestCase("", 0.00, 100000.00, 2020, 2021, -2)] // new inventory test - year min/max entered
        //[TestCase("", 9000.00, 9200.00, 2000, 2021, -1)] // new inventory test - price min/max entered
        //[TestCase("Ni", 0.00, 1000000.00, 2000, 2021, -1)] // new inventory test - searchTerm provided
        //[TestCase("Ni", 0.00, 9000.00, 2015, 2017, -1)] // new inventory test - searchTerm provided, priceMax set
        public void CanGetVehicleBySearchParameters(string searchTerm, decimal priceMin, decimal priceMax, int yearMin, int yearMax, int mileage)
        {
            var vehicles = VehicleRepositoryFactory.GetVehicleRepository().GetVehicles();
            var makes    = MakeRepositoryFactory.GetMakeRepository().GetMakes();
            var models   = ModelRepositoryFactory.GetModelRepository().GetModels();

            // used vehicle search, no search terms entered
            if (searchTerm == "" && priceMin == 0.00m && priceMax == 100000.00m && yearMin == 2000 && yearMax == 2021 && mileage == -1)
            {
                vehicles = vehicles.Where(v => v.Mileage > 1000).OrderBy(v => v.MSRP).Take(20).ToList();
                Assert.AreEqual(4, vehicles.Count());
            }
            // new vehicle search, no search terms entered
            else if (searchTerm == "" && priceMin == 0.00m && priceMax == 100000.00m && yearMin == 2000 && yearMax == 2021 && mileage == -2)
            {
                vehicles = vehicles.Where(v => v.Mileage < 1000).OrderBy(v => v.MSRP).Take(20).ToList();
                Assert.AreEqual(3, vehicles.Count());
            }
            // admin or sales vehicle search, no search terms entered
            else if (searchTerm == "" && priceMin == 0.00m && priceMax == 100000.00m && yearMin == 2000 && yearMax == 2021 && mileage == -3)
            {
                vehicles = vehicles.OrderBy(v => v.MSRP).Take(20).ToList();
                Assert.AreEqual(7, vehicles.Count());
            }
            else if (mileage == -1) // used vehicle, price min/max or year min/max was entered
            {
                vehicles = vehicles.Where(v => v.Mileage > 1000).ToList();
                var vehiclesToReturn = new List <Vehicle>();
                if (searchTerm != "")
                {
                    foreach (var vehicle in vehicles)
                    {
                        var model = new VehicleWithNames();

                        model.Vehicle = vehicle;
                        model.Model   = models.FirstOrDefault(m => m.ModelID == vehicle.ModelID);
                        model.Make    = makes.FirstOrDefault(m => m.MakeID == vehicle.MakeID);

                        if (model.Make.MakeName.Contains(searchTerm) || model.Model.ModelName.Contains(searchTerm) || model.Vehicle.Year.ToString().Contains(searchTerm))
                        {
                            vehiclesToReturn.Add(model.Vehicle);
                        }
                    }
                }

                if (vehiclesToReturn.Count() > 0)
                {
                    vehiclesToReturn.RemoveAll(v => v.SalePrice < priceMin);
                    vehiclesToReturn.RemoveAll(v => v.SalePrice > priceMax);
                    vehiclesToReturn.RemoveAll(v => v.Year < yearMin);
                    vehiclesToReturn.RemoveAll(v => v.Year > yearMax);

                    Assert.AreEqual(2, vehiclesToReturn.Count());
                }
                else
                {
                    vehicles.RemoveAll(v => v.SalePrice < priceMin);
                    vehicles.RemoveAll(v => v.SalePrice > priceMax);
                    vehicles.RemoveAll(v => v.Year < yearMin);
                    vehicles.RemoveAll(v => v.Year > yearMax);
                }

                Assert.AreEqual(2, vehicles.Count());
            }
            else if (mileage == -2)
            {
                vehicles = vehicles.Where(v => v.Mileage < 1000).ToList();
                Assert.AreEqual(3, vehicles.Count());

                if (searchTerm != "")
                {
                    foreach (var vehicle in vehicles)
                    {
                        var model = new VehicleWithNames();

                        model.Vehicle = vehicle;
                        model.Model   = models.FirstOrDefault(m => m.ModelID == vehicle.ModelID);
                        model.Make    = makes.FirstOrDefault(m => m.MakeID == vehicle.MakeID);

                        if (model.Make.MakeName.Contains(searchTerm) || model.Model.ModelName.Contains(searchTerm) || model.Vehicle.Year.ToString().Contains(searchTerm))
                        {
                            vehicles.Add(model.Vehicle);
                        }
                    }
                }

                vehicles.RemoveAll(v => v.SalePrice < priceMin);
                vehicles.RemoveAll(v => v.SalePrice > priceMax);
                vehicles.RemoveAll(v => v.Year < yearMin);
                vehicles.RemoveAll(v => v.Year > yearMax);

                throw new NotImplementedException();
            }
        }