private static void ExecuteDaoOperations(ITestObjectDao dao)
        {
            TestObject toGeorge = new TestObject();

            toGeorge.Name = "George";
            toGeorge.Age  = 33;
            dao.Create(toGeorge);
            TestObject to = dao.FindByName("George");

            Assert.IsNotNull(to, "FindByName for George should not return null");
            Assert.AreEqual("George", to.Name);
            Assert.AreEqual(33, to.Age);

            to.Age = 34;
            dao.Update(to);

            TestObject to2 = dao.FindByName("George");

            Assert.AreEqual(34, to2.Age);

            dao.Delete(to);

            TestObject to3 = dao.FindByName("George");

            Assert.IsNull(to3, "Should not have found TestObject with name George. TestObject = " + to.ToString());
        }
        public static void PerformOperations(ITestObjectManager mgr,
            ITestObjectDao dao)
        {
            Assert.IsNotNull(mgr);
            TestObject to1 = new TestObject();
            to1.Name = "Jack";
            to1.Age = 7;
            TestObject to2 = new TestObject();
            to2.Name = "Jill";
            to2.Age = 8;
            mgr.SaveTwoTestObjects(to1, to2);

            TestObject to = dao.FindByName("Jack");
            Assert.IsNotNull(to);

            to = dao.FindByName("Jill");
            Assert.IsNotNull(to);
            Assert.AreEqual("Jill", to.Name);

            mgr.DeleteTwoTestObjects("Jack", "Jill");

            to = dao.FindByName("Jack");
            Assert.IsNull(to);

            to = dao.FindByName("Jill");
            Assert.IsNull(to);
        }
示例#3
0
        public static void PerformOperations(ITestObjectManager mgr,
                                             ITestObjectDao dao)
        {
            Assert.IsNotNull(mgr);
            TestObject to1 = new TestObject();

            to1.Name = "Jack";
            to1.Age  = 7;
            TestObject to2 = new TestObject();

            to2.Name = "Jill";
            to2.Age  = 8;
            mgr.SaveTwoTestObjects(to1, to2);

            TestObject to = dao.FindByName("Jack");

            Assert.IsNotNull(to);

            to = dao.FindByName("Jill");
            Assert.IsNotNull(to);
            Assert.AreEqual("Jill", to.Name);

            mgr.DeleteTwoTestObjects("Jack", "Jill");

            to = dao.FindByName("Jack");
            Assert.IsNull(to);

            to = dao.FindByName("Jill");
            Assert.IsNull(to);
        }
        public void SimpleDao()
        {
            ITestObjectDao dao = (ITestObjectDao)ctx["NHTestObjectDao"];

            Assert.IsNotNull(dao);
            TestObject to = dao.FindByName("Gabriel");

            Assert.IsNotNull(to);
            Assert.AreEqual("Gabriel", to.Name);
        }
        public void DaoOperationsWithRollback()
        {
            ITestObjectDao dao = (ITestObjectDao)ctx["testObjectDaoTransProxy"];

            try
            {
                ExecuteAndRollbackDaoOperations(dao);
            } catch (Exception e)
            {
                TestObject to = dao.FindByName("Bugs");
                Assert.IsNull(to);

                //just to get rid of compiler warning...
                Assert.IsNotNull(e);
            }
        }
        public void ExecuteTransactionManager()
        {
            DefaultTransactionDefinition def = new DefaultTransactionDefinition();

            def.PropagationBehavior = TransactionPropagation.Required;

            ITransactionStatus status = transactionManager.GetTransaction(def);

            ITestObjectDao dao = (ITestObjectDao)ctx["NHTestObjectDao"];
            TestObject     to;

            try
            {
                to = dao.FindByName("Gabriel");
            }
            catch (Exception)
            {
                transactionManager.Rollback(status);
                throw;
            }
            transactionManager.Commit(status);
            Assert.IsNotNull(to, "FindByName for Gabriel should not return null");
            Assert.AreEqual("Gabriel", to.Name);
        }
 /// <summary>
 /// Gets called by TransactionTemplate.Execute within a
 /// transaction context.
 /// </summary>
 /// <param name="status">The associated transaction status.</param>
 /// <returns>a result object or <c>null</c></returns>
 public object DoInTransaction(ITransactionStatus status)
 {
     return(dao.FindByName("Gabriel"));
 }
示例#8
0
	    private static void ExecuteDaoOperations(ITestObjectDao dao)
	    {
	        TestObject toGeorge = new TestObject();
	        toGeorge.Name = "George";
	        toGeorge.Age = 33;
	        dao.Create(toGeorge);
	        TestObject to = dao.FindByName("George");
	        Assert.IsNotNull(to, "FindByName for George should not return null");
	        Assert.AreEqual("George", to.Name);
	        Assert.AreEqual(33, to.Age);
    
	        to.Age=34;
	        dao.Update(to);
    
	        TestObject to2 = dao.FindByName("George");
	        Assert.AreEqual(34, to2.Age);
    
	        dao.Delete(to);
    
	        TestObject to3 = dao.FindByName("George");
	        Assert.IsNull(to3, "Should not have found TestObject with name George. TestObject = " + to.ToString()   );
	    }