public void Search_ShouldReturnListOfAllCars_IfStringIsNullOrEmpty()
        {
            // Arrange
            var datebase = new List<Car>();
            var firstCar = new Car { Id = 1, Make = "Audi", Model = "A5", Year = 2005 };
            var secondCar = new Car { Id = 2, Make = "Moskvich", Model = "12-tak", Year = 1980 };
            datebase.Add(firstCar);
            datebase.Add(secondCar);
            var mock = new Mock<IDatabase>();
            mock.Setup(m => m.Cars).Returns(datebase);
            var fakeDB = mock.Object;
            var carsRepository = new CarsRepository(fakeDB);

            // Act
            var result = carsRepository.Search("");

            // Assert
            mock.Verify(m => m.Cars, Times.Exactly(1));
        }
示例#2
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));
        }
        public void Search_ShouldReturnCarByGivenString()
        {
            // Arrange
            var datebase = new List<Car>();
            var firstCar = new Car { Id = 1, Make = "Audi", Model = "A5", Year = 2005 };
            datebase.Add(firstCar);
            var mock = new Mock<IDatabase>();
            mock.Setup(m => m.Cars).Returns(datebase);
            var fakeDB = mock.Object;
            var carsRepository = new CarsRepository(fakeDB);

            // Act
            var result = carsRepository.Search("Audi");

            // Assert
            mock.Verify(m => m.Cars, Times.Exactly(1));
        }
示例#4
0
        public void TestCarsRepository_SearchMethodPassNull_ShouldReturnAllCars()
        {
            var carRepo = new CarsRepository();

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

            Assert.AreEqual(cars, carRepo.Search(null));
        }