Пример #1
0
        public void CanSearchForUsedCarOnMaxYear()
        {
            CarsRepositoryADO repo = new CarsRepositoryADO();

            CarsSearchParameters searchParameters = new CarsSearchParameters
            {
                IsNew      = false,
                MinYear    = null,
                MaxYear    = new DateTime(2022, 1, 1),
                MaxPrice   = null,
                MinPrice   = null,
                SearchTerm = null
            };

            List <SearchResultItem> searchCarResults = repo.SearchCars(searchParameters).ToList();

            Assert.AreEqual(5, searchCarResults.Count);

            Assert.AreEqual(3, searchCarResults[1].CarId);
            Assert.AreEqual(new DateTime(2019, 1, 1).Year.ToString(), searchCarResults[1].Year);
            Assert.AreEqual("Ford", searchCarResults[1].Make);
            Assert.AreEqual("Escape", searchCarResults[1].Model);
            Assert.AreEqual("White", searchCarResults[1].BodyColor);
            Assert.AreEqual("White", searchCarResults[1].InteriorColor);
            Assert.AreEqual("Automatic", searchCarResults[1].Transmission);
            Assert.AreEqual("/Images/2017FordEscape.png", searchCarResults[1].IMGURL);
            Assert.AreEqual("3ABC3ABC3ABC3ABC3", searchCarResults[1].VIN);
            Assert.AreEqual("1200", searchCarResults[1].Mileage);
            Assert.AreEqual(22669m, searchCarResults[1].SalePrice);
            Assert.AreEqual(24500m, searchCarResults[1].MSRP);
        }
Пример #2
0
        public void CanSearchForNewCarOnMinPrice()
        {
            CarsRepositoryADO repo = new CarsRepositoryADO();

            CarsSearchParameters searchParameters = new CarsSearchParameters
            {
                IsNew      = true,
                MinYear    = null,
                MaxYear    = null,
                MaxPrice   = null,
                MinPrice   = 50000m,
                SearchTerm = null
            };

            List <SearchResultItem> searchCarResults = repo.SearchCars(searchParameters).ToList();

            Assert.AreEqual(3, searchCarResults.Count);

            Assert.AreEqual(1, searchCarResults[1].CarId);
            Assert.AreEqual(new DateTime(2021, 1, 1).Year.ToString(), searchCarResults[1].Year);
            Assert.AreEqual("Toyota", searchCarResults[1].Make);
            Assert.AreEqual("Tundra LX", searchCarResults[1].Model);
            Assert.AreEqual("Black", searchCarResults[1].BodyColor);
            Assert.AreEqual("Black", searchCarResults[1].InteriorColor);
            Assert.AreEqual("Automatic", searchCarResults[1].Transmission);
            Assert.AreEqual("/Images/2017ToyotaTundra1794.jpg", searchCarResults[1].IMGURL);
            Assert.AreEqual("1ABC1ABC1ABC1ABC1", searchCarResults[1].VIN);
            Assert.AreEqual("0", searchCarResults[1].Mileage);
            Assert.AreEqual(50315m, searchCarResults[1].SalePrice);
            Assert.AreEqual(51815m, searchCarResults[1].MSRP);
        }
Пример #3
0
        public void CanGetCarById()
        {
            CarsRepositoryADO repo = new CarsRepositoryADO();
            Car car = repo.GetCarById(2);

            Assert.IsNotNull(car);

            Assert.AreEqual("2ABC2ABC2ABC2ABC2", car.VIN);
            Assert.AreEqual(2, car.CarId);
            Assert.AreEqual(new DateTime(2020, 1, 1), car.ModelYear);
            Assert.IsTrue(car.IsNew);
            Assert.IsFalse(car.IsSold);
            Assert.IsTrue(car.IsFeatured);
            Assert.AreEqual(1, car.UnitsInStock);
            Assert.AreEqual("200", car.Mileage);
            Assert.AreEqual(2, car.BodyColorId);
            Assert.AreEqual(2, car.BodyStyleId);
            Assert.AreEqual(2, car.TransmissionId);
            Assert.AreEqual(2, car.MakeId);
            Assert.AreEqual(3, car.ModelId);
            Assert.AreEqual(3, car.InteriorColorId);
            Assert.AreEqual(33000.00m, car.SalePrice);
            Assert.AreEqual(34150.00m, car.MSRP);
            Assert.AreEqual("/Images/2018AcuraTLX.png", car.IMGFilePath);
            Assert.AreEqual("Very very very dependable.", car.VehicleDetails);
        }
