Beispiel #1
0
        public void Add_NewCard_NewCarAdded()
        {
            var newCar = new Car {Make = "Saab", RegistrationNumber = "DN10000"};
            var repository = new CarRepository();
            repository.Add(newCar);

            AssertValuesForCarIsPersisted(newCar);
        }
Beispiel #2
0
        public void GetBy_IdFromCarInDb_CarReturned()
        {
            var newCar = new Car { Make = "Saab", RegistrationNumber = "DN10000" };
            var carRepository = new CarRepository();
            carRepository.Add(newCar);

            var savedCar = carRepository.GetBy(newCar.Id);

            Assert.AreEqual(newCar.Id, savedCar.Id);
        }
Beispiel #3
0
 public void Update(Car car)
 {
     using (var session = NHibernateSessionManager.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Update(car);
             transaction.Commit();
         }
     }
 }
Beispiel #4
0
        public void Add(Car car)
        {
            if(car == null) return;

            using (var session = NHibernateSessionManager.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    session.Save(car);
                    transaction.Commit();
                }
            }
        }
Beispiel #5
0
        public void GetAll_TwoSaabsAndOneBMWInDb_OnlySaabsReturned()
        {
            var saab1 = new Car { Make = "Saab", RegistrationNumber = "DN10000"};
            var saab2 = new Car { Make = "Saab", RegistrationNumber = "DN10001"};
            var bmw1 = new Car { Make = "BMW", RegistrationNumber = "DN10002"};

            var carRepository = new CarRepository();
            carRepository.Add(saab1);
            carRepository.Add(saab2);
            carRepository.Add(bmw1);

            var saabs = carRepository.GetAll("Saab");

            Assert.AreEqual(2, saabs.Count());
        }
Beispiel #6
0
 private static void AssertValuesForCarIsPersisted(Car newCar)
 {
     using (var session = _sessionFactory.OpenSession())
     {
         var addedCar = session.Get<Car>(newCar.Id);
         Assert.IsNotNull(addedCar);
         Assert.AreEqual(newCar.Id, addedCar.Id);
         Assert.AreEqual(newCar.Make, addedCar.Make);
         Assert.AreEqual(newCar.RegistrationNumber, addedCar.RegistrationNumber);
     }
 }
Beispiel #7
0
 private static void AssertCarIsNotInDb(Car car)
 {
     using (var session = _sessionFactory.OpenSession())
     {
         var removedCar = session.Get<Car>(car.Id);
         Assert.IsNull(removedCar);
     }
 }
Beispiel #8
0
        public void Update_RegistrationNumberChanged_ChangePersistsInDataBase()
        {
            var newCar = new Car { Make = "Saab", RegistrationNumber = "DN10000" };
            var carRepository = new CarRepository();
            carRepository.Add(newCar);

            newCar.RegistrationNumber = "LJ10000";

            carRepository.Update(newCar);

            AssertValuesForCarIsPersisted(newCar);
        }
Beispiel #9
0
        public void Remove_CarExistsInDb_CarRemoved()
        {
            var newCar = new Car { Make = "Saab", RegistrationNumber = "DN10000" };
            var carRepository = new CarRepository();
            carRepository.Add(newCar);

            carRepository.Remove(newCar);

            AssertCarIsNotInDb(newCar);
        }