public void VerifyTheMappings()
        {
            // Create the initial copy
            var first = new TEntity();

            // Set the "suggested" properties, including references
            // to other entities and possibly collections
            foreach (var o in _allProperties)
            {
                ((IPropertyValue)o).SetValue(first);
            }

            _repository.Save(first);
            _uow.Commit();
            _uow.Dispose();

            using (var newUow = new NHibernateUnitOfWork(_source))
            {
                // Get a completely different IRepository
                newUow.Initialize();
                var secondRepository = new NHibernateRepository <TId>(newUow);

                // "Find" the same entity from the second IRepository
                var second = secondRepository.Load <TEntity>(_idFunc(first));

                // Validate that each specified property and value
                // made the round trip
                // It's a bit naive right now because it fails on the first failure
                foreach (var o in _allProperties)
                {
                    ((IPropertyValue)o).CheckValue(second);
                }
            }
        }
        public PersistenceSpecification(Func <TEntity, TId> idFunc)
        {
            _idFunc = idFunc;
            _source = ObjectFactory.GetInstance <ISessionSource>();

            _uow = new NHibernateUnitOfWork(_source);
            _uow.Initialize();
            _repository = new NHibernateRepository <TId>(_uow);
        }
Ejemplo n.º 3
0
        public void SetUp()
        {
            _nHibernateSessionFactory = MockRepository.GenerateStub <INHibernateSessionFactory>();
            _session     = MockRepository.GenerateMock <ISession>();
            _transaction = MockRepository.GenerateStub <ITransaction>();

            _nHibernateSessionFactory.Stub(s => s.CreateSession()).Return(_session);
            _session.Stub(s => s.BeginTransaction()).Return(_transaction);

            _uow = new NHibernateUnitOfWork(_nHibernateSessionFactory);
            _uow.Initialize();
        }
Ejemplo n.º 4
0
 protected virtual void Before_each_test()
 {
     try
     {
         UnitOfWork = new NHibernateUnitOfWork(SessionSource);
         UnitOfWork.Initialize();
     }
     catch (Exception ex)
     {
         Console.WriteLine("The Following Error was detected:");
         Console.WriteLine(ex.Message);
         if (ex.InnerException != null)
         {
             Console.WriteLine(ex.InnerException.Message);
         }
     }
 }
        public void SetUp()
        {
            _nHibernateSessionFactory = MockRepository.GenerateStub<INHibernateSessionFactory>();
            _session = MockRepository.GenerateMock<ISession>();
            _transaction = MockRepository.GenerateStub<ITransaction>();

            _nHibernateSessionFactory.Stub(s => s.CreateSession()).Return(_session);
            _session.Stub(s => s.BeginTransaction()).Return(_transaction);

            _uow = new NHibernateUnitOfWork(_nHibernateSessionFactory);
            _uow.Initialize();
        }