Пример #4
0
        public void CanGetSoldCars()
        {
            CarsRepositoryADO repo = new CarsRepositoryADO();
            List <Car>        cars = repo.GetAllSoldCars().ToList();

            Assert.AreEqual(2, cars.Count);

            Assert.AreEqual("3ABC3ABC3ABC3ABC3", cars[1].VIN);
            Assert.AreEqual(3, cars[1].CarId);
            Assert.AreEqual(new DateTime(2019, 1, 1), cars[1].ModelYear);
            Assert.IsFalse(cars[1].IsNew);
            Assert.IsTrue(cars[1].IsSold);
            Assert.IsTrue(cars[1].IsFeatured);
            Assert.AreEqual(1, cars[1].UnitsInStock);
            Assert.AreEqual("1200", cars[1].Mileage);
            Assert.AreEqual(5, cars[1].BodyColorId);
            Assert.AreEqual(3, cars[1].BodyStyleId);
            Assert.AreEqual(1, cars[1].TransmissionId);
            Assert.AreEqual(3, cars[1].MakeId);
            Assert.AreEqual(2, cars[1].ModelId);
            Assert.AreEqual(5, cars[1].InteriorColorId);
            Assert.AreEqual(22669.00m, cars[1].SalePrice);
            Assert.AreEqual(24500.00m, cars[1].MSRP);
            Assert.AreEqual("/Images/2017FordEscape.png", cars[1].IMGFilePath);
            Assert.AreEqual("Loaded!", cars[1].VehicleDetails);
        }
Пример #5
0
        public void CanGetNewCars()
        {
            CarsRepositoryADO repo = new CarsRepositoryADO();
            List <Car>        cars = repo.GetAllNewCars().ToList();

            Assert.AreEqual(5, cars.Count);

            Assert.AreEqual("2ABC2ABC2ABC2ABC2", cars[1].VIN);
            Assert.AreEqual(2, cars[1].CarId);
            Assert.AreEqual(new DateTime(2020, 1, 1), cars[1].ModelYear);
            Assert.IsTrue(cars[1].IsNew);
            Assert.IsFalse(cars[1].IsSold);
            Assert.IsTrue(cars[1].IsFeatured);
            Assert.AreEqual(1, cars[1].UnitsInStock);
            Assert.AreEqual("200", cars[1].Mileage);
            Assert.AreEqual(2, cars[1].BodyColorId);
            Assert.AreEqual(2, cars[1].BodyStyleId);
            Assert.AreEqual(2, cars[1].TransmissionId);
            Assert.AreEqual(2, cars[1].MakeId);
            Assert.AreEqual(3, cars[1].ModelId);
            Assert.AreEqual(3, cars[1].InteriorColorId);
            Assert.AreEqual(33000.00m, cars[1].SalePrice);
            Assert.AreEqual(34150.00m, cars[1].MSRP);
            Assert.AreEqual("/Images/2018AcuraTLX.png", cars[1].IMGFilePath);
            Assert.AreEqual("Very very very dependable.", cars[1].VehicleDetails);
        }
