Ejemplo n.º 1
0
        private void btnReset_Click(object sender, EventArgs e)
        {
            txtSearchText.Text = "";
            carSearchCriteria  = new CarSearchCriteria();

            UpdateList();
        }
Ejemplo n.º 2
0
 /// <inheritdoc></inheritdoc>
 public List <Car> GetCars(CarSearchCriteria criteria)
 {
     return(this.GetDemoCars().Where(x =>
                                     x.NumberOfDoors >= criteria.NumberOfDoors &&
                                     x.RentalPrice >= criteria.RentalPrice &&
                                     x.TrunkCapacity >= criteria.TrunkCapacity).ToList());
 }
        public void A130_GetListByCriteriaNoCriteria()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria);

            Assert.AreEqual(numberOfCars, cars.Count);
        }
Ejemplo n.º 4
0
        public IEnumerable <CarViewModel> Search(CarSearchCriteria criteria)
        {
            Logger.Debug("CarSearchCriteria Received: {0}",
                         JsonConvert.SerializeObject(criteria, Formatting.Indented));
            var cars = CarService.SearchCars(criteria);

            return(cars);
        }
        public void A140_GetListByCriteriaNoCriteriaOrdered()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria, orderedList: true);

            Assert.AreEqual(numberOfCars, cars.Count);
            Assert.AreEqual(Car7.PrimaryKey, cars[0].PrimaryKey);
        }
Ejemplo n.º 6
0
        public void A180_ValidateSearchCritera()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.CategoryFrom = CarCategory.N300;
            carSearchCriteria.CategoryTo   = CarCategory.N600;
            carSearchCriteria.DriveTrain   = DriveTrain.FourWD;

            carValidation.ValidateSearchCriteria(carSearchCriteria);
        }
        public void A400_GetListByCriteriaRegionOrdered()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.RegionDescription = regionDescription;

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria, orderedList: true);

            Assert.AreEqual(numberOfRegionRecords, cars.Count);
            Assert.AreEqual(Car7.PrimaryKey, cars[0].PrimaryKey);
        }
        public void A190_GetListByCriteriaCategoryMax()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.CategoryTo = categoryMaxRange;

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria);

            Assert.AreEqual(numberOfCategoryMaxRecords, cars.Count);
            Assert.AreEqual(Car1.PrimaryKey, cars[0].PrimaryKey);
        }
        public void A360_GetListByCriteriaManufacturerOrdered()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.ManufacturerName = manufacturerName;

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria, orderedList: true);

            Assert.AreEqual(numberOfManufacturerRecords, cars.Count);
            Assert.AreEqual(Car2.PrimaryKey, cars[0].PrimaryKey);
        }
Ejemplo n.º 10
0
        /// <summary>Initializes a new instance of the <see cref="FilterCarsForm"/> class.</summary>
        /// <param name="returnCriteria">The return criteria the parent form is currently set to.</param>
        /// <param name="con">The database connection.</param>
        /// <exception cref="ArgumentNullException">returnCriteria or con</exception>
        public FilterCarsForm(CarSearchCriteria returnCriteria, NpgsqlConnection con)
        {
            this.returnCriteria = returnCriteria ?? throw new ArgumentNullException(nameof(returnCriteria));
            this.con            = con ?? throw new ArgumentNullException(nameof(con));

            manufacturersService = new ManufacturersService(con);
            countiresService     = new CountriesService(con);
            regionsService       = new RegionsService(con);

            InitializeComponent();
        }
Ejemplo n.º 11
0
        public void A340_GetListByCriteriaDriveTrainOrdered()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.DriveTrain = driveTrainTest;

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria, orderedList: true);

            Assert.AreEqual(numberOfDriveTrainRecords, cars.Count);
            Assert.AreEqual(Car6.PrimaryKey, cars[0].PrimaryKey);
        }
Ejemplo n.º 12
0
        public void A320_GetListByCriteriaMaxPowerMaxOrdered()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.MaxPowerTo = maxPowerMaxRange;

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria, orderedList: true);

            Assert.AreEqual(numberOfMaxPowerMaxRecords, cars.Count);
            Assert.AreEqual(Car7.PrimaryKey, cars[0].PrimaryKey);
        }
Ejemplo n.º 13
0
        public void A290_GetListByCriteriaMaxPowerMin()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.MaxPowerFrom = maxPowerMinRange;

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria);

            Assert.AreEqual(numberOfMaxPowerMinRecords, cars.Count);
            Assert.AreEqual(Car6.PrimaryKey, cars[0].PrimaryKey);
        }
Ejemplo n.º 14
0
        public void A250_GetListByCriteriaYearMax()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.YearTo = yearMaxRange;

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria);

            Assert.AreEqual(numberOfYearMaxRecords, cars.Count);
            Assert.AreEqual(Car3.PrimaryKey, cars[0].PrimaryKey);
        }
Ejemplo n.º 15
0
        public List <CarViewModel> SearchCars(CarSearchCriteria criteria)
        {
            //build EF query for search criteria
            var carQuery = CarRepository.Query();

            //dont show inactive cars
            carQuery = carQuery.Where(x => x.Status.Equals(Constants.CarAvailableStatus));

            if (!string.IsNullOrWhiteSpace(criteria.CarCategory))
            {
                carQuery = carQuery.Where(x => x.CarCategory.Equals(criteria.CarCategory));
            }
            if (!string.IsNullOrWhiteSpace(criteria.Suburb))
            {
                carQuery = carQuery.Where(x => x.Suburb.Equals(criteria.Suburb));
            }
            if (!string.IsNullOrWhiteSpace(criteria.Make))
            {
                carQuery = carQuery.Where(x => x.Make.Equals(criteria.Make));
            }
            if (!string.IsNullOrWhiteSpace(criteria.Model))
            {
                carQuery = carQuery.Where(x => x.Model.Equals(criteria.Model));
            }

            //execute query
            var cars = carQuery.ToList().Select(x => new CarViewModel(x)).ToList();

            //perform distance calculation in memory
            if (criteria.Longitude.HasValue && criteria.Latitude.HasValue)
            {
                foreach (var car in cars)
                {
                    //use microsofts haversine formula (returns metres)
                    var carCoordinate    = new GeoCoordinate((double)car.LatPos, (double)car.LongPos);
                    var searchCoordinate = new GeoCoordinate((double)criteria.Latitude.Value,
                                                             (double)criteria.Longitude.Value);
                    car.Distance = carCoordinate.GetDistanceTo(searchCoordinate);
                }
            }
            if (criteria.Radius.HasValue)
            {
                cars.RemoveAll(x => !x.Distance.HasValue || x.Distance.Value > criteria.Radius.Value);
            }

            cars = cars.OrderBy(x => x.Distance).ToList();

            if (criteria.MaxResults.HasValue)
            {
                cars = cars.Take(criteria.MaxResults.Value).ToList();
            }

            return(cars);
        }
Ejemplo n.º 16
0
        public void A380_GetListByCriteriaCountryOrdered()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.CountryDescription = countryDescription;

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria, orderedList: true);

            Assert.AreEqual(numberOfCountryRecords, cars.Count);
            Assert.AreEqual(Car5.PrimaryKey, cars[0].PrimaryKey);
        }
Ejemplo n.º 17
0
        public void A240_GetListByCriteriaYearMinOrdered()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.YearFrom = yearMinRange;

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria, orderedList: true);

            Assert.AreEqual(numberOfYearMinRecords, cars.Count);
            Assert.AreEqual(Car7.PrimaryKey, cars[0].PrimaryKey);
        }
Ejemplo n.º 18
0
        public void A160_GetListByCriteriaCategoryRangeOrdered()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.CategoryFrom = categoryMinRange;
            carSearchCriteria.CategoryTo   = categoryMaxRange;

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria, orderedList: true);

            Assert.AreEqual(numberOfCategoryRangeRecords, cars.Count);
            Assert.AreEqual(Car7.PrimaryKey, cars[0].PrimaryKey);
        }
Ejemplo n.º 19
0
        private void btnFilter_Click(object sender, EventArgs e)
        {
            FilterCarsForm filterCarsForm = new FilterCarsForm(carSearchCriteria, con);

            if (filterCarsForm.ShowDialog(this) == DialogResult.OK)
            {
                carSearchCriteria = filterCarsForm.returnCriteria;
                UpdateList();
                tvOwnedCars.Focus();
            }

            filterCarsForm.Dispose();
        }
Ejemplo n.º 20
0
        public void CarSearch_Everything_OnlyActiveCars()
        {
            //check on car search when ensuring only active cars are returned
            // Arrange
            var criteria = new CarSearchCriteria();

            // Act
            var result = Controller.Search(criteria);

            Console.WriteLine("Testing {0} Cars", result.Count());

            foreach (var car in result)
                Assert.IsTrue(car.Status.Equals("Available",
                    StringComparison.InvariantCultureIgnoreCase));
        }
Ejemplo n.º 21
0
        public void CarSearch_WithMaxResults_DoesNotExceedLimit()
        {
            //check on car search does not exceed other paging restrictions
            // Arrange
            var criteria = new CarSearchCriteria
            {
                MaxResults = 10
            };

            // Act
            var result = Controller.Search(criteria);

            Console.WriteLine("Testing {0} Cars", result.Count());

            Assert.IsTrue(result.Count() <= criteria.MaxResults.Value);
        }
Ejemplo n.º 22
0
        public void A190_ValidateSearchCriteraBadFromCategory()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.CategoryFrom = badCategory;
            carSearchCriteria.CategoryTo   = CarCategory.N600;
            carSearchCriteria.DriveTrain   = DriveTrain.FourWD;

            try
            {
                carValidation.ValidateSearchCriteria(carSearchCriteria);
            } catch (CarCategoryNotValidException ccnve)
            {
                Assert.AreEqual(CarCategoryNotValidException.CarCategoryNotValidMsg, ccnve.Message);
                throw ccnve;
            }
        }
