Example #1
0
        public void ProxySerialize()
        {
            ISession s  = OpenSession();
            IMyProxy ap = new MyProxyImpl {
                Id = 1, Name = "first proxy"
            };

            s.Save(ap);
            s.Flush();
            s.Close();

            s  = OpenSession();
            ap = (IMyProxy)s.Load(typeof(MyProxyImpl), ap.Id);
            Assert.AreEqual(1, ap.Id);
            s.Disconnect();

            SerializeAndDeserialize(ref s);

            s.Reconnect();
            s.Disconnect();

            // serialize and then deserialize the session again - make sure Castle.DynamicProxy
            // has no problem with serializing two times - earlier versions of it did.
            SerializeAndDeserialize(ref s);

            s.Close();

            s = OpenSession();
            s.Delete(ap);
            s.Flush();
            s.Close();
        }
Example #2
0
        public void ExceptionStackTrace()
        {
            ISession s  = OpenSession();
            IMyProxy ap = new MyProxyImpl {
                Id = 1, Name = "first proxy"
            };

            s.Save(ap);
            s.Flush();
            s.Close();

            s  = OpenSession();
            ap = (IMyProxy)s.Load(typeof(MyProxyImpl), ap.Id);
            Assert.IsFalse(NHibernateUtil.IsInitialized(ap), "check we have a proxy");

            try
            {
                ap.ThrowDeepException();
                Assert.Fail("Exception not thrown");
            }
            catch (ArgumentException ae)
            {
                Assert.AreEqual("thrown from Level2", ae.Message);

                string[] stackTraceLines = ae.StackTrace.Split('\n');
                Assert.IsTrue(stackTraceLines[0].Contains("Level2"), "top of exception stack is Level2()");
                Assert.IsTrue(stackTraceLines[1].Contains("Level1"), "next on exception stack is Level1()");
            }
            finally
            {
                s.Delete(ap);
                s.Flush();
                s.Close();
            }
        }
Example #3
0
		public void ExceptionStackTrace()
		{
			ISession s = OpenSession();
			IMyProxy ap = new MyProxyImpl {Id = 1, Name = "first proxy"};
			s.Save(ap);
			s.Flush();
			s.Close();

			s = OpenSession();
			ap = (IMyProxy) s.Load(typeof (MyProxyImpl), ap.Id);
			Assert.IsFalse(NHibernateUtil.IsInitialized(ap), "check we have a proxy");

			try
			{
				ap.ThrowDeepException();
				Assert.Fail("Exception not thrown");
			}
			catch (ArgumentException ae)
			{
				Assert.AreEqual("thrown from Level2", ae.Message);

				string[] stackTraceLines = ae.StackTrace.Split('\n');
				Assert.IsTrue(stackTraceLines[0].Contains("Level2"), "top of exception stack is Level2()");
				Assert.IsTrue(stackTraceLines[1].Contains("Level1"), "next on exception stack is Level1()");
			}
			finally
			{
				s.Delete(ap);
				s.Flush();
				s.Close();
			}
		}
Example #4
0
		public void Proxy()
		{
			ISession s = OpenSession();
			IMyProxy ap = new MyProxyImpl {Id = 1, Name = "first proxy"};
			s.Save(ap);
			s.Flush();
			s.Close();

			s = OpenSession();
			ap = (IMyProxy) s.Load(typeof (MyProxyImpl), ap.Id);
			Assert.IsFalse(NHibernateUtil.IsInitialized(ap));
			int id = ap.Id;
			Assert.IsFalse(NHibernateUtil.IsInitialized(ap), "get id should not have initialized it.");
			string name = ap.Name;
			Assert.IsTrue(NHibernateUtil.IsInitialized(ap), "get name should have initialized it.");
			s.Delete(ap);
			s.Flush();
			s.Close();
		}
Example #5
0
        public void Proxy()
        {
            ISession s  = OpenSession();
            IMyProxy ap = new MyProxyImpl {
                Id = 1, Name = "first proxy"
            };

            s.Save(ap);
            s.Flush();
            s.Close();

            s  = OpenSession();
            ap = (IMyProxy)s.Load(typeof(MyProxyImpl), ap.Id);
            Assert.IsFalse(NHibernateUtil.IsInitialized(ap));
            int id = ap.Id;

            Assert.IsFalse(NHibernateUtil.IsInitialized(ap), "get id should not have initialized it.");
            string name = ap.Name;

            Assert.IsTrue(NHibernateUtil.IsInitialized(ap), "get name should have initialized it.");
            s.Delete(ap);
            s.Flush();
            s.Close();
        }
Example #6
0
		public void ProxySerialize()
		{
			ISession s = OpenSession();
			IMyProxy ap = new MyProxyImpl {Id = 1, Name = "first proxy"};
			s.Save(ap);
			s.Flush();
			s.Close();

			s = OpenSession();
			ap = (IMyProxy) s.Load(typeof (MyProxyImpl), ap.Id);
			Assert.AreEqual(1, ap.Id);
			s.Disconnect();

			SerializeAndDeserialize(ref s);

			s.Reconnect();
			s.Disconnect();

			// serialize and then deserialize the session again - make sure Castle.DynamicProxy
			// has no problem with serializing two times - earlier versions of it did.
			SerializeAndDeserialize(ref s);

			s.Close();

			s = OpenSession();
			s.Delete(ap);
			s.Flush();
			s.Close();
		}