Пример #6
0
        public void CanGetUnsoldCars()
        {
            CarsRepositoryADO repo = new CarsRepositoryADO();
            List <Car>        cars = repo.GetAllUnsoldCars().ToList();

            Assert.AreEqual(8, cars.Count);

            Assert.AreEqual("4ABC4ABC4ABC4ABC4", cars[1].VIN);
            Assert.AreEqual(4, cars[1].CarId);
            Assert.AreEqual(new DateTime(2005, 1, 1), cars[1].ModelYear);
            Assert.IsFalse(cars[1].IsNew);
            Assert.IsFalse(cars[1].IsSold);
            Assert.IsFalse(cars[1].IsFeatured);
            Assert.AreEqual(1, cars[1].UnitsInStock);
            Assert.AreEqual("111200", cars[1].Mileage);
            Assert.AreEqual(5, cars[1].BodyColorId);
            Assert.AreEqual(4, cars[1].BodyStyleId);
            Assert.AreEqual(1, cars[1].TransmissionId);
            Assert.AreEqual(4, cars[1].MakeId);
            Assert.AreEqual(4, cars[1].ModelId);
            Assert.AreEqual(4, cars[1].InteriorColorId);
            Assert.AreEqual(4000.00m, cars[1].SalePrice);
            Assert.AreEqual(5000.00m, cars[1].MSRP);
            Assert.AreEqual("/Images/2005DodgeGrandCaravan.jpg", cars[1].IMGFilePath);
            Assert.AreEqual("Dusty old van.", cars[1].VehicleDetails);
        }
Пример #7
0
        public void CanDeleteCar()
        {
            Car carToAdd = new Car();
            var repo     = new CarsRepositoryADO();

            carToAdd.MakeModelId     = 2;
            carToAdd.CarTypeId       = 2;
            carToAdd.BodyStyleId     = 2;
            carToAdd.TransmissionId  = 2;
            carToAdd.CarColorId      = 2;
            carToAdd.CarYear         = 1999;
            carToAdd.VIN             = 222;
            carToAdd.MSRP            = 17000M;
            carToAdd.SalePrice       = 16500M;
            carToAdd.CarDescription  = "Description2";
            carToAdd.Mileage         = 47000;
            carToAdd.InteriorColorId = 2;
            carToAdd.PicturePNG      = "Placeholder.png2";
            carToAdd.IsFeatured      = true;

            repo.Insert(carToAdd);

            var loaded = repo.GetById(2);

            Assert.IsNotNull(loaded);

            repo.Delete(2);
            loaded = repo.GetById(2);

            Assert.IsNull(loaded);
        }
Пример #8
0
        public void NotFoundCarReturnsNull()
        {
            var repo = new CarsRepositoryADO();
            var car  = repo.GetById(5000);

            Assert.IsNull(car);
        }
