コード例 #1
0
        public void TestCarsRepository_AllMethod_ShouldWorkCorrectly()
        {
            var carRepo = new CarsRepository();

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

            Assert.AreEqual(cars, carRepo.All());
        }
コード例 #2
0
        public void All_ShouldReturnAllOfTheCarsInTheDB()
        {
            // Arrange
            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 };
            var thirdCar = new Car { Id = 3, Make = "Lada", Model = "7-marka", Year = 1991 };

            var mock = new Mock<IDatabase>();
            mock.Setup(m => m.Cars).Returns(new List<Car>() { });
            var fakeDB = mock.Object;
            fakeDB.Cars.Add(firstCar);
            fakeDB.Cars.Add(secondCar);
            fakeDB.Cars.Add(thirdCar);
            var carsRepository = new CarsRepository(fakeDB);

            // Act
            var result = carsRepository.All();

            //Assert
            Assert.AreEqual(3, result.Count);
        }