public void GetById_ShouldThrowException_IfThereIsNoCarWithThatId()
        {
            // Arrange
            var mock = new Mock<IDatabase>();
            mock.Setup(m => m.Cars).Returns(new List<Car>() { }); ;
            var fakeDB = mock.Object;
            var carsRepository = new CarsRepository(fakeDB);

            // Act and Assert
            var ex = Assert.Throws<ArgumentException>(() => carsRepository.GetById(7));
            Assert.IsTrue(ex.Message.Contains("Car with such Id could not be found"));
        }
Ejemplo n.º 2
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));
        }
        public void GetById_ShouldFindCarById()
        {
            // Arrange
            var car = new Car { Id = 1, Make = "Audi", Model = "A5", Year = 2005 };
            var mock = new Mock<IDatabase>();
            mock.Setup(m => m.Cars).Returns(new List<Car>() { });
            var fakeDB = mock.Object;
            fakeDB.Cars.Add(car);
            var carsRepository = new CarsRepository(fakeDB);

            // Act
            var result = carsRepository.GetById(1);

            // Assert
            mock.Verify(m => m.Cars, Times.Exactly(2));
        }
Ejemplo n.º 4
0
        public void TestCarsRepository_GetByIdInvalidParameter_ShouldThrowArgumentException()
        {
            var carRepo = new CarsRepository();

            Assert.Throws<ArgumentException>(() => carRepo.GetById(5));
        }