Esempio n. 1
0
        public void Can_add_new_daycare()
        {
            DateTime date = DateTime.Now;
            // Set the Milliseconds to 0 since MySQL DATETIME does not support milliseconds.
            date = DateTime.ParseExact(date.ToString(), "M/d/yyyy h:mm:ss tt", null);

            var daycare = new Daycare(date, _dog1, _daycareCost, _user1);
            IDaycareRepository repository = new DaycareRepository();
            repository.Add(daycare);

            // use session to try to load the daycare
            using (ISession session = _sessionFactory.OpenSession())
            {
                var fromDb = session.Get<Daycare>(daycare.DaycareId);
                // Test that the daycare was successfully inserted
                Assert.IsNotNull(fromDb);
                Assert.AreNotSame(daycare, fromDb);
                Assert.AreEqual(daycare.Date, fromDb.Date);
                Assert.AreEqual(daycare.Dog, fromDb.Dog);
                Assert.AreEqual(daycare.DaycareCost, fromDb.DaycareCost);
                Assert.AreEqual(daycare.User, fromDb.User);
            }

            repository.Remove(daycare);
        }
 public void Update(Daycare daycare)
 {
     using (ISession session = NHibernateHelper.OpenSession())
     using (ITransaction transaction = session.BeginTransaction())
     {
         session.Update(daycare);
         transaction.Commit();
     }
 }
Esempio n. 3
0
        public void Can_add_multiple_new_daycares()
        {
            ISession session = _sessionFactory.OpenSession();

            int countBefore = getDaycareTableSize(session);

            ITransaction tx = session.BeginTransaction();
            Daycare daycare1 = new Daycare();
            daycare1.Date = DateTime.Now;
            daycare1.Dog = _dog1;
            daycare1.DaycareCost = _daycareCost;
            daycare1.User = _user1;
            session.Save(daycare1);

            Daycare daycare2 = new Daycare();
            daycare2.Date = DateTime.Now;
            daycare2.Dog = _dog2;
            daycare2.DaycareCost = _daycareCost;
            daycare2.User = _user2;
            session.Save(daycare2);

            Daycare daycare3 = new Daycare();
            daycare3.Date = DateTime.Now;
            daycare3.Dog = _dog1;
            daycare3.DaycareCost = _daycareCost;
            daycare3.User = _user1;
            session.Save(daycare3);

            tx.Commit();

            Assert.AreEqual(countBefore + 3, getDaycareTableSize(session));

            tx = session.BeginTransaction();

            session.Delete(daycare1);
            session.Delete(daycare2);
            session.Delete(daycare3);

            tx.Commit();

            session.Close();
        }
Esempio n. 4
0
        private bool IsInCollection(Daycare daycare, ICollection<Daycare> fromDb)
        {
            bool result = false;

            foreach (var item in fromDb)
            {
                if (daycare.DaycareId == item.DaycareId)
                {
                    result = true;
                    break;
                }
            }
            return result;
        }
Esempio n. 5
0
        private void CreateInitialData()
        {
            using (ISession session = _sessionFactory.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                // Save the user to populate its UserId.
                session.Save(_user1);
                session.Save(_user2);

                session.Save(_dog1);
                session.Save(_dog2);

                session.Save(_daycareCost);

                // Get rid of milliseconds to make comparisons work, since MySQL
                // DateTime does not support milliseconds.
                DateTime date = DateTime.ParseExact(DateTime.Now.ToString(), "M/d/yyyy h:mm:ss tt", null);

                _daycares = new Daycare [4];
                _daycares[0] = new Daycare(date, _dog1, _daycareCost, _user1);
                _daycares[1] = new Daycare(date, _dog1, _daycareCost, _user2);
                _daycares[2] = new Daycare(date, _dog2, _daycareCost, _user1);
                _daycares[3] = new Daycare(date, _dog2, _daycareCost, _user2);

                foreach (var daycare in _daycares)
                {
                    session.Save(daycare);
                }

                transaction.Commit();
            }
        }