Ejemplo n.º 23
0
        public void CarSearch_NearLocation_ReturnsCalculcatedDistances()
        {
            //check on car search when searching vehicles nearby
            // Arrange
            var criteria = new CarSearchCriteria
            {
                Latitude = (decimal) -33.89806198,
                Longitude = (decimal) 151.17925644
            };

            // Act
            var result = Controller.Search(criteria);

            Console.WriteLine("Testing {0} Cars", result.Count());

            foreach (var car in result)
                Assert.IsTrue(car.Distance.HasValue);
        }
Ejemplo n.º 24
0
        public void CarSearch_ByModel_OnlyReturnsThatModel()
        {
            //check on car search when searching vehicle model
            // Arrange
            var criteria = new CarSearchCriteria
            {
                Model = "CLS250"
            };

            // Act
            var result = Controller.Search(criteria);

            Console.WriteLine("Testing {0} Cars", result.Count());

            foreach (var car in result)
                Assert.IsTrue(car.Model.Equals(criteria.Model,
                    StringComparison.InvariantCultureIgnoreCase));
        }
Ejemplo n.º 25
0
        public void CarSearch_InSuburb_OnlyReturnsThatSuburb()
        {
            //check to see cars are within the suburb search
            // Arrange
            var criteria = new CarSearchCriteria
            {
                Suburb = "Sydney"
            };

            // Act
            var result = Controller.Search(criteria);

            Console.WriteLine("Testing {0} Cars", result.Count());

            foreach (var car in result)
                Assert.IsTrue(car.Suburb.Equals(criteria.Suburb,
                    StringComparison.InvariantCultureIgnoreCase));
        }
Ejemplo n.º 26
0
        public void A210_ValidateSearchCriteraBadDriveTrain()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.CategoryFrom = CarCategory.N300;
            carSearchCriteria.CategoryTo   = CarCategory.N600;
            carSearchCriteria.DriveTrain   = badDriveTrain;

            try
            {
                carValidation.ValidateSearchCriteria(carSearchCriteria);
            }
            catch (CarDriveTrainNotValidException cdtnve)
            {
                Assert.AreEqual(CarDriveTrainNotValidException.CarDriveTrainNotValidMsg, cdtnve.Message);
                throw cdtnve;
            }
        }
Ejemplo n.º 27
0
        public void CarSearch_NearLocationAndRadius_ReturnsCarsWithinRadius()
        {
            //check on car search when searching nearby within a distance
            // Arrange
            var criteria = new CarSearchCriteria
            {
                Latitude = (decimal) -33.89806198,
                Longitude = (decimal) 151.17925644,
                Radius = 10000
            };

            // Act
            var result = Controller.Search(criteria);

            Console.WriteLine("Testing {0} Cars", result.Count());

            foreach (var car in result)
                Assert.IsTrue(car.Distance.HasValue &&
                              car.Distance.Value <= criteria.Radius.Value);
        }
Ejemplo n.º 28
0
        public void A420_GetListByCriteriaMultipuleCriteriaOrdered()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.CategoryFrom       = multipuleCriteriaCategoryMinRange;
            carSearchCriteria.CategoryTo         = categoryMaxRange;
            carSearchCriteria.YearFrom           = yearMinRange;
            carSearchCriteria.YearTo             = multipuleCriteriaYearMaxRange;
            carSearchCriteria.MaxPowerFrom       = multipuleCriteriaMaxPowerMinRange;
            carSearchCriteria.MaxPowerTo         = maxPowerMaxRange;
            carSearchCriteria.DriveTrain         = multipuleCriteriaDriveTrainTest;
            carSearchCriteria.ManufacturerName   = manufacturerName;
            carSearchCriteria.CountryDescription = countryDescription;
            carSearchCriteria.RegionDescription  = regionDescription;

            List <Car> cars = carsRepository.GetListByCriteria(carSearchCriteria, orderedList: true);

            Assert.AreEqual(numberOfMultipuleCriteriaRecords, cars.Count);
            Assert.AreEqual(Car2.PrimaryKey, cars[0].PrimaryKey);
        }
Ejemplo n.º 29
0
        public void A130_GetListForSearchCriteraOrdered()
        {
            CarSearchCriteria carSearchCriteria = new CarSearchCriteria();

            carSearchCriteria.CategoryFrom       = categoryMinRange;
            carSearchCriteria.CategoryTo         = categoryMaxRange;
            carSearchCriteria.YearFrom           = yearMinRange;
            carSearchCriteria.YearTo             = yearMaxRange;
            carSearchCriteria.MaxPowerFrom       = maxPowerMinRange;
            carSearchCriteria.MaxPowerTo         = maxPowerMaxRange;
            carSearchCriteria.DriveTrain         = driveTrainTest;
            carSearchCriteria.ManufacturerName   = manufacturerName;
            carSearchCriteria.CountryDescription = countryDescription;
            carSearchCriteria.RegionDescription  = regionDescription;

            List <Car> cars = carsService.GetListForSearchCriteria(carSearchCriteria, orderedList: true);

            Assert.AreEqual(numberOfCriteriaRecords, cars.Count);
            Assert.AreEqual(Car2.PrimaryKey, cars[0].PrimaryKey);
        }