public void SessionContextProviderTest()
 {
     using (var tr = new SessionContextProvider(this.SessionFactory.OpenSession))
     {
         INhPagedDAO dao = new EnterprisePagedDAO(tr);
         var res = dao.FindAll<Salesman>();
         Assert.IsTrue(res.Any());
     }
 }
        public void SessionContextProviderWorngTest()
        {
            var tr = new SessionContextProvider(this.SessionFactory.OpenSession);

            INhPagedDAO dao;
            using (tr)
            {
                dao = new EnterprisePagedDAO(tr);
                var res = dao.FindAll<Salesman>();
                Assert.IsTrue(res.Any());
            }
            // an error must be thrown ..
            // 'cause 
            dao.FindAll<Student>();
        }
 public void Run2(int startIndex, int pageSize, StringBuilder buffer)
 {
     using (var sss = new SessionContextProvider(this.SessionFactory.OpenSession))
     {
         INhPagedDAO dao = new EnterprisePagedDAO(sss);
         var result = dao.GetPagedResult<Salesman>(startIndex, pageSize, salesman => salesman.ID > 0);
         Assert.IsNotNull(result.Result);
         lock (buffer)
         {
             buffer.AppendLine("Begin writing on buffer");
             foreach (var res in result.Result)
             {
                 buffer.AppendLine(res.ToString());
             }
         }
     }
 }
        public void TestMultiTransactionsWithRollback()
        {
            using (ISessionProvider provider = new SessionContextProvider(this.SessionFactory.OpenSession))
            {
                provider.BeginTransaction("first");
                Assert.IsTrue(provider.InProgress);

                provider.BeginTransaction("second");
                Assert.IsTrue(provider.InProgress);

                provider.BeginTransaction("third");
                Assert.IsTrue(provider.InProgress);

                provider.CommitTransaction();           /* commit the third transaction. */
                Assert.IsTrue(provider.InProgress);

                provider.RollbackTransaction();         /* this throws an exception because there are another inner transaction in progress. */

            }
        }
        public void TestMultiTransactions()
        {
            using (ISessionProvider provider = new SessionContextProvider(this.SessionFactory.OpenSession))
            {
                provider.BeginTransaction("first");
                Assert.IsTrue(provider.InProgress);

                provider.BeginTransaction("second");
                Assert.IsTrue(provider.InProgress);

                provider.BeginTransaction("third");
                Assert.IsTrue(provider.InProgress);

                provider.CommitTransaction();
                Assert.IsTrue(provider.InProgress);

                provider.CommitTransaction();
                Assert.IsTrue(provider.InProgress);

                provider.CommitTransaction();
                Assert.IsFalse(provider.InProgress);
            }
        }