public void SortedByYear_ShouldReturnSortedListOfCarsByYear()
        {
            // 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 };
            var thirdCar = new Car { Id = 3, Make = "Lada", Model = "7-marka", Year = 1991 };
            datebase.Add(firstCar);
            datebase.Add(secondCar);
            datebase.Add(thirdCar);

            var mock = new Mock<IDatabase>();
            mock.Setup(m => m.Cars).Returns(datebase);
            var fakeDB = mock.Object;
            var carsRepository = new CarsRepository(fakeDB);

            // Act
            var sortedListByYear = carsRepository.SortedByYear();
            var expected = 2005;

            // Assert
            Assert.AreEqual(expected, (sortedListByYear.First()).Year);
        }
Exemplo n.º 2
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());
        }