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

            AssertValuesForCarIsPersisted(newCar);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
 public void Update(Car car)
 {
     using (var session = NHibernateSessionManager.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Update(car);
             transaction.Commit();
         }
     }
 }
Exemplo n.º 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();
                }
            }
        }
Exemplo n.º 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());
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 7
0
 private static void AssertCarIsNotInDb(Car car)
 {
     using (var session = _sessionFactory.OpenSession())
     {
         var removedCar = session.Get<Car>(car.Id);
         Assert.IsNull(removedCar);
     }
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }