Ejemplo n.º 1
0
 public void TestCarsRepository_AddMethodWhenPassCarr_ShouldAddCorrectly()
 {
     // Database did not initialise the list, solved it with a database constructor
     var carRepo = new CarsRepository();
     var mockedCar = new Mock<Car>();
     var initialCount = carRepo.TotalCars;
     carRepo.Add(mockedCar.Object);
     var finalCount = carRepo.TotalCars;
     Assert.AreEqual(initialCount + 1, finalCount);
 }
Ejemplo n.º 2
0
        public void TestCarsRepository_AllMethod_ShouldWorkCorrectly()
        {
            var carRepo = new CarsRepository();

            foreach (var car in cars)
            {
                carRepo.Add(car);
            }

            Assert.AreEqual(cars, carRepo.All());
        }
        public void Add_ShouldThrowArgumentException_IfCarIsNull()
        {
            // Arrange
            Car car = null;
            var db = new Database();
            db.Cars = new List<Car>();
            var count = db.Cars.Count;
            var carsRepository = new CarsRepository(db);

            // Act and Assert
            Assert.Throws<ArgumentException>(() => carsRepository.Add(car), "Null car cannot be added");
        }
        public void Add_ShouldAddCarToCarRepository()
        {
            // Arrange
            var car = new Car { Id = 1, Make = "Audi", Model = "A5", Year = 2005 };
            var db = new Database();
            db.Cars = new List<Car>();
            var count = db.Cars.Count;
            var carsRepository = new CarsRepository(db);

            // Act
            carsRepository.Add(car);

            // Assert
            Assert.AreEqual(1, db.Cars.Count);
        }
        public void Remove_ShouldremoveCarFromCarsRepository_WhenIsCalled()
        {
            // Arrange
            var car = new Car { Id = 1, Make = "Audi", Model = "A5", Year = 2005 };
            var db = new Database();
            db.Cars = new List<Car>();
            var carsRepository = new CarsRepository(db);

            // Act
            carsRepository.Add(car);
            carsRepository.Remove(car);

            // Assert
            Assert.AreEqual(0, db.Cars.Count);
        }
Ejemplo n.º 6
0
        public void TestCarsRepository_GetByIdValidParameter_ShouldReturnCar()
        {
            var carRepo = new CarsRepository();
            var car = new Car { Id = 1, Make = "Audi", Model = "A5", Year = 2005 };

            carRepo.Add(car);

            Assert.AreEqual(car, carRepo.GetById(car.Id));
        }
Ejemplo n.º 7
0
 public void TestCarsRepository_AddMethodWhenPassNull_ShouldThrowArgumentException()
 {
     var carRepo = new CarsRepository();
     Assert.Throws<ArgumentException>(() => carRepo.Add(null));
 }
Ejemplo n.º 8
0
        public void TestCarsRepository_SortedByYear_ShouldWorkCorrectly()
        {
            var carRepo = new CarsRepository();

            foreach (var car in cars)
            {
                carRepo.Add(car);
            }

            Assert.AreEqual(cars.OrderBy(c => c.Year).ToList(), carRepo.SortedByYear());
        }
Ejemplo n.º 9
0
        public void TestCarsRepository_SearchMethodPassValidCars_ShouldReturnAllCars()
        {
            var carRepo = new CarsRepository();
            var make = "Audi";
            List<Car> result;

            cars[0].Make = make;
            foreach (var car in cars)
            {
                carRepo.Add(car);
            }
            result = cars.Where(c => c.Make == make || c.Model == make).ToList();

            Assert.AreEqual(result, carRepo.Search(make));
        }
Ejemplo n.º 10
0
        public void TestCarsRepository_SearchMethodPassNull_ShouldReturnAllCars()
        {
            var carRepo = new CarsRepository();

            foreach (var car in cars)
            {
                carRepo.Add(car);
            }

            Assert.AreEqual(cars, carRepo.Search(null));
        }
Ejemplo n.º 11
0
        public void TestCarsRepository_RemoveMethodWhenPassCarr_ShouldRemoveCorrectly()
        {
            var carRepo = new CarsRepository();
            var mockedCar = new Mock<Car>();
            var initialCount = carRepo.TotalCars;

            carRepo.Add(mockedCar.Object);
            carRepo.Remove(mockedCar.Object);
            var finalCount = carRepo.TotalCars;

            Assert.AreEqual(initialCount, finalCount);
        }