예제 #1
0
        public void ContactHasOneOrZeroAddresses_AddressHasOneContact_WithNHibernate()
        {
            using (new TransactionScope())
            {
                ISession session = ServiceLocator.Factory.OpenSession();
                var address = new Domain.Address{Street = "Lipowa"};
                var contact = new Domain.Contact {Name = "Test", Address = address};
                address.Contact = contact;

                using(ITransaction transaction = session.BeginTransaction())
                {
                    session.Save(contact);
                    transaction.Commit();
                }
                session = ServiceLocator.Factory.OpenSession();
                using (ITransaction transaction = session.BeginTransaction())
                {
                    IList<Domain.Contact> contacts = session.Linq<Domain.Contact>().Where(x => x.Name == "Test").ToList();
                    Assert.That(contacts.Count, Is.EqualTo(1));
                }
            }
        }
예제 #2
0
 public void ShouldThrowAnExceptionWhenSavingAddressWithoutContactReference_withNH()
 {
     //Required not null property mapping
     var address = new Domain.Address {Street = "Lipowa"};
     ISession session = ServiceLocator.Factory.OpenSession();
     using(ITransaction transaction = session.BeginTransaction())
     {
         Assert.Throws(typeof(PropertyValueException),()=>session.Save(address));
     }
 }