コード例 #1
0
        public void Remove_ShouldThrowArgumentException_IfCarIsNull()
        {
            // Arrange
            Car car = null;
            var carsRepository = new CarsRepository();

            // Act and Assert
            var ex = Assert.Throws<ArgumentException>(() => carsRepository.Remove(car));
            Assert.IsTrue(ex.Message.Contains("Null car cannot be removed"));
        }
コード例 #2
0
 public void TestCarsRepository_RemoveMethodWhenPassNull_ShouldThrowArgumentException()
 {
     var carRepo = new CarsRepository();
     Assert.Throws<ArgumentException>(() => carRepo.Remove(null));
 }
コード例 #3
0
        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);
        }
コード例 #4
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);
        }