Пример #9
0
        public void CanUpdateCar()
        {
            Car carToAdd = new Car();
            var repo     = new CarsRepositoryADO();

            carToAdd.MakeModelId     = 2;
            carToAdd.CarTypeId       = 2;
            carToAdd.BodyStyleId     = 2;
            carToAdd.TransmissionId  = 2;
            carToAdd.CarColorId      = 2;
            carToAdd.CarYear         = 1999;
            carToAdd.VIN             = 222;
            carToAdd.MSRP            = 17000M;
            carToAdd.SalePrice       = 16500M;
            carToAdd.CarDescription  = "Description2";
            carToAdd.Mileage         = 47000;
            carToAdd.InteriorColorId = 2;
            carToAdd.PicturePNG      = "Placeholder.png2";
            carToAdd.IsFeatured      = true;

            repo.Insert(carToAdd);

            carToAdd.MakeModelId     = 3;
            carToAdd.CarTypeId       = 1;
            carToAdd.BodyStyleId     = 1;
            carToAdd.TransmissionId  = 1;
            carToAdd.CarColorId      = 4;
            carToAdd.CarYear         = 1998;
            carToAdd.VIN             = 212;
            carToAdd.MSRP            = 21000M;
            carToAdd.SalePrice       = 2000M;
            carToAdd.CarDescription  = "Look at these updates!";
            carToAdd.Mileage         = 175000;
            carToAdd.InteriorColorId = 4;
            carToAdd.PicturePNG      = "Placeholder.png2";
            carToAdd.IsFeatured      = false;

            repo.Update(carToAdd);

            var updatedCar = repo.GetById(3);

            Assert.AreEqual(3, updatedCar.MakeModelId);
            Assert.AreEqual(1, updatedCar.CarTypeId);
            Assert.AreEqual(1, updatedCar.BodyStyleId);
            Assert.AreEqual(1, updatedCar.TransmissionId);
            Assert.AreEqual(4, updatedCar.CarColorId);
            Assert.AreEqual(1998, updatedCar.CarYear);
            Assert.AreEqual(212, updatedCar.VIN);
            Assert.AreEqual(21000M, updatedCar.MSRP);
            Assert.AreEqual(2000M, updatedCar.SalePrice);
            Assert.AreEqual("Look at these updates!", updatedCar.CarDescription);
            Assert.AreEqual(175000, updatedCar.Mileage);
            Assert.AreEqual(4, updatedCar.InteriorColorId);
            Assert.AreEqual("Placeholder.png2", updatedCar.PicturePNG);
            Assert.AreEqual(false, updatedCar.IsFeatured);
        }
Пример #10
0
        public void CanAddCar()
        {
            Car car = new Car
            {
                ModelYear       = new DateTime(2015, 1, 1),
                IsNew           = false,
                IsFeatured      = true,
                IsSold          = false,
                UnitsInStock    = 1,
                Mileage         = "20000",
                VIN             = "5ABC5ABC5ABC5ABC5",
                BodyColorId     = 5,
                BodyStyleId     = 3,
                TransmissionId  = 2,
                MakeId          = 3,
                ModelId         = 2,
                InteriorColorId = 5,
                SalePrice       = 19500m,
                MSRP            = 21000m,
                IMGFilePath     = "Images/placeholder.png",
                VehicleDetails  = "2015 Ford Escape. Fully Loaded!"
            };

            CarsRepositoryADO repo = new CarsRepositoryADO();

            repo.Insert(car);

            List <Car> cars = repo.GetAllCars().ToList();

            Assert.AreEqual(11, cars.Count);

            Assert.IsNotNull(cars[10].CarId);
            Assert.AreEqual(car.ModelYear, cars[10].ModelYear);
            Assert.AreEqual(car.IsNew, cars[10].IsNew);
            Assert.AreEqual(car.IsFeatured, cars[10].IsFeatured);
            Assert.AreEqual(car.IsSold, cars[10].IsSold);
            Assert.AreEqual(car.UnitsInStock, cars[10].UnitsInStock);
            Assert.AreEqual(car.Mileage, cars[10].Mileage);
            Assert.AreEqual(car.VIN, cars[10].VIN);
            Assert.AreEqual(car.BodyColorId, cars[10].BodyColorId);
            Assert.AreEqual(car.BodyStyleId, cars[10].BodyStyleId);
            Assert.AreEqual(car.TransmissionId, cars[10].TransmissionId);
            Assert.AreEqual(car.MakeId, cars[10].MakeId);
            Assert.AreEqual(car.ModelId, cars[10].ModelId);
            Assert.AreEqual(car.InteriorColorId, cars[10].InteriorColorId);
            Assert.AreEqual(car.SalePrice, cars[10].SalePrice);
            Assert.AreEqual(car.MSRP, cars[10].MSRP);
            Assert.AreEqual(car.IMGFilePath, cars[10].IMGFilePath);
            Assert.AreEqual(car.VehicleDetails, cars[10].VehicleDetails);
        }
Пример #11
0
        public void CanLoadFeatured()
        {
            var             repo     = new CarsRepositoryADO();
            List <Featured> featured = repo.GetFeatured().ToList();

            Assert.AreEqual(1, featured.Count());

            Assert.AreEqual(2, featured[0].CarId);
            Assert.AreEqual(2, featured[0].MakeModelId);
            Assert.AreEqual("Make2", featured[0].MakeName);
            Assert.AreEqual("Model2", featured[0].ModelName);
            Assert.AreEqual("Placeholder2.PNG", featured[0].PicturePNG);
            Assert.AreEqual(3000M, featured[0].SalePrice);
        }
Пример #12
0
        public void CanGetFeaturedCars()
        {
            CarsRepositoryADO            repo         = new CarsRepositoryADO();
            List <FeaturedShortListItem> featuredCars = repo.GetAllFeaturedCars().ToList();

            Assert.AreEqual(8, featuredCars.Count);

            Assert.AreEqual(2, featuredCars[0].CarId);
            Assert.AreEqual(new DateTime(2020, 1, 1), featuredCars[0].Year);
            Assert.AreEqual(2, featuredCars[0].MakeId);
            Assert.AreEqual(3, featuredCars[0].ModelId);
            Assert.AreEqual(33000.00m, featuredCars[0].Price);
            Assert.AreEqual("/Images/2018AcuraTLX.png", featuredCars[0].ImageURL);
            Assert.AreEqual("Acura", featuredCars[0].Make);
            Assert.AreEqual("TLX", featuredCars[0].Model);
        }
Пример #13
0
        public void CanDeleteCar()
        {
            Car car = new Car
            {
                ModelYear       = new DateTime(2015, 1, 1),
                IsNew           = false,
                IsFeatured      = true,
                IsSold          = false,
                UnitsInStock    = 1,
                Mileage         = "20000",
                VIN             = "5ABC5ABC5ABC5ABC5",
                BodyColorId     = 5,
                BodyStyleId     = 3,
                TransmissionId  = 2,
                MakeId          = 3,
                ModelId         = 2,
                InteriorColorId = 5,
                SalePrice       = 19500m,
                MSRP            = 21000m,
                IMGFilePath     = "Images/placeholder.png",
                VehicleDetails  = "2015 Ford Escape. Fully Loaded!"
            };

            CarsRepositoryADO repo = new CarsRepositoryADO();

            repo.Insert(car);

            List <Car> cars = repo.GetAllCars().ToList();

            Assert.AreEqual(11, cars.Count);

            Assert.IsNotNull(cars[10].CarId);
            Assert.AreEqual("20000", cars[10].Mileage);
            Assert.AreEqual("5ABC5ABC5ABC5ABC5", cars[10].VIN);

            repo.Delete(10);

            List <Car> updatedCar = repo.GetAllCars().ToList();

            Car deletedCar = updatedCar.FirstOrDefault(c => c.CarId == 10);

            Assert.AreEqual(10, updatedCar.Count);

            Assert.IsNull(deletedCar);
        }
Пример #14
0
        public void CanLoadCar()
        {
            var repo = new CarsRepositoryADO();
            var car  = repo.GetById(1);

            Assert.IsNotNull(car);
            Assert.AreEqual(1, car.CarId);
            Assert.AreEqual(1, car.MakeModelId);
            Assert.AreEqual(1, car.CarTypeId);
            Assert.AreEqual(1, car.BodyStyleId);
            Assert.AreEqual(1, car.TransmissionId);
            Assert.AreEqual(1, car.CarColorId);
            Assert.AreEqual(2017, car.CarYear);
            Assert.AreEqual(111, car.VIN);
            Assert.AreEqual(10000M, car.MSRP);
            Assert.AreEqual(12000M, car.SalePrice);
            Assert.AreEqual("Brilliant", car.CarDescription);
            Assert.AreEqual(777, car.Mileage);
            Assert.AreEqual(1, car.InteriorColorId);
            Assert.AreEqual("Placeholder.PNG", car.PicturePNG);
        }
Пример #15
0
        public void CanAddCar()
        {
            Car carToAdd = new Car();
            var repo     = new CarsRepositoryADO();

            carToAdd.MakeModelId     = 2;
            carToAdd.CarTypeId       = 2;
            carToAdd.BodyStyleId     = 2;
            carToAdd.TransmissionId  = 2;
            carToAdd.CarColorId      = 2;
            carToAdd.CarYear         = 1999;
            carToAdd.VIN             = 222;
            carToAdd.MSRP            = 17000M;
            carToAdd.SalePrice       = 16500M;
            carToAdd.CarDescription  = "Description2";
            carToAdd.Mileage         = 47000;
            carToAdd.InteriorColorId = 2;
            carToAdd.PicturePNG      = "Placeholder.png2";
            carToAdd.IsFeatured      = true;

            repo.Insert(carToAdd);

            Assert.AreEqual(3, carToAdd.CarId);
        }
Пример #16
0
        public void CanUpdateCar()
        {
            Car car = new Car
            {
                ModelYear       = new DateTime(2015, 1, 1),
                IsNew           = false,
                IsFeatured      = true,
                IsSold          = false,
                UnitsInStock    = 1,
                Mileage         = "20000",
                VIN             = "5ABC5ABC5ABC5ABC5",
                BodyColorId     = 5,
                BodyStyleId     = 3,
                TransmissionId  = 2,
                MakeId          = 3,
                ModelId         = 2,
                InteriorColorId = 5,
                SalePrice       = 19500m,
                MSRP            = 21000m,
                IMGFilePath     = "Images/placeholder.png",
                VehicleDetails  = "2015 Ford Escape. Fully Loaded!"
            };

            CarsRepositoryADO repo = new CarsRepositoryADO();

            repo.Insert(car);

            car.BodyColorId     = 2;
            car.InteriorColorId = 5;
            car.SalePrice       = 17500m;
            car.MSRP            = 19200m;
            car.IMGFilePath     = "Images/updatedImage.png";
            car.IsSold          = true;
            car.IsNew           = true;
            car.IsFeatured      = true;
            car.VIN             = "6ABC6ABC6ABC6ABC6";
            car.VehicleDetails  = "Updated";
            car.Mileage         = "3";
            car.ModelYear       = new DateTime(2018, 1, 1);
            car.MakeId          = 2;
            car.ModelId         = 3;
            car.TransmissionId  = 1;
            car.UnitsInStock    = 9;
            car.BodyStyleId     = 2;

            repo.Update(car);

            var updatedCar = repo.GetCarById(car.CarId);

            Assert.AreEqual(updatedCar.BodyStyleId, 2);
            Assert.AreEqual(updatedCar.BodyColorId, 2);
            Assert.AreEqual(updatedCar.InteriorColorId, 5);
            Assert.AreEqual(updatedCar.IMGFilePath, "Images/updatedImage.png");
            Assert.AreEqual(updatedCar.SalePrice, 17500m);
            Assert.AreEqual(updatedCar.MSRP, 19200m);
            Assert.AreEqual(updatedCar.IsNew, true);
            Assert.AreEqual(updatedCar.IsFeatured, true);
            Assert.AreEqual(updatedCar.IsSold, true);
            Assert.AreEqual(updatedCar.VIN, "6ABC6ABC6ABC6ABC6");
            Assert.AreEqual(updatedCar.VehicleDetails, "Updated");
            Assert.AreEqual(updatedCar.Mileage, "3");
            Assert.AreEqual(updatedCar.ModelYear, new DateTime(2018, 1, 1));
            Assert.AreEqual(updatedCar.MakeId, 2);
            Assert.AreEqual(updatedCar.ModelId, 3);
            Assert.AreEqual(updatedCar.TransmissionId, 1);
            Assert.AreEqual(updatedCar.UnitsInStock, 8);
        }